polygon drawer implementation (processing.py)

if ever you wanted to implement a polygon drawer, here it is :


nodes = [

first we added some coordinates as 2d arrays

    for i,node in enumerate(nodes):
            line(nodes[i][0], nodes[i][1], nodes[i+1][0], nodes[i+1][1])

then for each coordinate we drew a line from it to the next, the try pass is a bad and lazy practise to prevent out of index error. the proper way is to add an if

        line(nodes[0][0], nodes[0][1], nodes[len(nodes)-1][0], nodes[len(nodes)-1][1])

then after the try catch we drew a line from the first coordinate to the last coordinate

def mousePressed():
    nodes.append([mouseX, mouseY])

then upon mouse press, we added a new coord to the array

Free Flask Course