from graphics import *
from math import pi , cos, sin
#~~~~~~~~~~~~~~~~~~~~~~~~STAR~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
def drawStar(p, win, rin, rout):
rs = [rin, rout]
points = []
cx, cy = p.getX(), p.getY()
x,y = cx + rin, cy
theta = 0
points.append(Point(x, y))
for i in range(11):
r = rs[i % 2]
theta += pi/5
x,y = cx + r*cos(theta), cy + r*sin(theta)
points.append(Point(x,y))
star = Polygon(*points)
star.draw(win)
star.setFill('orange')
return star
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
win = GraphWin('Click to draw a star', 400, 400)
win.setBackground('black')
for i in range (10):
p = win.getMouse()
drawStar(p, win, 20, 40)
win.close()
Comments
Displaying 0 of 0 comments ( View all | Add Comment )