Sha256: 8e338ecf20d8a8da598e136c4c07405132bef82f20854648707774237625aa33

Contents?: true

Size: 955 Bytes

Versions: 10

Compression:

Stored size: 955 Bytes

Contents

#
# PolygonPShapeOOP. 
# 
# Wrapping a PShape inside a custom class 
# and demonstrating how we can have a multiple objects each
# using the same PShape.
#
load_library 'polygon'

# A list of objects
attr_reader :polygons

def setup
  size(640, 360, P2D)
  smooth
  # Make a PShape
  star = createShape
  star.beginShape
  star.noStroke
  star.fill(0, 127)
  star.vertex(0, -50)
  star.vertex(14, -20)
  star.vertex(47, -15)
  star.vertex(23, 7)
  star.vertex(29, 40)
  star.vertex(0, 25)
  star.vertex(-29, 40)
  star.vertex(-23, 7)
  star.vertex(-47, -15)
  star.vertex(-14, -20)
  star.endShape(CLOSE)

  @polygons = []
  
  # Add a bunch of objects to the ArrayList
  # Pass in reference to the PShape
  # We coud make polygons with different PShapes
  25.times do
    polygons << Polygon.new(star, width, height)
  end
end

def draw
  background(255)

  # Display and move them all
  polygons.each do |poly|
    poly.display
    poly.move
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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