ruby-processing 2.4.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rpextras.jar +0 -0
- data/lib/ruby-processing.rb +8 -6
- data/lib/ruby-processing/app.rb +54 -67
- data/lib/ruby-processing/config.rb +7 -7
- data/lib/ruby-processing/exporters/application_exporter.rb +37 -38
- data/lib/ruby-processing/exporters/base_exporter.rb +34 -37
- data/lib/ruby-processing/exporters/creator.rb +27 -25
- data/lib/ruby-processing/helper_methods.rb +18 -22
- data/lib/ruby-processing/helpers/numeric.rb +5 -6
- data/lib/ruby-processing/helpers/string.rb +11 -20
- data/lib/ruby-processing/library_loader.rb +33 -35
- data/lib/ruby-processing/runner.rb +118 -65
- data/lib/ruby-processing/runners/base.rb +21 -26
- data/lib/ruby-processing/runners/live.rb +3 -4
- data/lib/ruby-processing/runners/run.rb +1 -3
- data/lib/ruby-processing/runners/watch.rb +8 -8
- data/lib/ruby-processing/version.rb +1 -1
- data/lib/templates/application/lib/args.txt.erb +1 -1
- data/lib/templates/application/run.erb +3 -3
- data/library/control_panel/control_panel.rb +29 -29
- data/library/fastmath/fastmath.rb +3 -0
- data/library/file_chooser/file_chooser.rb +11 -13
- data/library/vecmath/vecmath.rb +6 -35
- data/samples/Rakefile +3 -1
- data/samples/configRP5/configRP5.pde +150 -0
- data/samples/contributed/Rakefile +6 -6
- data/samples/contributed/animator.rb +6 -6
- data/samples/contributed/bezier_playground.rb +29 -68
- data/samples/contributed/circle_collision.rb +6 -13
- data/samples/contributed/elegant_ball.rb +14 -17
- data/samples/contributed/empathy.rb +8 -5
- data/samples/contributed/fibonacci_sphere.rb +10 -49
- data/samples/contributed/full_screen.rb +1 -1
- data/samples/contributed/grapher.rb +10 -9
- data/samples/contributed/gravity.rb +11 -16
- data/samples/contributed/jwishy.rb +18 -20
- data/samples/contributed/quadraticvertex.rb +26 -26
- data/samples/external_library/java_processing/custom/landscape.rb +6 -4
- data/samples/external_library/java_processing/hemesh/twin_iso.rb +69 -71
- data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +57 -0
- data/samples/external_library/java_processing/pbox2d/contact_test.rb +23 -0
- data/samples/external_library/java_processing/pbox2d/data/java_args.txt +2 -0
- data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +158 -0
- data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +212 -0
- data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +154 -0
- data/samples/external_library/java_processing/pbox2d/liquidy.rb +58 -0
- data/samples/external_library/java_processing/pbox2d/polygons.rb +58 -0
- data/samples/external_library/java_processing/toxiclibs/library/vbo/vbo.rb +52 -0
- data/samples/external_library/java_processing/toxiclibs/model_align.rb +9 -16
- data/samples/processing_app/basics/color/color_wheel.rb +1 -1
- data/samples/processing_app/basics/form/regular_polygon.rb +2 -2
- data/samples/processing_app/basics/form/rgb_cube.rb +2 -2
- data/samples/processing_app/basics/form/shape_primitives.rb +1 -1
- data/samples/processing_app/basics/form/star.rb +2 -2
- data/samples/processing_app/basics/input/clock.rb +21 -16
- data/samples/processing_app/basics/input/storing_input.rb +6 -6
- data/samples/processing_app/basics/math/additive_wave.rb +1 -1
- data/samples/processing_app/basics/math/sine.rb +2 -2
- data/samples/processing_app/basics/math/sine_cosine.rb +1 -1
- data/samples/processing_app/basics/math/sine_wave.rb +1 -1
- data/samples/processing_app/basics/objects/inheritance.rb +2 -0
- data/samples/processing_app/basics/objects/inheritance_two.rb +88 -0
- data/samples/processing_app/basics/objects/module.rb +89 -0
- data/samples/processing_app/{library/vecmath/drawolver.rb → basics/objects/module_two.rb} +1 -1
- data/samples/processing_app/basics/objects/multiple_constructors.rb +5 -0
- data/samples/processing_app/basics/objects/struct.rb +38 -0
- data/samples/processing_app/basics/structure/recursion2.rb +1 -1
- data/samples/processing_app/basics/transform/birds.rb +7 -10
- data/samples/processing_app/basics/transform/library/bird/bird.rb +3 -3
- data/samples/processing_app/basics/transform/rotate.rb +1 -1
- data/samples/processing_app/basics/transform/rotate1.rb +1 -1
- data/samples/processing_app/basics/transform/rotate_x_y.rb +1 -1
- data/samples/processing_app/demos/graphics/bezier_patch.rb +1 -38
- data/samples/processing_app/demos/graphics/trefoil.rb +50 -40
- data/samples/processing_app/demos/graphics/wiggling.rb +36 -38
- data/samples/processing_app/demos/performance/cubic_grid_retained.rb +14 -14
- data/samples/processing_app/demos/performance/esfera.rb +27 -39
- data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
- data/samples/processing_app/library/fastmath/clock.rb +44 -0
- data/samples/processing_app/library/pdf/complex_3D.rb +26 -24
- data/samples/processing_app/library/vecmath/{Rakefile → arcball/Rakefile} +6 -6
- data/samples/processing_app/library/vecmath/arcball/arcball_box.rb +23 -0
- data/samples/processing_app/library/vecmath/arcball/arcball_radius.rb +23 -0
- data/samples/processing_app/library/vecmath/arcball/arcball_shape.rb +29 -0
- data/samples/processing_app/library/vecmath/{README.txt → vec2d/README.txt} +0 -0
- data/samples/processing_app/library/vecmath/vec2d/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/{acceleration_with_vectors.rb → vec2d/acceleration_with_vectors.rb} +4 -5
- data/samples/processing_app/library/vecmath/{bouncing_ball.rb → vec2d/bouncing_ball.rb} +9 -15
- data/samples/processing_app/library/vecmath/{circle_collision.rb → vec2d/circle_collision.rb} +46 -51
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/java_args.txt +0 -0
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/sprite.png +0 -0
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/texture.png +0 -0
- data/samples/processing_app/library/vecmath/{flocking.rb → vec2d/flocking.rb} +3 -6
- data/samples/processing_app/library/vecmath/{library → vec2d/library}/flock/flock.rb +47 -67
- data/samples/processing_app/library/vecmath/{library → vec2d/library}/particle/particle_system.rb +5 -5
- data/samples/processing_app/library/vecmath/vec2d/library/tile/tile.rb +85 -0
- data/samples/processing_app/library/vecmath/{morph.rb → vec2d/morph.rb} +17 -16
- data/samples/processing_app/library/vecmath/{multiple_particle_systems.rb → vec2d/multiple_particle_systems.rb} +11 -28
- data/samples/processing_app/library/vecmath/{particle_system_pshape.rb → vec2d/particle_system_pshape.rb} +4 -6
- data/samples/processing_app/library/vecmath/vec2d/penrose.rb +71 -0
- data/samples/processing_app/library/vecmath/{reflection1.rb → vec2d/reflection1.rb} +6 -6
- data/samples/processing_app/library/vecmath/{seeking_neural.rb → vec2d/seeking_neural.rb} +12 -16
- data/samples/processing_app/library/vecmath/{simple_particle_system.rb → vec2d/simple_particle_system.rb} +8 -12
- data/samples/processing_app/library/vecmath/{smoke_particle_system.rb → vec2d/smoke_particle_system.rb} +8 -13
- data/samples/processing_app/library/vecmath/{vector_math.rb → vec2d/vector_math.rb} +0 -0
- data/samples/processing_app/library/vecmath/{library/wiggler/wiggler.rb → vec2d/wiggle_pshape.rb} +28 -4
- data/samples/processing_app/library/vecmath/vec3d/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/vec3d/drawolver.rb +86 -0
- data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +103 -0
- data/samples/processing_app/library/vecmath/{hilbert_fractal.rb → vec3d/hilbert_fractal.rb} +5 -33
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/geometry.rb +3 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/cylinder.rb +44 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/mat4.rb +28 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/plane.rb +60 -0
- data/samples/processing_app/library/vecmath/{library → vec3d/library}/hilbert/hilbert.rb +14 -17
- data/samples/processing_app/library/vecmath/{retained_menger.rb → vec3d/retained_menger.rb} +20 -55
- data/samples/processing_app/topics/advanced_data/Rakefile +6 -6
- data/samples/processing_app/topics/advanced_data/counting_words.rb +7 -7
- data/samples/processing_app/topics/advanced_data/data/data.xml +0 -15
- data/samples/processing_app/topics/advanced_data/data/struct_data.yml +5 -0
- data/samples/processing_app/topics/advanced_data/library/bubble/bubble.rb +8 -8
- data/samples/processing_app/topics/advanced_data/load_save_XML.rb +41 -42
- data/samples/processing_app/topics/advanced_data/load_save_json.rb +11 -11
- data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +22 -23
- data/samples/processing_app/topics/advanced_data/load_save_table.rb +12 -12
- data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +10 -12
- data/samples/processing_app/topics/advanced_data/regex.rb +5 -6
- data/samples/processing_app/topics/advanced_data/threads.rb +27 -27
- data/samples/processing_app/topics/advanced_data/threads_two.rb +3 -2
- data/samples/processing_app/topics/advanced_data/word_frequency.rb +18 -16
- data/samples/processing_app/topics/advanced_data/yahoo_weather.rb +6 -5
- data/samples/processing_app/topics/animation/animated_sprite.rb +9 -7
- data/samples/processing_app/topics/animation/sequential.rb +19 -19
- data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +1 -1
- data/samples/processing_app/topics/cellular_automata/wolfram.rb +1 -1
- data/samples/processing_app/topics/create_shapes/begin_end_contour.rb +1 -1
- data/samples/processing_app/topics/create_shapes/library/wiggler/wiggler.rb +4 -4
- data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +2 -2
- data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
- data/samples/processing_app/topics/create_shapes/polygon_pshape_oo3.rb +1 -1
- data/samples/processing_app/topics/create_shapes/polygon_shape.rb +3 -3
- data/samples/processing_app/topics/file_io/load_file1.rb +1 -1
- data/samples/processing_app/topics/file_io/save_frames.rb +5 -5
- data/samples/processing_app/topics/file_io/save_one_image.rb +2 -2
- data/samples/processing_app/topics/file_io/tile_images.rb +1 -1
- data/samples/processing_app/topics/gui/scrollbar.rb +3 -3
- data/samples/processing_app/topics/image_processing/blending.rb +13 -13
- data/samples/processing_app/topics/image_processing/blur.rb +1 -1
- data/samples/processing_app/topics/image_processing/brightness.rb +1 -1
- data/samples/processing_app/topics/image_processing/convolution.rb +1 -1
- data/samples/processing_app/topics/image_processing/edge_detection.rb +4 -4
- data/samples/processing_app/topics/image_processing/explode.rb +1 -1
- data/samples/processing_app/topics/image_processing/extrusion.rb +1 -1
- data/samples/processing_app/topics/image_processing/histogram.rb +1 -1
- data/samples/processing_app/topics/image_processing/linear_image.rb +1 -1
- data/samples/processing_app/topics/image_processing/pixel_array.rb +1 -1
- data/samples/processing_app/topics/image_processing/zoom.rb +2 -2
- data/samples/processing_app/topics/lsystems/Rakefile +6 -6
- data/samples/processing_app/topics/lsystems/chequer.rb +4 -10
- data/samples/processing_app/topics/lsystems/csplant.rb +25 -25
- data/samples/processing_app/topics/lsystems/cstest.rb +9 -4
- data/samples/processing_app/topics/lsystems/david_tour.rb +14 -16
- data/samples/processing_app/topics/lsystems/koch.rb +8 -18
- data/samples/processing_app/topics/lsystems/library/cs_grammar/cs_grammar.rb +18 -24
- data/samples/processing_app/topics/lsystems/library/grammar/grammar.rb +7 -9
- data/samples/processing_app/topics/lsystems/library/koch/koch_fractal.rb +75 -94
- data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +11 -13
- data/samples/processing_app/topics/lsystems/mpeano.rb +29 -32
- data/samples/processing_app/topics/lsystems/peano.rb +19 -21
- data/samples/processing_app/topics/lsystems/penrose.rb +31 -37
- data/samples/processing_app/topics/lsystems/penrose_snowflake.rb +10 -15
- data/samples/processing_app/topics/lsystems/pentagonal.rb +20 -23
- data/samples/processing_app/topics/lsystems/snake_kolam.rb +13 -13
- data/samples/processing_app/topics/lsystems/stochastic_test.rb +25 -28
- data/samples/processing_app/topics/lsystems/three_d_tree.rb +25 -24
- data/samples/processing_app/topics/motion/bouncy_bubbles.rb +17 -17
- data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -3
- data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
- data/samples/processing_app/topics/motion/reflection2.rb +1 -1
- data/samples/processing_app/topics/shaders/blur_filter.rb +3 -3
- data/samples/processing_app/topics/shaders/bw_shader.rb +3 -3
- data/samples/processing_app/topics/shaders/conway.rb +5 -5
- data/samples/processing_app/topics/shaders/deform.rb +5 -5
- data/samples/processing_app/topics/shaders/edge_detect.rb +3 -5
- data/samples/processing_app/topics/shaders/glossy_fish_eye.rb +15 -21
- data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +21 -19
- data/samples/processing_app/topics/shaders/image_mask.rb +6 -6
- data/samples/processing_app/topics/shaders/landscape.rb +4 -4
- data/samples/processing_app/topics/shaders/monjori.rb +15 -15
- data/samples/processing_app/topics/shaders/nebula.rb +3 -3
- data/samples/processing_app/topics/shaders/sep_blur.rb +15 -15
- data/samples/processing_app/topics/shaders/toon_shading.rb +2 -2
- data/samples/processing_app/topics/simulate/chain.rb +16 -14
- data/samples/processing_app/topics/simulate/smoke_particle_system.rb +3 -3
- data/samples/processing_app/topics/vectors/acceleration_with_vectors.rb +3 -2
- data/samples/processing_app/topics/vectors/bouncing_ball.rb +1 -0
- data/samples/processing_app/topics/vectors/vector_math.rb +2 -1
- data/vendors/Rakefile +15 -3
- metadata +99 -86
- data/.gitignore +0 -13
- data/.travis.yml +0 -6
- data/.yardopts +0 -5
- data/CHANGELOG +0 -316
- data/CONTRIBUTING.md +0 -35
- data/Gemfile +0 -6
- data/LICENSE.md +0 -39
- data/README.md +0 -119
- data/Rakefile +0 -37
- data/bin/install_jruby_complete +0 -13
- data/lib/ruby-processing/exporters/exporters.rb +0 -7
- data/library/vecmath/lib/arcball.rb +0 -64
- data/library/vecmath/lib/quaternion.rb +0 -62
- data/library/vecmath/lib/vec.rb +0 -232
- data/ruby-processing.gemspec +0 -54
- data/samples/processing_app/library/pdf/.gitignore +0 -1
- data/samples/processing_app/library/vecmath/retained_test.rb +0 -65
- data/samples/processing_app/library/vecmath/retained_test2.rb +0 -65
- data/samples/processing_app/library/vecmath/wiggle_pshape.rb +0 -22
- data/test/README.md +0 -6
- data/test/basic.rb +0 -14
- data/test/draw_ex.rb +0 -12
- data/test/graphics.rb +0 -7
- data/test/p2d.rb +0 -14
- data/test/p3d.rb +0 -14
- data/test/rp5_test.rb +0 -86
- data/test/setup_ex.rb +0 -12
data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb
CHANGED
|
@@ -8,9 +8,8 @@ class StochasticGrammar
|
|
|
8
8
|
PROB = 1
|
|
9
9
|
attr_accessor :axiom, :srules
|
|
10
10
|
|
|
11
|
-
def initialize
|
|
11
|
+
def initialize(axiom)
|
|
12
12
|
@axiom = axiom
|
|
13
|
-
@srules = {} # rules dictionary (a hash of hashes)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
######################################################
|
|
@@ -18,8 +17,8 @@ class StochasticGrammar
|
|
|
18
17
|
#####################################################
|
|
19
18
|
|
|
20
19
|
def stochastic_rule(rules)
|
|
21
|
-
total = rules.inject(0) do |
|
|
22
|
-
|
|
20
|
+
total = rules.inject(0) do |sum, rule_and_weight|
|
|
21
|
+
sum + rule_and_weight[PROB]
|
|
23
22
|
end
|
|
24
23
|
srand
|
|
25
24
|
chance = rand * total
|
|
@@ -30,29 +29,28 @@ class StochasticGrammar
|
|
|
30
29
|
return rule
|
|
31
30
|
end
|
|
32
31
|
|
|
33
|
-
def
|
|
34
|
-
@srules.
|
|
32
|
+
def rule?(pre)
|
|
33
|
+
@srules.key?(pre)
|
|
35
34
|
end
|
|
36
35
|
|
|
37
|
-
def add_rule(pre, rule, weight = 1.0)
|
|
38
|
-
|
|
36
|
+
def add_rule(pre, rule, weight = 1.0) # default weighting 1 (can handle non-stochastic rules)
|
|
37
|
+
@srules ||= Hash.new { |h, k| h[k] = 1 }
|
|
38
|
+
if rule?(pre) # add to existing hash
|
|
39
39
|
srules[pre][rule] = weight
|
|
40
40
|
else
|
|
41
|
-
srules[pre] = {rule => weight} # store new hash with pre key
|
|
41
|
+
srules[pre] = { rule => weight } # store new hash with pre key
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def new_production(prod) # note the use of gsub!, we are changing prod as we go
|
|
46
46
|
prod.gsub!(/./) do |ch|
|
|
47
|
-
|
|
47
|
+
rule?(ch) ? stochastic_rule(srules[ch]) : ch
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def generate(repeat = 0)
|
|
52
52
|
prod = axiom
|
|
53
|
-
repeat.times
|
|
54
|
-
prod = new_production(prod)
|
|
55
|
-
end
|
|
53
|
+
repeat.times { prod = new_production(prod) }
|
|
56
54
|
return prod
|
|
57
55
|
end
|
|
58
56
|
end
|
|
@@ -4,27 +4,26 @@
|
|
|
4
4
|
########################################################
|
|
5
5
|
load_library 'grammar'
|
|
6
6
|
####################################################
|
|
7
|
-
# The MPeano fractal has been used to study the
|
|
7
|
+
# The MPeano fractal has been used to study the
|
|
8
8
|
# Euclidean travelling salesman problem
|
|
9
9
|
####################################################
|
|
10
10
|
class MPeano
|
|
11
11
|
include Processing::Proxy
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
SQRT2 = Math.sqrt(2.0)
|
|
15
14
|
ISQRT2 = 1/SQRT2
|
|
16
|
-
|
|
15
|
+
|
|
17
16
|
attr_reader :draw_length, :xpos, :ypos, :theta, :axiom, :grammar, :delta
|
|
18
|
-
|
|
19
|
-
def initialize
|
|
20
|
-
@axiom =
|
|
17
|
+
|
|
18
|
+
def initialize(xpos, ypos)
|
|
19
|
+
@axiom = 'XFF--AFF--XFF--AFF' # Axiom
|
|
21
20
|
rules = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
21
|
+
'X' => '+!X!FF-BQFI-!X!FF+', # LSystem Rules
|
|
22
|
+
'F' => '', # Example of a 'delete' replace
|
|
23
|
+
'Y' => 'FFY',
|
|
24
|
+
'A' => 'BQFI',
|
|
25
|
+
'B' => 'AFF'
|
|
26
|
+
}
|
|
28
27
|
@grammar = Grammar.new(axiom, rules)
|
|
29
28
|
@delta = QUARTER_PI # 45 degrees
|
|
30
29
|
@theta = HALF_PI
|
|
@@ -32,28 +31,28 @@ class MPeano
|
|
|
32
31
|
@xpos = xpos
|
|
33
32
|
@ypos = ypos
|
|
34
33
|
end
|
|
35
|
-
|
|
36
|
-
def generate
|
|
34
|
+
|
|
35
|
+
def generate(gen)
|
|
37
36
|
grammar.generate gen
|
|
38
37
|
end
|
|
39
|
-
|
|
38
|
+
|
|
40
39
|
def translate_rules(prod)
|
|
41
40
|
points = [] # An empty array to store line vertices
|
|
42
41
|
prod.each do |ch|
|
|
43
42
|
case(ch)
|
|
44
|
-
when
|
|
45
|
-
points << xpos << ypos << (@xpos -= draw_length * cos(theta)) << (@ypos -= draw_length * sin(theta))
|
|
46
|
-
when
|
|
47
|
-
@theta += delta
|
|
48
|
-
when
|
|
49
|
-
@theta -= delta
|
|
50
|
-
when
|
|
43
|
+
when 'F'
|
|
44
|
+
points << xpos << ypos << (@xpos -= draw_length * cos(theta)) << (@ypos -= draw_length * sin(theta))
|
|
45
|
+
when '+'
|
|
46
|
+
@theta += delta
|
|
47
|
+
when '-'
|
|
48
|
+
@theta -= delta
|
|
49
|
+
when '!'
|
|
51
50
|
@delta = -delta
|
|
52
|
-
when
|
|
53
|
-
@draw_length *= ISQRT2
|
|
54
|
-
when
|
|
55
|
-
@draw_length *= SQRT2
|
|
56
|
-
when
|
|
51
|
+
when 'I'
|
|
52
|
+
@draw_length *= ISQRT2
|
|
53
|
+
when 'Q'
|
|
54
|
+
@draw_length *= SQRT2
|
|
55
|
+
when 'X', 'A', 'B'
|
|
57
56
|
else
|
|
58
57
|
puts("character '#{ch}' not in grammar")
|
|
59
58
|
end
|
|
@@ -66,7 +65,7 @@ attr_reader :points
|
|
|
66
65
|
|
|
67
66
|
def setup
|
|
68
67
|
size(600, 600)
|
|
69
|
-
mpeano = MPeano.new(width/2, height*0.95)
|
|
68
|
+
mpeano = MPeano.new(width / 2, height * 0.95)
|
|
70
69
|
production = mpeano.generate 7 # 7 generations looks OK
|
|
71
70
|
@points = mpeano.translate_rules(production)
|
|
72
71
|
no_loop
|
|
@@ -78,6 +77,4 @@ def draw
|
|
|
78
77
|
points.each_slice(4) do |point|
|
|
79
78
|
line(*point)
|
|
80
79
|
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
end
|
|
@@ -2,57 +2,55 @@
|
|
|
2
2
|
# A Peano fractal implemented using a
|
|
3
3
|
# Lindenmayer System in ruby-processing by Martin Prout
|
|
4
4
|
########################################################
|
|
5
|
-
|
|
5
|
+
load_libraries :grammar, :fastmath, :vecmath
|
|
6
6
|
|
|
7
7
|
class Peano
|
|
8
|
-
include Processing::Proxy
|
|
9
|
-
import 'grammar'
|
|
8
|
+
include Processing::Proxy
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@axiom = "XF" # Axiom
|
|
10
|
+
attr_reader :draw_length, :vec, :theta, :axiom, :grammar
|
|
11
|
+
DELTA = 60 # degrees
|
|
12
|
+
def initialize vec
|
|
13
|
+
@axiom = 'XF' # Axiom
|
|
16
14
|
rules = {
|
|
17
|
-
'X' =>
|
|
18
|
-
|
|
15
|
+
'X' => 'X+YF++YF-FX--FXFX-YF+', # LSystem Rules
|
|
16
|
+
'Y' => '-FX+YFYF++YF+FX--FX-Y'
|
|
19
17
|
}
|
|
20
18
|
@grammar = Grammar.new(axiom, rules)
|
|
21
19
|
@theta = 0
|
|
22
20
|
@draw_length = 100
|
|
23
|
-
@
|
|
24
|
-
@ypos = ypos
|
|
21
|
+
@vec = vec
|
|
25
22
|
end
|
|
26
23
|
|
|
27
24
|
def generate gen
|
|
28
|
-
@draw_length = draw_length *
|
|
25
|
+
@draw_length = draw_length * 0.6**gen
|
|
29
26
|
grammar.generate gen
|
|
30
27
|
end
|
|
31
28
|
|
|
32
29
|
def translate_rules(prod)
|
|
33
|
-
points = [] # An empty array to store line vertices
|
|
30
|
+
points = [] # An empty array to store line vertices as Vec2D
|
|
34
31
|
prod.each do |ch|
|
|
35
32
|
case ch
|
|
36
33
|
when 'F'
|
|
37
|
-
points <<
|
|
34
|
+
points << vec.copy << Vec2D.new(vec.x += draw_length * DegLut.cos(theta), vec.y -= draw_length * DegLut.sin(theta))
|
|
38
35
|
when '+'
|
|
39
36
|
@theta += DELTA
|
|
40
37
|
when '-'
|
|
41
38
|
@theta -= DELTA
|
|
42
39
|
when 'X', 'Y'
|
|
43
40
|
else
|
|
44
|
-
puts("character
|
|
41
|
+
puts("character #{ch} not in grammar")
|
|
45
42
|
end
|
|
46
43
|
end
|
|
47
44
|
return points
|
|
48
45
|
end
|
|
49
46
|
end
|
|
50
47
|
|
|
51
|
-
attr_reader :points
|
|
48
|
+
attr_reader :points, :renderer
|
|
52
49
|
|
|
53
50
|
def setup
|
|
54
51
|
size(800, 800)
|
|
55
|
-
|
|
52
|
+
@renderer = AppRender.new(self)
|
|
53
|
+
peano = Peano.new(Vec2D.new(width * 0.65, height * 0.9))
|
|
56
54
|
production = peano.generate 4 # 4 generations looks OK
|
|
57
55
|
@points = peano.translate_rules(production)
|
|
58
56
|
no_loop
|
|
@@ -68,9 +66,9 @@ def render points
|
|
|
68
66
|
stroke 200.0
|
|
69
67
|
stroke_weight 3
|
|
70
68
|
begin_shape
|
|
71
|
-
points.each_slice(
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
points.each_slice(2) do |v0, v1|
|
|
70
|
+
v0.to_vertex(renderer)
|
|
71
|
+
v1.to_vertex(renderer)
|
|
74
72
|
end
|
|
75
73
|
end_shape
|
|
76
74
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# penrose tiling in ruby processing using LSystems
|
|
3
3
|
# in ruby-processing by Martin Prout
|
|
4
4
|
######################################################
|
|
5
|
-
load_libraries
|
|
5
|
+
load_libraries :grammar, :fastmath
|
|
6
6
|
|
|
7
7
|
attr_reader :penrose
|
|
8
8
|
|
|
@@ -10,9 +10,9 @@ def setup
|
|
|
10
10
|
size 800, 800
|
|
11
11
|
stroke_weight 2
|
|
12
12
|
smooth
|
|
13
|
-
@penrose = PenroseColored.new(width/2, height/2)
|
|
13
|
+
@penrose = PenroseColored.new(width / 2, height / 2)
|
|
14
14
|
penrose.create_grammar 5
|
|
15
|
-
no_loop
|
|
15
|
+
no_loop
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def draw
|
|
@@ -20,7 +20,7 @@ def draw
|
|
|
20
20
|
penrose.render
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Turtle = Struct.new(:x, :y, :angle, :color)
|
|
24
24
|
|
|
25
25
|
#############################
|
|
26
26
|
# penrose_colored.rb
|
|
@@ -28,30 +28,23 @@ end
|
|
|
28
28
|
|
|
29
29
|
class PenroseColored
|
|
30
30
|
include Processing::Proxy
|
|
31
|
-
import 'grammar'
|
|
32
31
|
|
|
33
|
-
attr_reader :axiom, :grammar, :start_length, :theta, :production,
|
|
34
|
-
|
|
32
|
+
attr_reader :axiom, :grammar, :start_length, :theta, :production,
|
|
33
|
+
:draw_length, :repeats, :xpos, :ypos
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
YPOS = 1
|
|
38
|
-
ANGLE = 2
|
|
39
|
-
COL = 3
|
|
40
|
-
DELTA = PI/5 # radians or 36 degrees
|
|
35
|
+
DELTA = 36 # degrees
|
|
41
36
|
RED = 70<<24|200<<16|0<<8|0 # using bit operations to set color int
|
|
42
37
|
BLUE = 70<<24|0<<16|0<<8|200
|
|
43
38
|
|
|
44
|
-
def initialize
|
|
45
|
-
@axiom =
|
|
39
|
+
def initialize(xpos, ypos) # Note use of abbreviated grammar
|
|
40
|
+
@axiom = '[X]2+[X]2+[X]2+[X]2+[X]' # nos, used to indicate repeats
|
|
46
41
|
@grammar = Grammar.new(
|
|
47
|
-
axiom,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"Z" => "2-YBF4+WRF[+ZRF4+XBF]2-XBF",
|
|
54
|
-
}
|
|
42
|
+
axiom,
|
|
43
|
+
'F' => '', # a so called deletion rule
|
|
44
|
+
'W' => 'YBF2+ZRF4-XBF[-YBF4-WRF]2+', # regular substitution rules ....
|
|
45
|
+
'X' => '+YBF2-ZRF[3-WRF2-XBF]+',
|
|
46
|
+
'Y' => '-WRF2+XBF[3+YBF2+ZRF]-',
|
|
47
|
+
'Z' => '2-YBF4+WRF[+ZRF4+XBF]2-XBF'
|
|
55
48
|
)
|
|
56
49
|
@start_length = 1000.0
|
|
57
50
|
@theta = 0
|
|
@@ -70,27 +63,29 @@ class PenroseColored
|
|
|
70
63
|
|
|
71
64
|
def render
|
|
72
65
|
repeats = 1
|
|
73
|
-
|
|
66
|
+
ignored = %w(W X Y Z)
|
|
67
|
+
repeated = %w(1 2 3 4)
|
|
68
|
+
pen = Turtle.new(xpos, ypos, theta, :R) # simple Struct for pen, symbol :R = red
|
|
74
69
|
stack = [] # simple array for stack
|
|
75
70
|
production.each do |element|
|
|
76
71
|
case element
|
|
77
72
|
when 'F'
|
|
78
73
|
pen = draw_line(pen, draw_length)
|
|
79
74
|
when '+'
|
|
80
|
-
pen
|
|
75
|
+
pen.angle += DELTA * repeats
|
|
81
76
|
repeats = 1
|
|
82
77
|
when '-'
|
|
83
|
-
pen
|
|
78
|
+
pen.angle -= DELTA * repeats
|
|
84
79
|
repeats = 1
|
|
85
80
|
when '['
|
|
86
|
-
stack
|
|
81
|
+
stack << pen.dup # push a copy current pen to stack
|
|
87
82
|
when ']'
|
|
88
83
|
pen = stack.pop # assign current pen to instance off the stack
|
|
89
84
|
when 'R', 'B'
|
|
90
|
-
pen
|
|
91
|
-
when
|
|
92
|
-
when
|
|
93
|
-
repeats =
|
|
85
|
+
pen.color = element.to_sym # set pen color as symbol
|
|
86
|
+
when *ignored
|
|
87
|
+
when *repeated
|
|
88
|
+
repeats = element.to_i
|
|
94
89
|
else puts "Character '#{element}' not in grammar"
|
|
95
90
|
end
|
|
96
91
|
end
|
|
@@ -106,18 +101,17 @@ class PenroseColored
|
|
|
106
101
|
end
|
|
107
102
|
|
|
108
103
|
private
|
|
104
|
+
|
|
109
105
|
####################################################################
|
|
110
106
|
# draws line using current pen position, color and length parameters
|
|
111
107
|
# returns a pen corresponding to the new position
|
|
112
108
|
###################################################################
|
|
113
109
|
|
|
114
110
|
def draw_line(pen, length)
|
|
115
|
-
stroke
|
|
116
|
-
new_xpos = pen
|
|
117
|
-
new_ypos = pen
|
|
118
|
-
line(pen
|
|
119
|
-
|
|
111
|
+
stroke(pen.color == :R ? RED : BLUE)
|
|
112
|
+
new_xpos = pen.x - length * DegLut.cos(pen.angle)
|
|
113
|
+
new_ypos = pen.y - length * DegLut.sin(pen.angle)
|
|
114
|
+
line(pen.x, pen.y, new_xpos, new_ypos) # draw line
|
|
115
|
+
Turtle.new(new_xpos, new_ypos, pen.angle, pen.color) # return pen @ new pos
|
|
120
116
|
end
|
|
121
117
|
end
|
|
122
|
-
|
|
123
|
-
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
load_libraries :grammar, :fastmath
|
|
2
2
|
|
|
3
3
|
class PenroseSnowflake
|
|
4
4
|
include Processing::Proxy
|
|
5
|
-
import 'grammar'
|
|
6
5
|
|
|
7
|
-
attr_accessor :axiom, :grammar, :start_length, :theta, :production,
|
|
8
|
-
:
|
|
9
|
-
DELTA =
|
|
6
|
+
attr_accessor :axiom, :grammar, :start_length, :theta, :production,
|
|
7
|
+
:draw_length, :xpos, :ypos
|
|
8
|
+
DELTA = 18 # degrees as radians
|
|
10
9
|
|
|
11
10
|
def initialize xpos, ypos
|
|
12
|
-
@axiom =
|
|
13
|
-
@grammar = Grammar.new(
|
|
14
|
-
{"F" => "F3-F3-F45-F++F3-F"}
|
|
15
|
-
)
|
|
11
|
+
@axiom = 'F3-F3-F3-F3-F'
|
|
12
|
+
@grammar = Grammar.new(axiom, 'F' => 'F3-F3-F45-F++F3-F')
|
|
16
13
|
@start_length = 450.0
|
|
17
14
|
@theta = 0
|
|
18
15
|
@xpos = xpos
|
|
@@ -48,7 +45,7 @@ class PenroseSnowflake
|
|
|
48
45
|
|
|
49
46
|
##########################################
|
|
50
47
|
# adjust draw length with number of repeats
|
|
51
|
-
# uses grammar to set production string
|
|
48
|
+
# uses grammar to set production string
|
|
52
49
|
# see 'grammar.rb'
|
|
53
50
|
##########################################
|
|
54
51
|
|
|
@@ -56,7 +53,7 @@ class PenroseSnowflake
|
|
|
56
53
|
@draw_length *= 0.4**gen
|
|
57
54
|
@production = grammar.generate gen
|
|
58
55
|
end
|
|
59
|
-
|
|
56
|
+
|
|
60
57
|
###########################################
|
|
61
58
|
# a helper method that returns dx or dy with type & repeat
|
|
62
59
|
# multiplier after Dan Mayer
|
|
@@ -65,7 +62,7 @@ class PenroseSnowflake
|
|
|
65
62
|
def multiplier(repeats, type)
|
|
66
63
|
value = draw_length * repeats
|
|
67
64
|
# using equal? for identity comparison
|
|
68
|
-
(type.equal? :cos)? value * cos(theta) : value * sin(theta)
|
|
65
|
+
(type.equal? :cos)? value * DegLut.cos(theta) : value * DegLut.sin(theta)
|
|
69
66
|
end
|
|
70
67
|
end
|
|
71
68
|
|
|
@@ -82,12 +79,10 @@ def setup
|
|
|
82
79
|
stroke 255
|
|
83
80
|
@penrose = PenroseSnowflake.new width * 0.8, height * 0.95
|
|
84
81
|
penrose.create_grammar 4
|
|
85
|
-
no_loop
|
|
82
|
+
no_loop
|
|
86
83
|
end
|
|
87
84
|
|
|
88
85
|
def draw
|
|
89
86
|
background 0
|
|
90
87
|
penrose.render
|
|
91
88
|
end
|
|
92
|
-
|
|
93
|
-
|
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
############################
|
|
2
2
|
# pentagonal.rb here I roll one of my own
|
|
3
3
|
###########################
|
|
4
|
-
load_library
|
|
4
|
+
load_library :grammar, :fastmath
|
|
5
5
|
|
|
6
6
|
class Pentagonal
|
|
7
7
|
include Processing::Proxy
|
|
8
|
-
|
|
9
|
-
DELTA = (Math::PI/180) * 72.0 # convert degrees to radians
|
|
8
|
+
DELTA = 72 # degrees
|
|
10
9
|
attr_accessor :draw_length
|
|
11
10
|
attr_reader :axiom, :grammar, :theta, :production, :xpos, :ypos
|
|
12
|
-
def initialize
|
|
13
|
-
@axiom =
|
|
14
|
-
@grammar = Grammar.new(
|
|
15
|
-
{"F" => "F+F+F-F-F-F+F+F"}
|
|
16
|
-
)
|
|
11
|
+
def initialize
|
|
12
|
+
@axiom = 'F-F-F-F-F'
|
|
13
|
+
@grammar = Grammar.new(axiom, 'F' => 'F+F+F-F-F-F+F+F')
|
|
17
14
|
@draw_length = 400
|
|
18
15
|
@theta = 0.0
|
|
19
16
|
@xpos = 0.0
|
|
20
17
|
@ypos = 0.0
|
|
21
18
|
end
|
|
22
|
-
|
|
19
|
+
|
|
23
20
|
##############################
|
|
24
21
|
# create grammar from axiom and
|
|
25
22
|
# rules (adjust scale)
|
|
26
23
|
##############################
|
|
27
|
-
|
|
24
|
+
|
|
28
25
|
def create_grammar(gen)
|
|
29
26
|
@draw_length *= 0.25**gen
|
|
30
27
|
@production = grammar.generate gen
|
|
31
|
-
end
|
|
32
|
-
|
|
28
|
+
end
|
|
29
|
+
|
|
33
30
|
def make_shape
|
|
34
31
|
no_fill
|
|
35
32
|
shape = create_shape
|
|
@@ -40,25 +37,25 @@ class Pentagonal
|
|
|
40
37
|
production.each do |element|
|
|
41
38
|
case element
|
|
42
39
|
when 'F' # you could use processing transforms here, I prefer to do the Math
|
|
43
|
-
shape.vertex(@xpos -= adjust(:cos), @ypos += adjust(:sin))
|
|
40
|
+
shape.vertex(@xpos -= adjust(:cos), @ypos += adjust(:sin))
|
|
44
41
|
when '+'
|
|
45
|
-
@theta += DELTA
|
|
42
|
+
@theta += DELTA
|
|
46
43
|
when '-'
|
|
47
|
-
@theta -= DELTA
|
|
48
|
-
else puts
|
|
44
|
+
@theta -= DELTA
|
|
45
|
+
else puts 'Grammar not recognized'
|
|
49
46
|
end
|
|
50
47
|
end
|
|
51
48
|
shape.end_shape
|
|
52
49
|
return shape
|
|
53
50
|
end
|
|
54
|
-
|
|
51
|
+
|
|
55
52
|
###########################################
|
|
56
53
|
# a helper method that returns dx or dy with type
|
|
57
54
|
###########################################
|
|
58
|
-
|
|
55
|
+
|
|
59
56
|
def adjust(type)
|
|
60
57
|
# using equal? for identity comparison
|
|
61
|
-
(type.equal? :cos)? draw_length * cos(theta) : draw_length *
|
|
58
|
+
(type.equal? :cos)? draw_length * DegLut.cos(theta) : draw_length * DegLut.sin(theta)
|
|
62
59
|
end
|
|
63
60
|
end
|
|
64
61
|
|
|
@@ -67,7 +64,7 @@ end
|
|
|
67
64
|
# Lindenmayer System in ruby-processing by Martin Prout
|
|
68
65
|
###
|
|
69
66
|
|
|
70
|
-
# Empirically determined pstition
|
|
67
|
+
# Empirically determined pstition adjustments
|
|
71
68
|
ADJUST = [[800, 50], [500, 500], [500, 500], [300, 280], [50, 600]]
|
|
72
69
|
|
|
73
70
|
attr_reader :pentagonal, :pentive
|
|
@@ -82,7 +79,7 @@ def setup
|
|
|
82
79
|
end
|
|
83
80
|
|
|
84
81
|
def draw
|
|
85
|
-
background 0
|
|
82
|
+
background 0
|
|
86
83
|
shape(pentive)
|
|
87
84
|
end
|
|
88
85
|
|
|
@@ -94,10 +91,10 @@ def key_pressed
|
|
|
94
91
|
pentagonal.create_grammar gen
|
|
95
92
|
@pentive = pentagonal.make_shape
|
|
96
93
|
pentive.translate(ADJUST[gen - 1][0], ADJUST[gen - 1][1])
|
|
97
|
-
else
|
|
94
|
+
else
|
|
98
95
|
@pentagonal = Pentagonal.new
|
|
99
96
|
pentagonal.create_grammar 2
|
|
100
97
|
@pentive = pentagonal.make_shape
|
|
101
98
|
pentive.translate(ADJUST[1][0], ADJUST[1][1])
|
|
102
99
|
end
|
|
103
|
-
end
|
|
100
|
+
end
|