Another context free DSL example, better annotated, control panel and library as previous post (not shown):-
# cube.rb
load_libraries :test_free, :control_panel
attr_reader :xrot, :yrot, :zrot
def setup_the_spiral
@spiral = ContextFree.define do # define the cf rules
rule :cubeform do
5.times do |i|
split do # record the context
cuby :ry => 72 * i
rewind # restore the context
end
end
end
rule :beam do
6.times do |i|
split do # record the context
cube :y => 0.2 * i
rewind # restore the context
end
end
end
rule :cuby do
beam :brightness => 1
cuby :size => 0.98, :y => -0.24 # recursive call ends when size < 1
end
end
end
def setup # static setup
size 800, 800, P3D # I can only use P3D (unless full_screen) on linux opengl might work on mac/windows
configure_control
smooth
setup_the_spiral
end
def configure_control # setup control panel gui
control_panel do |c|
c.title = "Attitude Control"
c.slider :xrot, -3.1..3.1, 0.5
c.slider :yrot, -3.1..3.1, 0.5
c.slider :zrot, -3.1..3.1, 1.0
end
end
def draw # animation loop
background 0.8
lights
@spiral.render :cubeform, :start_x => 0, :start_y => 10, :start_z => -30, :size => height/300, :stop_size => 1, :color => [0, 0.8, 0.8]
@spiral.rotate_x xrot
@spiral.rotate_y yrot
@spiral.rotate_z zrot
end
Within the sketch :hue, :saturation and :brightness can be individually set. If you want to use :alpha, initialize :color with a 4 dimension array. Note, the color mode in the ruleset is hsb with range 0 .. 1.0. Increment and decrement is linear cf size where it is multiplicative.
Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0
Thursday, 9 September 2010
Subscribe to:
Post Comments (Atom)
Followers
Blog Archive
-
▼
2010
(73)
-
▼
September
(15)
- Basic Hair Example SunflowAPIAPI just using jruby
- Basic Hair Example SunflowAPIAPI in ruby processing
- SunflowAPIAPI in ruby processing
- A Staffordshire Knot Using Ruby Processing and A C...
- An Infinity Loop? With My 3D Context Free Library
- Revised 3D Context Free DSL Sketch, with Mouse Whe...
- A Mouse Wheel Listener in Ruby Processing
- 3D Context Free DSL Screen Saver?
- Translating the default.es to ruby processing DSL
- Testing the cube primitive in my context free DSL
- Experimental 3D Context Free DSL in ruby-processin...
- Using the control panel and Toxi Processing Libra...
- Tone map example of Gray-Scott diffusion using tox...
- Another Example of Using Toxi Processing Libraries
- Using the Toxi Processing Libraries in ruby proces...
-
▼
September
(15)
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