-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathline_draw.py
More file actions
47 lines (37 loc) · 1.11 KB
/
line_draw.py
File metadata and controls
47 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# import turtle
# from turtle import *
# from time import sleep
# turtle = Turtle()
# turtle.home()
# turtle.pensize(3)
# turtle.pencolor('white')
# turtle.ht()
# turtle.setposition(-450,0)
# screen = Screen()
# turtle.pencolor('black')
# turtle.st()
# screen.onscreenclick(turtle.goto)
# turtle.getscreen()._root.mainloop()
import pygame
def main():
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
keepGoing = True
lineStart = (0, 0)
drawColor = (0, 0, 0)
lineWidth = 3
while keepGoing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
elif event.type == pygame.MOUSEMOTION:
lineEnd = pygame.mouse.get_pos()
if pygame.mouse.get_pressed() == (1, 0, 0):
pygame.draw.line(background, drawColor, lineStart, lineEnd, lineWidth)
lineStart = lineEnd
screen.blit(background, (0, 0))
pygame.display.flip()
if __name__ == "__main__":
main()