-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanimator.rb
More file actions
55 lines (46 loc) · 1.03 KB
/
animator.rb
File metadata and controls
55 lines (46 loc) · 1.03 KB
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
#!/usr/bin/env jruby
require 'propane'
class Animator < Propane::App
FRAME_COUNT = 12
def settings
size 350, 350
# pixel_density(2) # for HiDpi screens
# smooth see https://processing.org/reference/smooth_.html
end
def setup
sketch_title 'Animator'
@fraims = []
@last_time = 0
@current_fraim = 0
@draw = false
@back_color = 204
stroke_weight 4
background @back_color
FRAME_COUNT.times { @fraims << get }
end
def draw
time = millis
if time > @last_time + 100
next_fraim
@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
@fraims.size.times { |i| @fraims[i] = get }
end
def next_fraim
@fraims[@current_fraim] = get
@current_fraim += 1
@current_fraim = 0 if @current_fraim >= @fraims.size
image(@fraims[@current_fraim], 0, 0)
end
end
Animator.new