Sha256: e5968cf5d80b81fda436995bf6654279de704ba2a66e3ff106e03fd96ca7f5ca
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
require 'ruby-processing/app' # require Processing::Proxi class Cube include Processing::Proxy # mixin Processing::Proxi attr_accessor :vertices attr_accessor :w, :h, :d attr_accessor :position, :speed, :rotation # PVector def initialize ( w, h, d ) @w, @h, @d = w, h, d w2 = @w/2 h2 = @h/2 d2 = @d/2 tfl = PVector.new -w2, h2, d2 # four points making the top quad: tfr = PVector.new w2, h2, d2 # "tfl" is "top front left", etc tbr = PVector.new w2, h2,-d2 tbl = PVector.new -w2, h2,-d2 bfl = PVector.new -w2,-h2, d2 # bottom quad points bfr = PVector.new w2,-h2, d2 bbr = PVector.new w2,-h2,-d2 bbl = PVector.new -w2,-h2,-d2 @vertices = [ [tfl, tfr, tbr, tbl], # top [tfl, tfr, bfr, bfl], # front [tfl, tbl, bbl, bfl], # left [tbl, tbr, bbr, bbl], # back [tbr, tfr, bfr, bbr], # right [bfl, bfr, bbr, bbl] ] end def draw ( side_colors = nil ) @vertices.each_with_index { |quad, i| # each face begin_shape QUADS fill side_colors[i] if side_colors && i < side_colors.length quad.each { |pvec| vertex pvec.x, pvec.y, pvec.z } end_shape } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-processing-1.0.11 | samples/processing_app/3D/transform/cubes_in_cube/cube.rb |
ruby-processing-1.0.10.1 | samples/processing_app/3D/transform/cubes_in_cube/cube.rb |