Skip to content

Commit

Permalink
some tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Oct 8, 2019
1 parent 2632267 commit 287ae01
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 107 deletions.
Binary file removed examples/WOVNS/data/random.png
Binary file not shown.
2 changes: 1 addition & 1 deletion nature-of-code/xor/.mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<extension>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-ruby</artifactId>
<version>0.1.19</version>
<version>0.4.3</version>
</extension>
</extensions>
11 changes: 9 additions & 2 deletions nature-of-code/xor/Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
task default: [:compile, :run]
desc 'Default'
task :default => [:compile, :install, :run]

desc 'Compile'
task :compile do
sh 'mvn package'
end

desc 'Move xor jar'
task :install do
sh 'mkdir -p library/xor' unless File.exist?('./library/xor')
sh 'mv target/xor-1.0-SNAPSHOT.jar library/xor/xor.jar'
end

desc 'Run'
task :run do
sh 'jruby xor.rb'
exec 'jruby xor.rb'
end
2 changes: 1 addition & 1 deletion nature-of-code/xor/landscape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def render
# (clean this part up)
no_stroke
push_matrix
begin_shape(QUADS)
begin_shape(Processing::QUADS)
translate(x * scl - w * 0.5, y * scl - h * 0.5, 0)
fill(z[x][y] + 127, 220)
vertex(0, 0, z[x][y])
Expand Down
31 changes: 0 additions & 31 deletions nature-of-code/xor/pom.rb

This file was deleted.

18 changes: 6 additions & 12 deletions nature-of-code/xor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@ DO NOT MODIFIY - GENERATED CODE
<artifactId>xor</artifactId>
<version>1.0-SNAPSHOT</version>
<name>xor</name>
<description>neural net library for xor</description>
<description>Neural Net Library for xor</description>
<developers>
<developer>
<id>shiffman</id>
<name>DanShiffman</name>
<name>Dan Shiffman</name>
<roles>
<role>developer</role>
</roles>
</developer>
</developers>
<properties>
<maven.compiler.release>11</maven.compiler.release>
<polyglot.dump.pom>pom.xml</polyglot.dump.pom>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<xor.basedir>${project.basedir}</xor.basedir>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<defaultGoal>package</defaultGoal>
<finalName>xor</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<outputDirectory>${xor.basedir}/library/xor</outputDirectory>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 24 additions & 16 deletions processing_app/demos/graphics/planets.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true

require 'propane'
# frozen_string_literal: true

# Planets, by Andres Colubri
#
# Planets, by Andres Colubri, translated to RubyArt by Martin Prout
# Sun and mercury textures from http://planetpixelemporium.com
# Star field picture from http://www.galacticimages.com/
class Planets < Propane::App
attr_reader :textures, :sun, :planet, :mercury

IMAGES = %w(starfield sun planet mercury)
KEY = %i(starfield sun planet mercury)
IMAGES = %w[starfield sun planet mercury].freeze

def setup
sketch_title 'Planets'
images = IMAGES.map { |img| load_image(data_path("#{img}.jpg")) }
@textures = KEY.zip(images).to_h
@textures = load_textures(IMAGES)
no_stroke
fill(255)
sphere_detail(40)
@sun = create_shape(SPHERE, 150)
@sun.set_texture(textures[:sun])
@planet = create_shape(SPHERE, 150)
planet.set_texture(textures[:planet])
@mercury = create_shape(SPHERE, 50)
mercury.set_texture(textures[:mercury])
@sun = textured_sphere(150, :sun)
@planet = textured_sphere(150, :planet)
@mercury = textured_sphere(50, :mercury)
end

def textured_sphere(size, texture)
create_shape(SPHERE, size).tap do |sphere|
sphere.set_texture(textures[texture])
end
end

# create a hash of loaded images for use as textures
def load_textures(image_names)
image_names.map do |img|
[img.to_sym, load_image(data_path("#{img}.jpg"))]
end.to_h
end

def draw
Expand All @@ -44,14 +52,14 @@ def draw
rotate_y(PI * frame_count / 500)
shape(sun)
pop_matrix
point_light(255, 255, 255, 0, 0, 0)
point_light(255, 255, 255, 0, 0, 0)
rotate_y(PI * frame_count / 300)
translate(0, 0, 300)
shape(mercury)
pop_matrix
no_lights
point_light(255, 255, 255, 0, 0, -150)
translate(0.75 * width, 0.6 * height, 50)
point_light(255, 255, 255, 0, 0, -150)
translate(0.75 * width, 0.6 * height, 50)
shape(planet)
end

Expand Down
2 changes: 1 addition & 1 deletion processing_app/library/vecmath/vec2d/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

def run_sample(sample_name)
puts "Running #{sample_name}...quit to run next sample"
open("|jruby #{sample_name}", 'r') do |io|
open("|jruby --dev #{sample_name}", 'r') do |io|
while l = io.gets
puts(l.chop)
end
Expand Down
1 change: 0 additions & 1 deletion processing_app/library/vecmath/vec2d/aabb_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true
require 'propane'
java_import 'monkstone.vecmath.GfxRender'
# Click on the box and drag it across the screen.
class AaBbExample < Propane::App
attr_reader :block, :block_locked, :over_block, :bounds
Expand Down
2 changes: 0 additions & 2 deletions processing_app/library/vecmath/vec2d/morph.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true
require 'propane'

java_import 'monkstone.vecmath.GfxRender'
# Morph.
#
# Changing one shape into another by interpolating
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true
require 'propane'
require_relative 'library/particle/particle'

# ParticleSystemPShape
# A particle system optimized for drawing using PShape
# For guts of implementation see 'particle' library
#
class ParticleShape < Propane::App

load_library :particle
# Particle System object and image
attr_reader :ps

Expand Down
4 changes: 2 additions & 2 deletions processing_app/library/vecmath/vec2d/penrose.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true

require 'propane'
require_relative 'library/tile/tile'
# Penrose Tile Generator
# Using a variant of the "ArrayList" recursion technique: http://natureofcode.com/book/chapter-8-fractals/chapter08_section4
# Penrose Algorithm from: http://preshing.com/20110831/penrose-tiling-explained
# Daniel Shiffman May 2013
# Translated (and refactored) to JRubyArt July 2015 by Martin Prout
class Penrose < Propane::App
load_library :control_panel
load_libraries :control_panel, :tile
attr_reader :tris, :s, :acute

def setup
Expand Down
1 change: 0 additions & 1 deletion processing_app/library/vecmath/vec2d/soft_body.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true
require 'propane'
java_import 'monkstone.vecmath.GfxRender'
########
# Soft Body by Ira Greenberg
# Softbody dynamic simulation using curve_vertex
Expand Down
4 changes: 2 additions & 2 deletions processing_app/library/vecmath/vec2d/verlet_integration.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true

require 'propane'
#
# Verlet Integration - ragdoll chain
# after a sketch by Ira Greenberg
#
require 'propane'

class VerletIntegration < Propane::App
load_library :verlet_chain
PARTICLES = 5
Expand Down
2 changes: 1 addition & 1 deletion processing_app/library/vecmath/vec3d/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

def run_sample(sample_name)
puts "Running #{sample_name}...quit to run next sample"
open("|jruby #{sample_name}", 'r') do |io|
open("|jruby --dev #{sample_name}", 'r') do |io|
while l = io.gets
puts(l.chop)
end
Expand Down
1 change: 0 additions & 1 deletion processing_app/library/vecmath/vec3d/drawolver.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true
require 'propane'
java_import 'monkstone.vecmath.GfxRender'
# Drawolver: draw 2D & revolve 3D

# Example shows how to use the vecmath library, including GfxRender utility.
Expand Down
13 changes: 6 additions & 7 deletions processing_app/library/vecmath/vec3d/frame_of_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
# frozen_string_literal: true
require 'propane'
require 'arcball'
require_relative 'library/geometry/geometry'
java_import 'monkstone.vecmath.GfxRender'

###############
# Frame of Reference example by Ira Greenberg
# https://github.com/irajgreenberg/ProcessingTips
# Translated to JRubyArt by Martin Prout February 2016
###############
class FrameOfReference < Propane::App
###############
# Frame of Reference example by Ira Greenberg
# https://github.com/irajgreenberg/ProcessingTips
# Translated to JRubyArt by Martin Prout February 2016
###############
load_library :geometry
FACE_COUNT = 50

attr_reader :c, :p
Expand Down
4 changes: 1 addition & 3 deletions processing_app/library/vecmath/vec3d/hilbert_fractal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# frozen_string_literal: true
require 'propane'
require 'arcball'
require_relative 'library/hilbert/hilbert'
java_import 'monkstone.vecmath.GfxRender'

########################################################
# A 3D Hilbert fractal implemented using a
# Lindenmayer System in JRubyArt by Martin Prout
Expand All @@ -14,6 +11,7 @@
# intuitive rotation using mouse drag.
########################################################
class HilbertFractal < Propane::App
load_library :hilbert
attr_reader :hilbert

def setup
Expand Down
52 changes: 32 additions & 20 deletions processing_app/topics/advanced_shader/blue_marble.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
#!/usr/bin/env jruby -w
# frozen_string_literal: true

require 'propane'
# Earth model with bump mapping, specular texture and dynamic cloud layer.
# Adapted from the THREE.js tutorial to processing by Andres Colubri,
# translated to propane by Martin Prout:
# http://learningthreejs.com/blog/2013/09/16/how-to-make-the-earth-in-webgl/
class BlueMarble < Propane::App
attr_reader :earth, :clouds, :earth_shader, :cloud_shader, :earth_rotation
attr_reader :clouds_rotation, :target_angle
attr_reader :clouds_rotation, :target_angle, :shaders

SHADERS = %w(EarthFrag.glsl EarthVert.glsl CloudFrag.glsl CloudVert.glsl).freeze
SHADER_NAME = %i(earth_frag earth_vert cloud_frag cloud_vert).freeze
IMAGES = %w(earthmap1k earthcloudmap earthcloudmaptrans earthbump1k earthspec1k).freeze
IMAGE_NAME = %i(earth_tex cloud_tex alpha_tex bump_map spec_map).freeze
SHADERS = %w[EarthFrag.glsl EarthVert.glsl CloudFrag.glsl CloudVert.glsl].freeze
SHADER_NAME = %i[earth_frag earth_vert cloud_frag cloud_vert].freeze
IMAGES = %w[earthmap1k earthcloudmap earthcloudmaptrans earthbump1k earthspec1k].freeze
IMAGE_NAME = %i[earth_tex cloud_tex alpha_tex bump_map spec_map].freeze

def setup
sketch_title 'Blue Marble'
@earth_rotation = 0
@clouds_rotation = 0
glsl_files = SHADERS.map { |shade| data_path(shade) }
shaders = SHADER_NAME.zip(glsl_files.to_java(:string)).to_h
@shaders = SHADER_NAME.zip(glsl_files.to_java(:string)).to_h
images = IMAGES.map { |img| load_image(data_path("#{img}.jpg")) }
textures = IMAGE_NAME.zip(images).to_h
@earth_shader = load_shader(shaders[:earth_frag], shaders[:earth_vert])
earth_shader.set('texMap', textures[:earth_tex])
earth_shader.set('bumpMap', textures[:bump_map])
earth_shader.set('specularMap', textures[:spec_map])
earth_shader.set('bumpScale', 0.05)
@cloud_shader = load_shader(shaders[:cloud_frag], shaders[:cloud_vert])
cloud_shader.set('texMap', textures[:cloud_tex])
cloud_shader.set('alphaMap', textures[:alpha_tex])
@earth = create_shape(SPHERE, 200)
earth.set_stroke(false)
earth.set_specular(color(125))
earth.set_shininess(10)
@clouds = create_shape(SPHERE, 201)
clouds.set_stroke(false)
@earth_shader = init_shader(:earth_frag, :earth_vert).tap do |shp|
shp.set('texMap', textures[:earth_tex])
shp.set('bumpMap', textures[:bump_map])
shp.set('specularMap', textures[:spec_map])
shp.set('bumpScale', 0.05)
end
@cloud_shader = init_shader(:cloud_frag, :cloud_vert).tap do |shp|
shp.set('texMap', textures[:cloud_tex])
shp.set('alphaMap', textures[:alpha_tex])
end
@earth = create_sphere(200).tap do |shp|
shp.set_stroke(false)
shp.set_specular(color(125))
shp.set_shininess(10)
end
@clouds = create_sphere(201).tap { |shp| shp.set_stroke(false) }
end

def create_sphere(dim)
create_shape(SPHERE, dim)
end

def init_shader(frag, vert)
load_shader(shaders[frag], shaders[vert])
end

def draw
Expand Down

0 comments on commit 287ae01

Please sign in to comment.