-
Notifications
You must be signed in to change notification settings - Fork 0
/
turtle_sine.py
80 lines (60 loc) · 1.74 KB
/
turtle_sine.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import math
import random
from turtle import *
def forward_to_position(dest_x, dest_y):
delta_x = dest_x - xcor()
delta_y = dest_y - ycor()
setheading(math.degrees(math.atan2(delta_y, delta_x)) % 360)
setposition(dest_x, dest_y)
speed(0)
GRAPH_SIZE = 720
PHASE_SHIFT = 45
bgcolor("black")
pencolor("white")
penup()
setposition(0, GRAPH_SIZE/2)
pendown()
setposition(0, -GRAPH_SIZE/2)
penup()
setposition(GRAPH_SIZE/2, 0)
pendown()
setposition(-GRAPH_SIZE/2, 0)
input("Press Enter to begin...")
penup()
speed(1)
forward_to_position(-GRAPH_SIZE/2, math.sin(math.radians(PHASE_SHIFT))*(GRAPH_SIZE/4))
speed(0)
pendown()
pencolor("cyan")
for i in range(math.floor(-GRAPH_SIZE/2), math.floor(GRAPH_SIZE/2)+1):
forward_to_position(i, math.sin(math.radians(i+PHASE_SHIFT))*(GRAPH_SIZE/4))
penup()
speed(1)
forward_to_position(GRAPH_SIZE/2, math.sin(math.radians(0))*(GRAPH_SIZE/4))
speed(0)
pendown()
pencolor("magenta")
for i in range(math.floor(GRAPH_SIZE/2), math.floor(-GRAPH_SIZE/2)-1, -1):
forward_to_position(i, math.sin(math.radians(i))*(GRAPH_SIZE/4))
penup()
speed(1)
forward_to_position(-GRAPH_SIZE/2, math.sin(math.radians(-PHASE_SHIFT))*(GRAPH_SIZE/4))
speed(0)
pendown()
pencolor("yellow")
for i in range(math.floor(-GRAPH_SIZE/2), math.floor(GRAPH_SIZE/2)+1):
forward_to_position(i, math.sin(math.radians(i-PHASE_SHIFT))*(GRAPH_SIZE/4))
input("Press Enter to continue...")
penup()
forward_to_position(0, 0)
clear()
bgcolor("black")
pencolor("orange red")
for i in range(GRAPH_SIZE*4):
if(i % 10 == 0):
dot()
i_rad = math.radians(i)
forward_to_position(math.sin(i_rad) * (i/8), math.cos(i_rad) * (i/8))
print("Final position: ", position())
print("Absolute position: ", abs(position()))
input("Press Enter to exit...")