Regular context free can't do dynamic random, here I experiment with the possibilities of ruby-processing DSL. This example is essentially a modified city.rb that is included as a sample with the application. Note I have added a convenience method rand_range for use in the DSL, partly as an experiment in ways of extending the program.
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
Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0
Wednesday 11 November 2009
Dynamic rand with ruby-processing context-free DSL
Labels:
context free,
DSL,
random,
ruby processing
Subscribe to:
Post Comments (Atom)
Followers
Blog Archive
-
▼
2009
(50)
-
▼
November
(18)
- Koch curve using l-systems
- Towards a forest, or too many matrix calls
- Seaweed using Lindenmayer system on ruby processing
- A basic example of a plant Lindenmayer systems in...
- Pentagonal Fractal
- Minkowski island using L-System in ruby processing
- Sierpinski Fractal Implemented in ruby-processing ...
- Snake Kolam Ruby Processing
- Penrose Snowflake L-Systems using ruby-processing
- Dragon Fractal Using L-Systems and ruby-processing
- Koch Island Using Lindemayer System in Ruby Proces...
- Lindenmayer system in ruby-processing
- Tessellated "curvy" triangles in ruby-processing
- Dynamic rand with ruby-processing context-free DSL
- Flower in ruby-processing DSL
- Heighway Dragon in ruby-processing context free DSL
- Lévy curve implemented in ruby-processing context ...
- jEdit as a cross platform GUI?
-
▼
November
(18)
About Me
- monkstone
- I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2
No comments:
Post a Comment