1- require 'picrate'
2- # Drawolver: draw 2D & revolve 3D
1+ # frozen_string_literal: true
32
3+ require 'picrate'
44# Example to show how to use the VecMath library.
55# Also the Array is extended to yield one_of_each using a module
66# pair of pts. See the drawolver library. Also features the use each_cons,
@@ -11,32 +11,33 @@ class ModuleTwo < Processing::App
1111
1212 def setup
1313 sketch_title 'Module Two'
14- @renderer = Java ::MonkstoneVecmath ::GfxRender . new ( self . g )
14+ @renderer = Java ::MonkstoneVecmath ::GfxRender . new ( g )
1515 frame_rate 30
1616 reset_scene
1717 end
1818
1919 def draw
2020 background 0
21- if ( ! drawing_mode )
21+ unless drawing_mode
2222 translate ( width / 2 , height / 2 )
2323 rotate_x rot_x
2424 rotate_y rot_y
2525 @rot_x += 0.01
2626 @rot_y += 0.02
27- translate ( -width / 2 , -height / 2 )
27+ translate ( -width / 2 , -height / 2 )
2828 end
2929 no_fill
3030 stroke 255
3131 points . each_cons ( 2 ) { |ps , pe | line ps . x , ps . y , pe . x , pe . y }
3232 return if drawing_mode
33+
3334 stroke 125
3435 fill 120
3536 lights
3637 ambient_light 120 , 120 , 120
3738 vertices . each_cons ( 2 ) do |r1 , r2 |
3839 begin_shape ( TRIANGLE_STRIP )
39- ext_array = [ r1 , r2 ] . extend ExtendedArray # extend an instance of Array
40+ ext_array = [ r1 , r2 ] . extend ExtendedArray # extend an instance of Array
4041 ext_array . one_of_each do |v1 , v2 |
4142 v1 . to_vertex ( renderer )
4243 v2 . to_vertex ( renderer )
@@ -68,18 +69,18 @@ def mouse_released
6869
6970 def recalculate_shape
7071 @vertices = [ ]
71- points . each_cons ( 2 ) do |ps , pe |
72+ points . each_cons ( 2 ) do |ps , _pe |
7273 b = points . last - points . first
7374 len = b . mag
7475 b . normalize!
7576 a = ps - points . first
7677 dot = a . dot b
77- b = b * dot
78+ b *= dot
7879 normal = points . first + b
7980 c = ps - normal
8081 nlen = c . mag
8182 vertices << [ ]
82- ( 0 ..TAU ) . step ( PI / 15 ) do |ang |
83+ ( 0 ..TAU ) . step ( PI / 15 ) do |ang |
8384 e = normal + c * Math . cos ( ang )
8485 e . z = c . mag * Math . sin ( ang )
8586 vertices . last << e
@@ -97,12 +98,12 @@ module ExtendedArray
9798 # send one item from each array, expects array to be 2D:
9899 # array [[1,2,3], [a,b,c]] sends
99100 # [1,a] , [2,b] , [3,c]
100- def one_of_each ( & block )
101+ def one_of_each
101102 i = 0
102103 one = self [ 0 ]
103104 two = self [ 1 ]
104105 mi = one . length > two . length ? two . length : one . length
105- while i < mi do
106+ while i < mi
106107 yield ( one [ i ] , two [ i ] )
107108 i += 1
108109 end
0 commit comments