Sha256: fe73dd46f729f222e4a71039a05f6e4e29be491e9ac70e3bcf607198ddd3ccc0

Contents?: true

Size: 707 Bytes

Versions: 4

Compression:

Stored size: 707 Bytes

Contents

require 'ruby-processing'

class LinesOneAtATime < Processing::App
  
  # No for loop here. Instead, a global variable.
  # In ruby, global variables start with $.
  $y = 0
  
  def setup
    background 255
    # Slowing down the frame rate so we can easily see the effect.
    frame_rate 5
  end
  
  def draw
    # Draw a line
    stroke 0 
    # Only one line is drawn each time through draw.
    line 0, $y, width, $y  
    # Increment y
    $y += 10

    # Reset y back to 0 when it gets to the bottom of window
    # In ruby, you can put if statements at the end, like speaking.
    $y = 0 if $y > height
  end
  
end

LinesOneAtATime.new :title => "Lines One At A Time", :width => 200, :height => 200

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-processing-1.0.1 samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb
ruby-processing-1.0.2 samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb
ruby-processing-1.0.3 samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb
ruby-processing-1.0.4 samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb