May-03-2020, 07:43 PM
(This post was last modified: May-03-2020, 07:43 PM by programmer229193.)
I want to be able to draw lines between my mouse clicks, for example, click 1(put a dot, draws a line from 0,0 to point 1) click 2( puts dot, draws a line from point 1 to point 2) and so on,
look at DEF SCENE here's some of my code...
look at DEF SCENE here's some of my code...
from pygame import * init() size = width, height = 800, 600 screen = display.set_mode(size) button = 0 BLACK = (0, 0, 0) RED = (255, 0, 0) screen.fill(BLACK) def getVal(tup): """ getVal returns the (position+1) of the first 1 within a tuple. This is used because MOUSEBUTTONDOWN and MOUSEMOTION deal with mouse events differently """ for i in range(3): if tup[i]==1: return i+1 return 0 def drawScene(screen, button): # Draw circle if the left mouse button is down. if button==1: draw.circle(screen,RED,(mx,my), 5) x,y = mouse.get_pos() draw.line(screen,RED,(0,0),(x,y),1) display.flip() if button>1: screen.fill(BLACK) display.flip() running = True myClock = time.Clock() while running: for e in event.get(): keydown= pygame.Key.get_pressed() if KeyDown[pygame.K_ESCAPE]: quit() if e.type== QUIT: running=False if e.type== MOUSEBUTTONDOWN: mx,my = e.pos button= e.button if e.type== MOUSEMOTION: mx,my= e.pos button= getVal(e.buttons) drawScene(screen,button) myClock.tick(60) quit()