How can I play with a turtle and how can I use a turtle?
I have trouble getting the thing to work as in the picture shown below (ignore the colors).
JavaScript
x
36
36
1
from turtle import *
2
from math import *
3
4
5
def formulaX(R, r, p, t):
6
x = (R-r)*cos(t) - (r + p)*cos((R-r)/r*t)
7
8
def formulaY(R, r, p, t):
9
y = (R-r)*sin(t) - (r + p)*sin((R-r)/r*t)
10
11
def t_iterating(R, r, p):
12
t = 2*pi
13
up()
14
goto(formulaX, formulaY)
15
down()
16
17
while (True):
18
t = t + 0.01
19
formulaX(R, r, p, t)
20
formulaY(R, r, p, t)
21
22
23
def main():
24
R = int(input("The radius of the fixed circle: "))
25
r = int(input("The radius of the moving circle: "))
26
p = int(input("The offset of the pen point, between <10 - 100>: "))
27
28
if p < 10 or p > 100:
29
input("Incorrect value for p!")
30
31
t_iterating(R, r, p)
32
33
input("Hit enter to close...")
34
35
main()'
36
I am trying to make that kind of shape. Here is the coding I have done so far.
Advertisement
Answer
Try changing your t_iterating
function to this:
JavaScript
1
9
1
def t_iterating(R, r, p):
2
t = 2*pi # It seems odd to me to start from 2*pi rather than 0.
3
down()
4
5
while t < 20*pi: # This loops while t goes from 2*pi to 20*pi.
6
t = t+0.01
7
goto(formulaX(R, r, p, t), formulaY(R, r, p, t))
8
up()
9