Polygon(*vertices) -> Polygon
| 6 | ################################################################################ |
| 7 | |
| 8 | class Polygon: |
| 9 | |
| 10 | "Polygon(*vertices) -> Polygon" |
| 11 | |
| 12 | __slots__ = 'vertices' |
| 13 | |
| 14 | def __init__(self, *vertices): |
| 15 | "Initializes polygon with a list of vertices." |
| 16 | self.vertices = vertices |
| 17 | |
| 18 | def translate(self, offset): |
| 19 | "Moves the polygon by the specified offset." |
| 20 | for vertex in self.vertices: |
| 21 | vertex += offset |
| 22 | |
| 23 | def rotate(self, direction): |
| 24 | "Rotates the polygon by a vector's direction." |
| 25 | for vertex in self.vertices: |
| 26 | vertex.direction += direction |
| 27 | |
| 28 | def scale(self, factor): |
| 29 | "Increases or decreases size of the polygon." |
| 30 | for vertex in self.vertices: |
| 31 | vertex *= factor |
| 32 | |
| 33 | def copy(self): |
| 34 | "Copies the polygon by copying its vertices." |
| 35 | return Polygon(*(vertex.copy() for vertex in self.vertices)) |
| 36 | |
| 37 | ################################################################################ |
| 38 |