Проблема в другом месте, потому что вы используете одно и то же имя points
в функции draw()
в l oop for points
, поэтому последний элемент назначается от pointList
до points
You должны использовать другое имя в draw()
- ie. items
def draw():
global pointsList, points
background(0)
for items in pointsList: # <-- use `items`
draw_points(items) # <-- use `items`
draw_points(points)
pointsList = []
points = []
def setup():
global pointsList, points
size(400,400)
stroke(255)
strokeWeight(5)
def draw():
global pointsList, points
background(0)
for items in pointsList: # <-- use `items`
draw_points(items) # <-- use `items`
draw_points(points)
def keyPressed():
global pointsList, points
if key == 'e':
try:
pointsList.append(points)
points = []
except Exception as e:
print(e)
print(pointsList)
def mouseClicked():
global points
points.append((mouseX,mouseY))
print(points)
def draw_points(points):
for i in range(len(points)-1):
draw_line(points[i], points[i+1])
def draw_line(p1, p2):
line(p1[0], p1[1], p2[0], p2[1])