-
Notifications
You must be signed in to change notification settings - Fork 0
/
flight_patterns.rb
58 lines (52 loc) · 1.28 KB
/
flight_patterns.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Description:
# Flight Patterns is that ol' Euruko 2008 demo.
full_screen
load_libraries 'boids', 'opengl'
import "processing.opengl" if library_loaded? "opengl"
def setup
library_loaded?(:opengl) ? setup_opengl : render_mode(P3D)
sphere_detail 8
color_mode RGB, 1.0
no_stroke
frame_rate 30
shininess 1.0
specular 0.3, 0.1, 0.1
emissive 0.03, 0.03, 0.1
@click = false
@flocks = []
3.times do |i|
flock = Boids.flock 20, 0, 0, width, height
flock.goal width/2, height/2, 0
@flocks << flock
end
end
def setup_opengl
render_mode(OPENGL)
hint ENABLE_OPENGL_4X_SMOOTH
end
def mouse_pressed
@click = !@click
end
def draw
background 0.05
ambient_light 0.01, 0.01, 0.01
light_specular 0.4, 0.2, 0.2
point_light 1.0, 1.0, 1.0, mouse_x, mouse_y, 190
@flocks.each_with_index do |flock, i|
flock.goal mouse_x, mouse_y, 0, @flee
flock.update(:goal => 185, :limit => 13.5)
for boid in flock do
r = 20 + (boid.z * 0.15)
alpha = 0.5 + (boid.z * 0.01)
case i
when 0 then fill 0.55, 0.35, 0.35
when 1 then fill 0.35, 0.55, 0.35
when 2 then fill 0.35, 0.35, 0.55
end
push_matrix
translate boid.x-r/2, boid.y-r/2, boid.z-r/2
@click ? sphere(r/2) : oval(0, 0, r, r)
pop_matrix
end
end
end