Example pinboard-2.py

This image is similar to pinboard-tk but we define points around all four edges of the image and join then using straight lines. We also use different colours for each quarter of the image.

Code

import sympl.tkcanvas
 
length = 500
step = 10
 
def draw(canvas):
    points1 = [(n, 0) for n in range(0, length+step, step)]
    points2 = [(0, n) for n in range(0, length+step, step)]
    points3 = [(n, length) for n in range(0, length+step, step)]
    points4 = [(length, n) for n in range(0, length+step, step)]
    for p1, p2 in zip(points1, reversed(points2)):
            canvas.create_line(p1, p2, width=1, fill="blue")
    for p1, p2 in zip(points3, reversed(points4)):
            canvas.create_line(p1, p2, width=1, fill="red")
    for p1, p2 in zip(points1, points4):
            canvas.create_line(p1, p2, width=1, fill="green")
    for p1, p2 in zip(points3, points2):
            canvas.create_line(p1, p2, width=1, fill="orange")
 
sympl.tkcanvas.tk_image(length, length, draw)

In the draw function, we use a list comprehension to define the four sets of points.

In each loop, we join each point on a horizontal line to a point on a vertical line. There are four combinations of horizontal and vertical lines, and we draw each in a different colour.