Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Saturday, 11 September 2010

3D Context Free DSL Screen Saver?

Here is an animated version of the default.es from StructureSynth in ruby-processing. Mac or windows users might want to experiment with OPENGL rendering, as this sketch exposes errors in processing P3D, I see odd missing pixels from time to time. If you don't like the holes remove the smooth, personally I prefer the holes to the glitchty non-smooth (it is a known issue with current versions of processing with both P2D and P3D renderers, something to do with tessellation algorithms).  The test_free library is as in previous post.
Nest the library as follows:-
library/test_free/test_free.rb in the folder containing the sketch
For instructions for installing ruby-processing follow the first link in the blog header.


# full_screen.rb
# An animation of default.es
# the StructureSynth default script

load_libraries :test_free
full_screen
attr_reader :xrot, :yrot, :zrot

def setup_the_spiral
  @spiral = ContextFree.define do

    rule :default do
      split do
      R1 :brightness => 1
      rewind
      R2 :brightness => 1
    end
    end

    rule :R1 do                      
      sphere :brightness => 1
      R1 :size => 0.99, :x => 0.25, :rz => 6, :ry => 6
    end

    rule :R2 do                      
      sphere :brightness => 1
      R2 :size => 0.99, :x => -0.25, :rz => 6, :ry => 6
    end

  end
end

def setup
  render_mode P3D
  smooth
  @xrot = 0.01
  @yrot = 0
  @zrot = 0
  setup_the_spiral
end

def draw
  background 0
  lights
  smooth_rotation(6.7, 7.3)
  @spiral.render :default, :start_x => 0, :start_y => 0, :start_z => -50, :size => height/350,
  :stop_size => 0.2, :color => [0, 0.8, 0.8], :rx => xrot, :ry => yrot, :rz => zrot
end

##
# Generate a vector whose components change smoothly over time in the range [ 0, 1 ].
# Each component uses a Math.sin() function to map the current time in milliseconds somewhere
# in the range [ 0, 1 ].A 'speed' factor is specified for each component.
#
def smooth_vector(s1, s2)
  mills = millis * 0.00003
  y = 0.5 * Math.sin(mills * s1) + 0.5
  z = 0.5 * Math.sin(mills * s2) + 0.5
  vec = [y, z]
end

##
# Rotate the current coordinate system.
# Uses smooth_vector() to smoothly animate the rotation.
#
def smooth_rotation(s1, s2)
  r1 = smooth_vector(s1, s2)
  @yrot = (2.0 * Math::PI * r1[0])
  @zrot = (2.0 * Math::PI * r1[1])
end






No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2