Sha256: a398e45f2ecdbb79f78b84f4a2cdea2d5f31a8bde3dd484f7aab3af866b20329
Contents?: true
Size: 1.34 KB
Versions: 4
Compression:
Stored size: 1.34 KB
Contents
require 'ruby-processing' class PyramidUsingBeginshape < Processing::App def setup render_mode P3D end def draw background 255 stroke 0 # The pyramid's vertices are drawn relative to a centerpoint. # Therefore, we call translate to place the pyramid properly in the window. # A slightly better option might be to include the translate in the draw_pyramid function and pass in x,y,z as arguments translate 100, 100, 0 draw_pyramid 150 end # The function sets the vertices for the pyramid around the centerpoint at a flexible distance, # depending on the number passed in as an argument. def draw_pyramid(t) # this pyramid has 4 sides, each drawn as a separate triangle # each side has 3 vertices, making up a triangle shape # the parameter " t " determines the size of the pyramid begin_shape TRIANGLES fill 255, 150 # Note that each polygon can have its own color. vertex -t,-t,-t vertex t,-t,-t vertex 0, 0, t fill 150, 150 vertex t,-t,-t vertex t, t,-t vertex 0, 0, t fill 255, 150 vertex t, t,-t vertex -t, t,-t vertex 0, 0, t fill 150, 150 vertex -t, t,-t vertex -t,-t,-t vertex 0, 0, t end_shape end end PyramidUsingBeginshape.new :title => "Draw Pyramid Using BeginShape", :width => 200, :height => 200
Version data entries
4 entries across 4 versions & 1 rubygems