from myro import * import math def makePoly(points, color): polygon = Polygon(points) polygon.setFill(color) polygon.color = color return polygon def rotate(polygon, degrees): radians = degrees * (2 * math.pi) / 360.0 points = polygon.getPoints() newpoints = [] for point in points: x = (point.x) * math.cos(radians) - (point.y) * math.sin(radians) y = (point.x) * math.sin(radians) + (point.y) * math.cos(radians) newpoints.append(Point(x, y)) newpoly = makePoly(newpoints, polygon.color) return newpoly def getCenter(polygon): xsum, ysum, count = 0, 0, 0 for point in polygon.getPoints(): xsum += point.x ysum += point.y count += 1 return (xsum/count, ysum/count) win = GraphWin("Shapes", 500, 500) x, y, r = 250, 100, 10 poly = makePoly([Point(x, y), Point(x + r * 3, y), Point(x + r * 3, y - r), Point(x + r * 2, y - r), Point(x + r * 1.5, y - r * 2), Point(x + r, y - r), Point(x, y - r)], "red") poly.draw(win) for i in range(45): newpoly = rotate(poly, 1) newpoly.draw(win) poly = newpoly