-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.py
67 lines (49 loc) · 1.75 KB
/
draw.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
__author__ = 'Liam'
"""Drawing testing. Mores specifically I used this as a scratch pad of
sorts to validate ideas before implementing into project1.py
"""
# convert_gui.pyw
# Program to convert Celsius to Fahrenheit using a simple
# graphical interface.
from random import randint
from math import *
from time import sleep
from graphics import *
def gcd(x, y):
while y != 0:
(x, y) = (y, x % y)
return x
def getPoints(R, r, d, prec): # R, r, d, prec > 0 (20%)
"""This function should return a list of pairs of floating point numbers
relating to a Hypotrochoid. The first number in each pair should be the
x-coordinate of the next point to draw, and the second number should be the
y-coordinate of the next point to draw.
"""
points = []
for t in range(prec):
points.append([(R - r) * cos(t) + d * cos(((R - r) / r) * t),
(R - r) * sin(t) - d * sin(((R - r) / r) * t)])
return points
def getNumberOfPoints(R, r, prec):
return prec * (r // gcd(R, r))
def main():
R, r, d = 1, 2, 7
win = GraphWin('Spyrograph Display', 500, 500)
win.setBackground("#343434")
# Line(Point(0, 250), Point(500, 250)).draw(win) # x-axis
# Line(Point(250, 0), Point(250, 500)).draw(win) # y-axis
prec = getNumberOfPoints(R, r, 360)
points = getPoints(R, r, d, prec)
print(len(points))
x = [i for i, j in points]
y = [j for i, j in points]
win.setCoords(min(x) - 2, min(y) - 2, max(x) + 2, max(y) + 2)
for i in points:
p = Point(i[0], i[1])
p.setFill(color_rgb(randint(0, 255), randint(0, 255), randint(0, 255)))
p.draw(win)
sleep(0.001)
# win.setCoords(mini[0], mini[1], maxi[0], maxi[1])
win.getMouse()
win.close()
main()