-
Notifications
You must be signed in to change notification settings - Fork 0
/
animator.rb
43 lines (37 loc) · 902 Bytes
/
animator.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
# From the Processing Examples
# Uses the "bare" style, where a Processing::App sketch is implicitly wrapped
# around the code.
# -- omygawshkenas
FRAME_COUNT = 12
def setup
@frames = []
@last_time = 0
@current_frame = 0
@draw = false
@back_color = 204
size 350, 350
stroke_weight 4
smooth
background @back_color
FRAME_COUNT.times { @frames << get() }
end
def draw
time = millis()
if time > @last_time + 100
next_frame
@last_time = time
end
line(pmouse_x, pmouse_y, mouse_x, mouse_y) if @draw
end
def mouse_pressed; @draw = true; end
def mouse_released; @draw = false; end
def key_pressed
background @back_color
@frames.size.times {|i| @frames[i] = get()}
end
def next_frame
@frames[@current_frame] = get()
@current_frame += 1
@current_frame = 0 if @current_frame >= @frames.size
image(@frames[@current_frame], 0, 0)
end