Sha256: c25427b98a23ed76b8c9ff0dc047ff079be5c3c6f43e574f1959eaf0dcd2696e

Contents?: true

Size: 547 Bytes

Versions: 9

Compression:

Stored size: 547 Bytes

Contents

# A class to describe a Polygon (with a PShape)

class Polygon
  include Processing::Proxy
  # The PShape object
  attr_reader :s, :x, :y, :speed, :height

  def initialize(s_, width, height)
    @x = rand(width)
    @y = rand(-500 .. -100)
    @s = s_
    @speed = rand(2 .. 6)
    @height = height
  end
  
  # Simple motion
  def move
    @y +=speed
    @y = -100 if (y > height + 100)
  end
  
  # Draw the object
  def display
    push_matrix
    translate(x, y)
    shape(s)
    pop_matrix
  end
  
  def run
    display
    move
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby-processing-2.6.2 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb
ruby-processing-2.6.1 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb
ruby-processing-2.6.0 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb
ruby-processing-2.5.1 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb
ruby-processing-2.5.0 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb
ruby-processing-2.4.4 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb
ruby-processing-2.4.3 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb
ruby-processing-2.4.2 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb
ruby-processing-2.4.1 samples/processing_app/topics/create_shapes/library/polygon/polygon.rb