我一直在修改Computing101.com提供的代码。它可以创建各种图形,但是,我试图将“外圆”修改为圆角三角形或椭圆形以及圆。.我希望它随机选择形状和大小。我还希望笔在每次完整的迭代中更改颜色
import turtle
from math import cos,sin,pi
from time import sleep
from random import randint, uniform, choice
window = turtle.Screen()
window.bgcolor("#FFFFFF")
myColourList = ['#C7980A', '#F4651F', '#82D8A7', '#CC3A05', '#575E76', '#156943', '#0BD055', '#ACD338']
mySpirograph = turtle.Turtle()
mySpirograph.hideturtle()
mySpirograph.speed(0)
mySpirograph.pensize(2)
myPen = turtle.Turtle()
myPen.hideturtle()
myPen.speed(0)
myPen.pensize(3)
myPen.color(choice(myColourList))
R = randint (150, 300) # Radius of outer Circle
r = randint (10, 100) # Radius of inner Circle
d = randint (5, 100)
s = randint (5, 25)
t = uniform (.01, 1.0)
angle = 0
myPen.penup()
myPen.goto(R-r+d,0)
myPen.pendown()
theta = t
steps = (int(s * pi/theta) * randint (1, 10))
for t in range(0,steps):
mySpirograph.clear()
mySpirograph.penup()
mySpirograph.setheading(0)
mySpirograph.goto(0,-R)
mySpirograph.color('#000')
mySpirograph.pendown()
mySpirograph.circle(R)
angle+=theta
x = (R - r) * cos(angle)
y = (R - r) * sin(angle)
mySpirograph.penup()
mySpirograph.goto(x,y-r)
mySpirograph.color('#000')
mySpirograph.pendown()
mySpirograph.circle(r)
mySpirograph.penup()
mySpirograph.goto(x,y)
mySpirograph.dot(5)
x = (R - r) * cos(angle) + d * cos(((R-r)/r)*angle)
y = (R - r) * sin(angle) - d * sin(((R-r)/r)*angle)
mySpirograph.pendown()
mySpirograph.goto(x,y)
mySpirograph.dot(5)
myPen.goto(mySpirograph.pos())
mySpirograph.getscreen().update()
sleep(0.05)
sleep(0.5)
#Hide Spirograph
mySpirograph.clear()
mySpirograph.getscreen().update()