-
Notifications
You must be signed in to change notification settings - Fork 0
/
tornado.py
61 lines (48 loc) · 1.17 KB
/
tornado.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import turtle as t
from pyaxidraw import axidraw
import math
PLOTTER_ENABLED = True
# plot size in inches
SIZE = 8
ad = None
def lerp(a, b, t):
return a*(1-t) + b*t
def smoothstep(x, lo, hi):
x = max(0, min(1, (x - lo) / (hi - lo)))
return x*x * (3 - 2 * x)
def goto(x, y):
t.penup()
t.goto(x, y)
if PLOTTER_ENABLED:
t.update()
ad.moveto((x/100)*SIZE, (y/100)*SIZE)
def lineto(x, y):
t.pendown()
t.goto(x, y)
if PLOTTER_ENABLED:
t.update()
ad.lineto((x/100)*SIZE, (y/100)*SIZE)
def main():
num_iters = 3000
goto(50, 90)
for i in range(num_iters):
x = 50 + 10*i/num_iters * math.cos(i/10) + 5*math.sin(i/500) + 2*math.sin(i/350)
y = 90-80*i/num_iters
lineto(x, y)
if __name__ == '__main__':
t.setworldcoordinates(0, 100, 100, 0)
t.hideturtle()
t.tracer(500, 0)
if PLOTTER_ENABLED:
ad = axidraw.AxiDraw()
ad.interactive()
ad.options.const_speed = True
ad.connect()
main()
if PLOTTER_ENABLED:
ad.plot_setup()
ad.options.mode = 'align'
ad.plot_run()
ad.disconnect()
t.update()
t.done()