Sha256: c7ba9dae1a7898e8a90bb4f2e0f919e5fbd16f79ebe87c7de1e58c0a4cb7e475

Contents?: true

Size: 699 Bytes

Versions: 9

Compression:

Stored size: 699 Bytes

Contents

# Double Random 
# by Ira Greenberg.  
# 
# Using two rand(..) calls and the point() function to 
# create an irregular sawtooth line. The noise line guards 
# against an illegal input to rand range when min > max, 
# and to return min as vanilla processing does 
# (NB: the sawtooth relies on this)

attr_reader :steps

def setup  
  size 640, 360  
  frame_rate(1) 
  total_pts = 300  
  @steps = total_pts + 1.0
  stroke_weight 2
  stroke 255  
end

def draw
  background 0
  rand_y = 0.0  
  (1 ... steps).each do |i|
    noise_y = (rand_y > 0)? rand(-rand_y .. rand_y) : rand(rand_y .. -rand_y)    
    point( (width/steps) * i, (height/2) + noise_y )
    rand_y += rand(-5 .. 5)  
  end
end


Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby-processing-2.6.2 samples/processing_app/basics/math/double_random.rb
ruby-processing-2.6.1 samples/processing_app/basics/math/double_random.rb
ruby-processing-2.6.0 samples/processing_app/basics/math/double_random.rb
ruby-processing-2.5.1 samples/processing_app/basics/math/double_random.rb
ruby-processing-2.5.0 samples/processing_app/basics/math/double_random.rb
ruby-processing-2.4.4 samples/processing_app/basics/math/double_random.rb
ruby-processing-2.4.3 samples/processing_app/basics/math/double_random.rb
ruby-processing-2.4.2 samples/processing_app/basics/math/double_random.rb
ruby-processing-2.4.1 samples/processing_app/basics/math/double_random.rb