propane 0.8.0-java → 0.9.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/README.md +1 -1
- data/lib/propane/app.rb +56 -55
- data/lib/propane/creators/sketch_writer.rb +7 -3
- data/lib/propane/helper_methods.rb +40 -29
- data/lib/propane/runner.rb +3 -2
- data/lib/propane/version.rb +1 -1
- data/pom.rb +1 -1
- data/pom.xml +1 -1
- data/vendors/Rakefile +31 -1
- metadata +2 -59
- data/examples/data_path/Rakefile +0 -32
- data/examples/data_path/bw_shader.rb +0 -47
- data/examples/data_path/data/Texture01.jpg +0 -0
- data/examples/data_path/data/Texture02.jpg +0 -0
- data/examples/data_path/data/Univers45.vlw +0 -0
- data/examples/data_path/data/bwfrag.glsl +0 -23
- data/examples/data_path/data/displaceFrag.glsl +0 -8
- data/examples/data_path/data/displaceVert.glsl +0 -201
- data/examples/data_path/data/lachoy.jpg +0 -0
- data/examples/data_path/data/landscape.glsl +0 -352
- data/examples/data_path/data/monjori.glsl +0 -30
- data/examples/data_path/data/moon.jpg +0 -0
- data/examples/data_path/data/sea.jpg +0 -0
- data/examples/data_path/edge_detection.rb +0 -49
- data/examples/data_path/glsl_heightmap_noise.rb +0 -125
- data/examples/data_path/kinetic_type.rb +0 -79
- data/examples/data_path/landscape.rb +0 -34
- data/examples/data_path/linear_image.rb +0 -51
- data/examples/data_path/monjori.rb +0 -35
- data/examples/regular/Rakefile +0 -30
- data/examples/regular/arcball_box.rb +0 -28
- data/examples/regular/arcball_constrain.rb +0 -29
- data/examples/regular/bezier_playground.rb +0 -206
- data/examples/regular/circle_collision.rb +0 -118
- data/examples/regular/colors_two.rb +0 -60
- data/examples/regular/creating_colors.rb +0 -64
- data/examples/regular/drawolver.rb +0 -93
- data/examples/regular/elegant_ball.rb +0 -159
- data/examples/regular/empathy.rb +0 -80
- data/examples/regular/fern.rb +0 -57
- data/examples/regular/fibonacci_sphere.rb +0 -91
- data/examples/regular/flight_patterns.rb +0 -64
- data/examples/regular/fractions.rb +0 -32
- data/examples/regular/grapher.rb +0 -40
- data/examples/regular/gravity.rb +0 -120
- data/examples/regular/grey_circles.rb +0 -28
- data/examples/regular/jwishy.rb +0 -99
- data/examples/regular/letters.rb +0 -42
- data/examples/regular/lib/boundary.rb +0 -38
- data/examples/regular/lib/particle.rb +0 -77
- data/examples/regular/lib/particle_system.rb +0 -111
- data/examples/regular/lib/rain_drops.rb +0 -54
- data/examples/regular/liquidy.rb +0 -41
- data/examples/regular/mouse_button_demo.rb +0 -32
- data/examples/regular/polyhedrons.rb +0 -249
- data/examples/regular/raining.rb +0 -60
- data/examples/regular/ribbon_doodle.rb +0 -89
- data/examples/regular/select_file.rb +0 -32
- data/examples/regular/select_image.rb +0 -40
- data/examples/regular/slider_demo.rb +0 -61
- data/examples/regular/slider_example.rb +0 -53
- data/examples/regular/slider_simple.rb +0 -47
- data/examples/regular/tree.rb +0 -76
- data/examples/regular/vector_math.rb +0 -37
- data/examples/regular/words.rb +0 -41
- data/lib/propane/helpers/string_extra.rb +0 -45
- data/lib/propane/underscorer.rb +0 -19
@@ -1,93 +0,0 @@
|
|
1
|
-
#!/usr/bin/env jruby -v -w
|
2
|
-
require 'propane'
|
3
|
-
|
4
|
-
# Example to show how to use the VecMath library.
|
5
|
-
# ruby replacement for PVector. Also features
|
6
|
-
# the use each_cons, possibly a rare use for this
|
7
|
-
# ruby Enumerable method?
|
8
|
-
# 2010-03-22 - fjenett (last revised by monkstone 2016-03-26)
|
9
|
-
# now uses 'zip' and 'each', in place of a custom Array object
|
10
|
-
# with a 'one_of_each' method
|
11
|
-
# Drawolver: draw 2D & revolve 3D
|
12
|
-
class Drawolver < Propane::App
|
13
|
-
attr_reader :drawing_mode, :points, :rot_x, :rot_y, :vertices
|
14
|
-
|
15
|
-
def setup
|
16
|
-
size 1024, 768, P3D
|
17
|
-
frame_rate 30
|
18
|
-
reset_scene
|
19
|
-
end
|
20
|
-
|
21
|
-
def draw
|
22
|
-
background 0
|
23
|
-
unless drawing_mode
|
24
|
-
translate(width / 2, height / 2)
|
25
|
-
rotate_x rot_x
|
26
|
-
rotate_y rot_y
|
27
|
-
@rot_x += 0.01
|
28
|
-
@rot_y += 0.02
|
29
|
-
translate(-width / 2, -height / 2)
|
30
|
-
end
|
31
|
-
no_fill
|
32
|
-
stroke 255
|
33
|
-
points.each_cons(2) { |ps, pe| line ps.x, ps.y, pe.x, pe.y }
|
34
|
-
return if drawing_mode
|
35
|
-
stroke 125
|
36
|
-
fill 120
|
37
|
-
lights
|
38
|
-
ambient_light 120, 120, 120
|
39
|
-
vertices.each_cons(2) do |r1, r2|
|
40
|
-
begin_shape(TRIANGLE_STRIP)
|
41
|
-
r1.zip(r2).each do |v1, v2|
|
42
|
-
vertex v1.x, v1.y, v1.z
|
43
|
-
vertex v2.x, v2.y, v2.z
|
44
|
-
end
|
45
|
-
end_shape
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def reset_scene
|
50
|
-
@drawing_mode = true
|
51
|
-
@points = []
|
52
|
-
@rot_x = 0.0
|
53
|
-
@rot_y = 0.0
|
54
|
-
end
|
55
|
-
|
56
|
-
def mouse_pressed
|
57
|
-
reset_scene
|
58
|
-
points << Vec3D.new(mouse_x, mouse_y)
|
59
|
-
end
|
60
|
-
|
61
|
-
def mouse_dragged
|
62
|
-
points << Vec3D.new(mouse_x, mouse_y)
|
63
|
-
end
|
64
|
-
|
65
|
-
def mouse_released
|
66
|
-
points << Vec3D.new(mouse_x, mouse_y)
|
67
|
-
recalculate_shape
|
68
|
-
end
|
69
|
-
|
70
|
-
def recalculate_shape
|
71
|
-
@vertices = []
|
72
|
-
points.each_cons(2) do |ps, _pe|
|
73
|
-
b = points.last - points.first
|
74
|
-
# len = b.mag
|
75
|
-
b.normalize!
|
76
|
-
a = ps - points.first
|
77
|
-
dot = a.dot b
|
78
|
-
b *= dot
|
79
|
-
normal = points.first + b
|
80
|
-
c = ps - normal
|
81
|
-
# nlen = c.mag
|
82
|
-
vertices << []
|
83
|
-
(0..TAU).step(PI / 15) do |ang|
|
84
|
-
e = normal + c * cos(ang)
|
85
|
-
e.z = c.mag * sin(ang)
|
86
|
-
vertices.last << e
|
87
|
-
end
|
88
|
-
end
|
89
|
-
@drawing_mode = false
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
Drawolver.new title: 'Drawolver'
|
@@ -1,159 +0,0 @@
|
|
1
|
-
#!/usr/bin/env jruby -v -w
|
2
|
-
# elegant_ball.rb
|
3
|
-
# After a vanilla processing sketch by
|
4
|
-
# Ben Notorianni aka lazydog
|
5
|
-
#
|
6
|
-
# elegant_ball.rb
|
7
|
-
require 'propane'
|
8
|
-
|
9
|
-
class ElegantBall < Propane::App
|
10
|
-
|
11
|
-
attr_reader :start_t
|
12
|
-
|
13
|
-
def setup
|
14
|
-
size(800, 800, P3D)
|
15
|
-
color_mode(RGB, 1)
|
16
|
-
end
|
17
|
-
|
18
|
-
def draw
|
19
|
-
background(0)
|
20
|
-
# Move the origin so that the scene is centered on the screen.
|
21
|
-
translate(width / 2, height / 2, 0.0)
|
22
|
-
# Set up the lighting.
|
23
|
-
setup_lights
|
24
|
-
# Rotate the local coordinate system.
|
25
|
-
smooth_rotation(5.0, 6.7, 7.3)
|
26
|
-
# Draw the inner object.
|
27
|
-
no_stroke
|
28
|
-
fill(smooth_colour(10.0, 12.0, 7.0))
|
29
|
-
draw_icosahedron(5, 60.0, false)
|
30
|
-
# Rotate the local coordinate system again.
|
31
|
-
smooth_rotation(4.5, 3.7, 7.3)
|
32
|
-
# Draw the outer object.
|
33
|
-
stroke(0.2)
|
34
|
-
fill(smooth_colour(6.0, 9.2, 0.7))
|
35
|
-
draw_icosahedron(5, 200.0, true)
|
36
|
-
end
|
37
|
-
|
38
|
-
def renderer
|
39
|
-
@renderer ||= Propane::Render::AppRender.new(self)
|
40
|
-
end
|
41
|
-
|
42
|
-
def setup_lights
|
43
|
-
ambient_light(0.025, 0.025, 0.025)
|
44
|
-
directional_light(0.2, 0.2, 0.2, -1, -1, -1)
|
45
|
-
spot_light(1.0, 1.0, 1.0, -200, 0, 300, 1, 0, -1, Math::PI / 4, 20)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Generate a vector whose components change smoothly over time in the range
|
49
|
-
# (0..1). Each component uses a Math.sin function to map the current time in
|
50
|
-
# milliseconds in the range (0..1).A 'speed' factor is specified for each
|
51
|
-
# component.
|
52
|
-
def smooth_vector(s1, s2, s3)
|
53
|
-
mills = millis * 0.00003 ## Lazydogs factor
|
54
|
-
# mills = millis * 0.0000001 ## worked for me a bit slower!!
|
55
|
-
x = 0.5 * Math.sin(mills * s1) + 0.5
|
56
|
-
y = 0.5 * Math.sin(mills * s2) + 0.5
|
57
|
-
z = 0.5 * Math.sin(mills * s3) + 0.5
|
58
|
-
Vec3D.new(x, y, z)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Generate a colour which smoothly changes over time.
|
62
|
-
# The speed of each component is controlled by the parameters s1, s2 and s3.
|
63
|
-
def smooth_colour(s1, s2, s3)
|
64
|
-
v = smooth_vector(s1, s2, s3)
|
65
|
-
color(v.x, v.y, v.z)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Rotate the current coordinate system.
|
69
|
-
# Uses smooth_vector to smoothly animate the rotation.
|
70
|
-
def smooth_rotation(s1, s2, s3)
|
71
|
-
r1 = smooth_vector(s1, s2, s3)
|
72
|
-
rotate_x(2.0 * Math::PI * r1.x)
|
73
|
-
rotate_y(2.0 * Math::PI * r1.y)
|
74
|
-
rotate_x(2.0 * Math::PI * r1.z)
|
75
|
-
end
|
76
|
-
|
77
|
-
# Draw an icosahedron defined by a radius r and recursive depth d.
|
78
|
-
# Geometry data will be saved into dst. If spherical is true then the
|
79
|
-
# icosahedron is projected onto the sphere with radius r.
|
80
|
-
def draw_icosahedron(depth, r, spherical)
|
81
|
-
# Calculate the vertex data for an icosahedron inscribed by a sphere radius
|
82
|
-
# 'r'. Use 4 Golden Ratio rectangles as the basis.
|
83
|
-
gr = (1.0 + Math.sqrt(5.0)) / 2.0
|
84
|
-
h = r / Math.sqrt(1.0 + gr * gr)
|
85
|
-
v = [
|
86
|
-
Vec3D.new(0, -h, h * gr),
|
87
|
-
Vec3D.new(0, -h, -h * gr),
|
88
|
-
Vec3D.new(0, h, -h * gr),
|
89
|
-
Vec3D.new(0, h, h * gr),
|
90
|
-
Vec3D.new(h, -h * gr, 0),
|
91
|
-
Vec3D.new(h, h * gr, 0),
|
92
|
-
Vec3D.new(-h, h * gr, 0),
|
93
|
-
Vec3D.new(-h, -h * gr, 0),
|
94
|
-
Vec3D.new(-h * gr, 0, h),
|
95
|
-
Vec3D.new(-h * gr, 0, -h),
|
96
|
-
Vec3D.new(h * gr, 0, -h),
|
97
|
-
Vec3D.new(h * gr, 0, h)
|
98
|
-
]
|
99
|
-
# Draw the 20 triangular faces of the icosahedron.
|
100
|
-
r = 0.0 unless spherical
|
101
|
-
begin_shape(TRIANGLES)
|
102
|
-
draw_triangle(depth, r, v[0], v[7], v[4])
|
103
|
-
draw_triangle(depth, r, v[0], v[4], v[11])
|
104
|
-
draw_triangle(depth, r, v[0], v[11], v[3])
|
105
|
-
draw_triangle(depth, r, v[0], v[3], v[8])
|
106
|
-
draw_triangle(depth, r, v[0], v[8], v[7])
|
107
|
-
draw_triangle(depth, r, v[1], v[4], v[7])
|
108
|
-
draw_triangle(depth, r, v[1], v[10], v[4])
|
109
|
-
draw_triangle(depth, r, v[10], v[11], v[4])
|
110
|
-
draw_triangle(depth, r, v[11], v[5], v[10])
|
111
|
-
draw_triangle(depth, r, v[5], v[3], v[11])
|
112
|
-
draw_triangle(depth, r, v[3], v[6], v[5])
|
113
|
-
draw_triangle(depth, r, v[6], v[8], v[3])
|
114
|
-
draw_triangle(depth, r, v[8], v[9], v[6])
|
115
|
-
draw_triangle(depth, r, v[9], v[7], v[8])
|
116
|
-
draw_triangle(depth, r, v[7], v[1], v[9])
|
117
|
-
draw_triangle(depth, r, v[2], v[1], v[9])
|
118
|
-
draw_triangle(depth, r, v[2], v[10], v[1])
|
119
|
-
draw_triangle(depth, r, v[2], v[5], v[10])
|
120
|
-
draw_triangle(depth, r, v[2], v[6], v[5])
|
121
|
-
draw_triangle(depth, r, v[2], v[9], v[6])
|
122
|
-
end_shape
|
123
|
-
end
|
124
|
-
|
125
|
-
##
|
126
|
-
# Draw a triangle either immediately or subdivide it first.
|
127
|
-
# If depth is 1 then draw the triangle otherwise subdivide first.
|
128
|
-
#
|
129
|
-
def draw_triangle(depth, r, p1, p2, p3)
|
130
|
-
if depth == 1
|
131
|
-
p1.to_vertex(renderer)
|
132
|
-
p2.to_vertex(renderer)
|
133
|
-
p3.to_vertex(renderer)
|
134
|
-
else
|
135
|
-
# Calculate the mid points of this triangle.
|
136
|
-
v1 = (p1 + p2) * 0.5
|
137
|
-
v2 = (p2 + p3) * 0.5
|
138
|
-
v3 = (p3 + p1) * 0.5
|
139
|
-
unless r == 0.0
|
140
|
-
# Project the vertices out onto the sphere with radius r.
|
141
|
-
v1.normalize!
|
142
|
-
v1 *= r
|
143
|
-
v2.normalize!
|
144
|
-
v2 *= r
|
145
|
-
v3.normalize!
|
146
|
-
v3 *= r
|
147
|
-
end
|
148
|
-
## Generate the next level of detail
|
149
|
-
depth -= 1
|
150
|
-
draw_triangle(depth, r, p1, v1, v3)
|
151
|
-
draw_triangle(depth, r, v1, p2, v2)
|
152
|
-
draw_triangle(depth, r, v2, p3, v3)
|
153
|
-
# Uncomment out the next line to include the central part of the triangle.
|
154
|
-
# draw_triangle(depth, r, v1, v2, v3)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
ElegantBall.new title: 'Elegant Ball'
|
data/examples/regular/empathy.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
#!/usr/bin/env jruby -v -W2
|
2
|
-
# Empathy
|
3
|
-
# original by Kyle McDonald
|
4
|
-
# http://www.openprocessing.org/visuals/?visualID=1182
|
5
|
-
|
6
|
-
# This sketch takes advantage of multiple processors by running calculations
|
7
|
-
# in a separate thread.
|
8
|
-
require 'propane'
|
9
|
-
|
10
|
-
CELL_COUNT = 5_000
|
11
|
-
SLOW_DOWN = 0.97
|
12
|
-
ROTATION = 0.004
|
13
|
-
LINE_LENGTH = 37
|
14
|
-
|
15
|
-
class Empathy < Propane::App
|
16
|
-
|
17
|
-
attr_reader :cells
|
18
|
-
|
19
|
-
def setup
|
20
|
-
size(500, 500)
|
21
|
-
stroke(0, 0, 0, 25)
|
22
|
-
@cells = create_cells(CELL_COUNT)
|
23
|
-
start_cell_updates
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_cells(n)
|
27
|
-
(0..n).map do |i|
|
28
|
-
a = i + rand(PI / 9.0)
|
29
|
-
r = ((i / n.to_f) * (width / 2) * (((n - i) / n.to_f) * 3.3)) + rand(6.0)
|
30
|
-
Cell.new((r * cos(a) + width / 2).to_i, (r * sin(a) + height / 2).to_i)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def start_cell_updates
|
35
|
-
Thread.new { Kernel.loop { cells.each(&:update) } }
|
36
|
-
end
|
37
|
-
|
38
|
-
def draw
|
39
|
-
background 255
|
40
|
-
cells.each(&:draw_line) if started?
|
41
|
-
end
|
42
|
-
|
43
|
-
def started?
|
44
|
-
pmouse_x != 0 || pmouse_y != 0
|
45
|
-
end
|
46
|
-
|
47
|
-
def mouse_pressed
|
48
|
-
cells.each(&:reset)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
##
|
53
|
-
# The cell responds to mouse movement
|
54
|
-
##
|
55
|
-
class Cell
|
56
|
-
include Propane::Proxy, Math
|
57
|
-
attr_reader :x, :y, :spin, :angle
|
58
|
-
def initialize(x, y)
|
59
|
-
@x, @y = x, y
|
60
|
-
reset
|
61
|
-
end
|
62
|
-
|
63
|
-
def reset
|
64
|
-
@spin, @angle = 0, 0
|
65
|
-
end
|
66
|
-
|
67
|
-
def update
|
68
|
-
det = ((pmouse_x - x) * (mouse_y - y) - (mouse_x - x) * (pmouse_y - y))
|
69
|
-
@spin += ROTATION * det.to_f / dist(x, y, mouse_x, mouse_y)
|
70
|
-
@spin *= SLOW_DOWN
|
71
|
-
@angle += spin
|
72
|
-
end
|
73
|
-
|
74
|
-
def draw_line
|
75
|
-
d = LINE_LENGTH * spin + 0.001
|
76
|
-
line(x, y, x + d * cos(angle), y + d * sin(angle))
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
Empathy.new(title: 'Empathy')
|
data/examples/regular/fern.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
#!/usr/bin/env jruby -v -w
|
2
|
-
require 'propane'
|
3
|
-
|
4
|
-
class Fern < Propane::App
|
5
|
-
# The Fern Fractal
|
6
|
-
# by Luis Correia
|
7
|
-
|
8
|
-
attr_reader :bnds
|
9
|
-
|
10
|
-
def setup
|
11
|
-
size 500, 500
|
12
|
-
@bnds = Boundary.new(0, width)
|
13
|
-
no_loop
|
14
|
-
puts 'Be patient. This takes about 10 seconds to render.'
|
15
|
-
end
|
16
|
-
|
17
|
-
def draw
|
18
|
-
background 0
|
19
|
-
load_pixels
|
20
|
-
x0, y0 = 0.0, 0.0
|
21
|
-
x, y, r = 0.0, 0.0, 0.0
|
22
|
-
i, j = 0, 0
|
23
|
-
max_iterations = 200_000
|
24
|
-
max_iterations.times do
|
25
|
-
r = rand(0..100.0)
|
26
|
-
if r <= 1
|
27
|
-
x = 0.0
|
28
|
-
y = 0.16 * y0
|
29
|
-
elsif r <= 7
|
30
|
-
x = 0.2 * x0 - 0.26 * y0
|
31
|
-
y = 0.23 * x0 + 0.22 * y0
|
32
|
-
elsif r <= 14
|
33
|
-
x = -0.15 * x0 + 0.28 * y0
|
34
|
-
y = 0.26 * x0 + 0.24 * y0
|
35
|
-
else
|
36
|
-
x = 0.85 * x0 + 0.04 * y0
|
37
|
-
y = -0.004 * x0 + 0.85 * y0 + 1.6
|
38
|
-
end
|
39
|
-
i = height - (y * 45).to_i
|
40
|
-
j = width / 2 + (x * 45).to_i
|
41
|
-
pixels[i * height + j] += 2_560 if bnds.include?(i) && bnds.include?(j)
|
42
|
-
x0, y0 = x, y
|
43
|
-
end
|
44
|
-
update_pixels
|
45
|
-
end
|
46
|
-
end
|
47
|
-
# Abstract bnds checking to this
|
48
|
-
# lightweight class
|
49
|
-
#
|
50
|
-
|
51
|
-
Boundary = Struct.new(:lower, :upper) do
|
52
|
-
def include?(x)
|
53
|
-
(lower...upper).cover? x
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
Fern.new title: 'Fern'
|
@@ -1,91 +0,0 @@
|
|
1
|
-
#!/usr/bin/env jruby -v -W2
|
2
|
-
require 'propane'
|
3
|
-
require 'arcball'
|
4
|
-
|
5
|
-
class FibonacciSphere < Propane::App
|
6
|
-
# fibonacci_sphere.rb
|
7
|
-
# After a vanilla processing sketch by Jim Bumgardner
|
8
|
-
# http://www.openprocessing.org/sketch/41142
|
9
|
-
#
|
10
|
-
# Controls:
|
11
|
-
# 1. drag mouse to rotate sphere (uses builtin arcball library)
|
12
|
-
# 2. click mouse to toggle add box to sphere surface
|
13
|
-
# 3. press x, y, or z to constrain arcball rotation to that axis
|
14
|
-
#
|
15
|
-
|
16
|
-
PHI = (sqrt(5) + 1) / 2 - 1 # golden ratio
|
17
|
-
GA = PHI * TAU # golden angle
|
18
|
-
|
19
|
-
KMAX_POINTS = 100_000
|
20
|
-
|
21
|
-
attr_reader :pts, :rotation_x, :rotation_y, :nbr_points, :radius, :add_points
|
22
|
-
|
23
|
-
|
24
|
-
def setup
|
25
|
-
size(1024, 768, P3D)
|
26
|
-
Processing::ArcBall.init(self, width / 2.0, height / 2.0)
|
27
|
-
@rotation_x = 0
|
28
|
-
@rotation_y = 0
|
29
|
-
@nbr_points = 2000
|
30
|
-
@radius = 0.8 * height / 2
|
31
|
-
@add_points = true
|
32
|
-
@pts = Array.new(KMAX_POINTS)
|
33
|
-
init_sphere(nbr_points)
|
34
|
-
background(0)
|
35
|
-
end
|
36
|
-
|
37
|
-
def draw
|
38
|
-
if add_points
|
39
|
-
@nbr_points += 1
|
40
|
-
@nbr_points = [nbr_points, KMAX_POINTS].min
|
41
|
-
init_sphere(nbr_points)
|
42
|
-
end
|
43
|
-
|
44
|
-
background 0
|
45
|
-
lights
|
46
|
-
ambient(200, 10, 10)
|
47
|
-
ambient_light(150, 150, 150)
|
48
|
-
render_globe
|
49
|
-
end
|
50
|
-
|
51
|
-
###########################################
|
52
|
-
# For Fibonacci Sphere
|
53
|
-
##################################
|
54
|
-
|
55
|
-
def render_globe
|
56
|
-
push_matrix
|
57
|
-
(0..[nbr_points, pts.length].min).each do |i|
|
58
|
-
lat = pts[i].lat
|
59
|
-
lon = pts[i].lon
|
60
|
-
push_matrix
|
61
|
-
rotate_y(lon)
|
62
|
-
rotate_z(-lat)
|
63
|
-
fill(200, 10, 10)
|
64
|
-
translate(radius, 0, 0)
|
65
|
-
box(4, 7, 7)
|
66
|
-
pop_matrix
|
67
|
-
end
|
68
|
-
pop_matrix
|
69
|
-
end
|
70
|
-
|
71
|
-
def mouse_clicked
|
72
|
-
@add_points = !add_points
|
73
|
-
end
|
74
|
-
|
75
|
-
SpherePoint = Struct.new(:lat, :lon)
|
76
|
-
|
77
|
-
def init_sphere(num)
|
78
|
-
(0..num).each do |i|
|
79
|
-
lon = GA * i
|
80
|
-
lon /= TAU
|
81
|
-
lon -= lon.floor
|
82
|
-
lon *= TAU
|
83
|
-
lon -= TAU if lon > PI
|
84
|
-
# Convert dome height (which is proportional to surface area) to latitude
|
85
|
-
# lat = asin(-1 + 2 * i / num.to_f)
|
86
|
-
pts[i] = SpherePoint.new(asin(-1 + 2 * i / num.to_f), lon)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
FibonacciSphere.new title: 'Fibonacci Sphere'
|