10.4: Coordinate Sequences
- Page ID
- 15477
The rectangle
method takes a sequence of coordinates that specify opposite corners of the rectangle. This example draws a blue rectangle with the lower left corner at the origin and the upper right corner at (200,100):
canvas.rectangle([[0, 0], [200, 100]], fill='blue', outline='orange', width=10)
This way of specifying corners is called a bounding box because the two points bound the rectangle.
oval
takes a bounding box and draws an oval within the specified rectangle:
canvas.oval([[0, 0], [200, 100]], outline='orange', width=10)
line
takes a sequence of coordinates and draws a line that connects the points. This example draws two legs of a triangle:
canvas.line([[0, 100], [100, 200], [200, 100]], width=10)
polygon
takes the same arguments, but it draws the last leg of the polygon (if necessary) and fills it in:
canvas.polygon([[0, 100], [100, 200], [200, 100]], fill='red', outline='orange', width=10)