load_library 'context_free'
def setup_the_spots
@spots = ContextFree.define do
class << self
define_method (:rand_range) do |max, min| # nice to have a range
rand * (max - min) + min
end
end
rule :region do
split do
block :x => -0.25, :y => -0.25, :brightness => 1.0, :saturation => 1.0
rewind
block :x => 0.25, :y => -0.25, :brightness => 1.0, :saturation => 1.0
rewind
block :x => 0.25, :y => 0.25, :brightness => 1.0, :saturation => 1.0
rewind
block :x => -0.25, :y => 0.25, :brightness => 1.0, :saturation => 1.0
end
end
rule :block do
spots :size => 0.85, :hue => rand, :saturation => rand_range(1.0, 0.8), :brightness => rand_range(1.0, 0.8)
end
rule :block, 5 do
region :size => 0.5, :rotation => rand_range(8, 4), :hue => rand_range(0.8, 0.5), :saturation => rand_range(1.0, 0.5), :brightness => rand_range(1.0, 0.5)
end
rule :block, 0.1 do
# Do nothing
end
rule :spots do
circle :hue => rand_range(0.8, 0.5), :saturation => 1.0, :brightness => 1.0, :alpha => 0.4
end
end
end
def setup
size 600, 600
background 255, 255, 0
smooth
color_mode HSB, 1.0
setup_the_spots
draw_it
end
def draw
# Do nothing
end
def draw_it
@spots.render :region, :color => [0.2, 1.0, 1.0, 1.0],
:start_x => width/2, :start_y => height/2,
:size => height/2.5
end
def mouse_clicked
draw_it
end

No comments:
Post a Comment