screen.onkey(pendown, 'd') def circle(): t.circle(100) screen.onkey(circle, 'c') def z(): t.undo() screen.onscreenclick(z, 1) screen.onkey(z, 'z') screen.onkey(up, 'Up') screen.onkey(down, 'Down') screen.onkey(left, 'Left') screen.onkey(right, 'Right') def main(): screen.listen() t.ondrag(dragging) screen.onclick(space, 3)
click_here.penup() click_here.goto(0, -200) click_here.write("CLICK ANYWHERE", align='center', font=HUGE_FONT) upgrade_man = Turtle() upgrade_man.hideturtle() upgrade_man.color(TEXT_COLOR) upgrade_man.penup() upgrade_man.goto(0, 100) upgrade_man.write( "Press E to upgrade click value. Press Q to upgrade clicks per second.", align='center', font=MEDIUM_FONT) save_and_quit = Turtle() save_and_quit.hideturtle() save_and_quit.color(TEXT_COLOR) save_and_quit.penup() save_and_quit.goto(-450, 325) save_and_quit.write("Press Esc to save and quit", align='center', font=TINY_FONT) screen.onscreenclick(click) screen.onkey(upgradeValue, 'e') screen.onkey(upgradeClicks_Per_Sec, 'q') screen.listen() adding_clicks() screen.mainloop()
#move the turtle turtle.setx(path[0][0]) turtle.sety(path[0][1]) turtle.pendown() for i in range(0, len(path)): turtle.goto(path[i][0], (path[i][1])) return def toggle_node(xCoord, yCoord): toggled_coord = (xCoord, yCoord) print("xCoord :" + str(xCoord) + " yCoord: " + str(yCoord)) radius = 1 #parameter for node toggling for i in range(len(path)): distance = get_distance_between(toggled_coord, path[i]) if distance < 1: #very close turtle.penup() #don't paint when we move turtle.goto(xCoord, yCoord - radius/2) turtle.pendown() #paint the circle turtle.circle(radius, 360) #small circle disabled_coords.append(path[i]) return turtle = Turtle() screen = Screen() all_coords = init() disabled_coords = [] #initially empty path = nearest_neighbour(all_coords) draw_graph(path) screen.onscreenclick(toggle_node) turtle.getscreen()._root.mainloop()