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

Saturday, 30 October 2010

Revised Perlin Noise Sketch (to use pixel array)

A somewhat optimized sketch, makes use of processing pixel array functionality, takes a little time to "warm-up". Original used P3D mode, probably should have been P2D (apparently better than default for pixel array type sketches)....


##################################################
# amp_zoom_in.rb
# adapted from a sketch at http://www.biothing.org
##################################################
attr_reader :col, :a, :b, :c, :k, :amp, :time

def setup()
  size(640, 480, P2D)
  color_mode(RGB, 1.0)
  frame_rate(4)
  load_pixels()
  reset
end

def draw()
  @time += 0.1   #step ahead in time with each frame
  #now go through each pixel in the window:

  (0...width).each do |x|
    (0...height).each do |y|
      #create values with trig functions, noise, etc acting on x,y and time.  
      #experiment with how these values are modulating over time.

      @a = dist(x, y, width/2, height/2)
      @b= (cos(x/360.0 + time)).abs         # frequency larger means less
      @c = noise(y/180.0*cos(time/20.0))    # inteference, larger means less
      @amp = k                              # amplitude

      @col = color((cos(a/120.0 + b + c * 10.0).abs)) * amp
      #combine values into a color somehow.  again the possibilities are limitless
      begin
        pixels[y * width + x] = col
      rescue
        reset        
      end
    end
  end
  update_pixels()
  @k += 1 
end

def reset
  @k = 0
  @time = 0
end





No comments:

Post a Comment

Followers

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