-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy path08-drag.py
42 lines (35 loc) · 1.18 KB
/
08-drag.py
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
from nodeboxgl.graphics import *
# A classic NodeBox example (http://nodebox.net/code/index.php/Dendrite).
# It registers the dragged mouse movements,
# and use those to draw wavering lines.
# Thanks to Karsten Wolf.
from random import seed
from math import sin
lines = []
def draw(canvas):
background(0.1, 0.0, 0.1, 0.25)
nofill()
stroke(1, 1, 1, 0.2)
strokewidth(0.5)
# Register mouse movement.
if canvas.mouse.dragged:
lines.append((LINETO, canvas.mouse.x, canvas.mouse.y, canvas.frame))
elif canvas.mouse.pressed:
lines.append((MOVETO, canvas.mouse.x, canvas.mouse.y, canvas.frame))
if len(lines) > 0:
for i in range(5):
seed(i) # Lock the seed for smooth animation.
p = BezierPath()
for cmd, x, y, t in lines:
d = sin((canvas.frame - t) / 10.0) * 10.0 # Play with the numbers.
x += random(-d, d)
y += random(-d, d)
if cmd == MOVETO:
p.moveto(x, y)
else:
p.lineto(x, y)
drawpath(p)
canvas.fps = 60
canvas.size = 600, 400
#canvas.fullscreen = True
canvas.run(draw)