1
- require 'picrate'
2
- # Drawolver: draw 2D & revolve 3D
1
+ # frozen_string_literal: true
3
2
3
+ require 'picrate'
4
4
# Example to show how to use the VecMath library.
5
5
# Also the Array is extended to yield one_of_each using a module
6
6
# pair of pts. See the drawolver library. Also features the use each_cons,
@@ -11,32 +11,33 @@ class ModuleTwo < Processing::App
11
11
12
12
def setup
13
13
sketch_title 'Module Two'
14
- @renderer = Java ::MonkstoneVecmath ::GfxRender . new ( self . g )
14
+ @renderer = Java ::MonkstoneVecmath ::GfxRender . new ( g )
15
15
frame_rate 30
16
16
reset_scene
17
17
end
18
18
19
19
def draw
20
20
background 0
21
- if ( ! drawing_mode )
21
+ unless drawing_mode
22
22
translate ( width / 2 , height / 2 )
23
23
rotate_x rot_x
24
24
rotate_y rot_y
25
25
@rot_x += 0.01
26
26
@rot_y += 0.02
27
- translate ( -width / 2 , -height / 2 )
27
+ translate ( -width / 2 , -height / 2 )
28
28
end
29
29
no_fill
30
30
stroke 255
31
31
points . each_cons ( 2 ) { |ps , pe | line ps . x , ps . y , pe . x , pe . y }
32
32
return if drawing_mode
33
+
33
34
stroke 125
34
35
fill 120
35
36
lights
36
37
ambient_light 120 , 120 , 120
37
38
vertices . each_cons ( 2 ) do |r1 , r2 |
38
39
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
40
41
ext_array . one_of_each do |v1 , v2 |
41
42
v1 . to_vertex ( renderer )
42
43
v2 . to_vertex ( renderer )
@@ -68,18 +69,18 @@ def mouse_released
68
69
69
70
def recalculate_shape
70
71
@vertices = [ ]
71
- points . each_cons ( 2 ) do |ps , pe |
72
+ points . each_cons ( 2 ) do |ps , _pe |
72
73
b = points . last - points . first
73
74
len = b . mag
74
75
b . normalize!
75
76
a = ps - points . first
76
77
dot = a . dot b
77
- b = b * dot
78
+ b *= dot
78
79
normal = points . first + b
79
80
c = ps - normal
80
81
nlen = c . mag
81
82
vertices << [ ]
82
- ( 0 ..TAU ) . step ( PI / 15 ) do |ang |
83
+ ( 0 ..TAU ) . step ( PI / 15 ) do |ang |
83
84
e = normal + c * Math . cos ( ang )
84
85
e . z = c . mag * Math . sin ( ang )
85
86
vertices . last << e
@@ -97,12 +98,12 @@ module ExtendedArray
97
98
# send one item from each array, expects array to be 2D:
98
99
# array [[1,2,3], [a,b,c]] sends
99
100
# [1,a] , [2,b] , [3,c]
100
- def one_of_each ( & block )
101
+ def one_of_each
101
102
i = 0
102
103
one = self [ 0 ]
103
104
two = self [ 1 ]
104
105
mi = one . length > two . length ? two . length : one . length
105
- while i < mi do
106
+ while i < mi
106
107
yield ( one [ i ] , two [ i ] )
107
108
i += 1
108
109
end
0 commit comments