Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Committer: Martin Prout <martin_p@lineone.net>

	modified:   context_free.rb
	new file:   samples/levy.rb
  • Loading branch information...
commit 4c94f7ff403207c32244e0e224d7f7610f155c93 1 parent 5440226
Martin Prout authored committed
Showing with 45 additions and 5 deletions.
  1. +5 −5 context_free.rb
  2. +40 −0 samples/levy.rb
View
10 context_free.rb
@@ -9,8 +9,8 @@ class ContextFree
attr_accessor :rules, :app
- AVAILABLE_OPTIONS = [:x, :y, :rotation, :size, :flip, :color, :hue, :saturation, :brightness]
- HSB_ORDER = {:hue => 0, :saturation => 1, :brightness => 2}
+ AVAILABLE_OPTIONS = [:x, :y, :rotation, :size, :flip, :color, :hue, :saturation, :brightness, :alpha]
+ HSB_ORDER = {:hue => 0, :saturation => 1, :brightness => 2, :alpha => 3}
TRIANGLE_TOP = -1 / Math.sqrt(3)
TRIANGLE_BOTTOM = Math.sqrt(3) / 6
@@ -94,7 +94,7 @@ def merge_options(old_ops, new_ops)
old_ops[key] = value * old_ops[:size]
when :rotation
old_ops[key] = value * (Math::PI / 180.0)
- when :hue, :saturation, :brightness
+ when :hue, :saturation, :brightness, :alpha
adjusted = old_ops[:color].dup
adjusted[HSB_ORDER[key]] *= value
old_ops[:color] = adjusted
@@ -167,7 +167,7 @@ def render(rule_name, starting_values={})
:rotation => 0, :flip => false,
:size => 20, :width => 20, :height => 20,
:start_x => width/2, :start_y => height/2,
- :color => [0.5, 0.5, 0.5],
+ :color => [0.5, 0.5, 0.5, 1],
:stop_size => 1.5}
@values.merge!(starting_values)
@finished = false
@@ -175,7 +175,7 @@ def render(rule_name, starting_values={})
@app.rect_mode CENTER
@app.ellipse_mode CENTER
@app.no_stroke
- @app.color_mode HSB, 1.0
+ @app.color_mode HSB, 1.0, 1.0, 1.0, 1.0
@app.translate @values[:start_x], @values[:start_y]
self.send(rule_name, {})
end
View
40 samples/levy.rb
@@ -0,0 +1,40 @@
+# levy.rb ruby-processing NB: :alpha is not implemented in vanilla ruby-processing
+load_library 'context_free'
+
+def setup_the_levy
+ @levy = ContextFree.define do
+ rule :start do
+ levy :brightness => 0.9
+ end
+ rule :levy do
+ square :alpha => 0.1
+ split do
+ levy :size => 1/Math.sqrt(2), :rotation => -45, :x => 0.5, :brightness => 0.9
+ rewind
+ levy :size => 1/Math.sqrt(2), :rotation => 45, :x => 0.5, :brightness => 0.9
+ rewind
+ end
+ end
+ end
+end
+
+
+def setup
+ size 400, 400
+ setup_the_levy
+ smooth
+ draw_it
+ save_frame("levy.png")
+end
+
+
+def draw
+ # Do nothing.
+end
+
+
+def draw_it
+ background 255
+ @levy.render :start, :size => 250, :stop_size => 2,
+ :start_x => width/4, :start_y => height/2
+end
Please sign in to comment.
Something went wrong with that request. Please try again.