'Etch' Drawing experiment
This was a joint effort between me and Gemini
Gemini did about 70% of the code I provided the idea, as I was exprimenting with libraries. This really helped me understand how it worked
Use WASD to move the line and SPACE to shake it clean
import pygame
pygame.init()
screen = pygame.display.set_mode((600,600))
#pen position to start
x = 300
y = 300
white = (255, 255,255)
black = (0, 0, 0)
running = True
while running:
for event in pygame.event.get():
if event.type ==pygame.QUIT:
running = False
#if event.type == pygame.KEYDOWN:#is the key pressed?
keys = pygame.key.get_pressed()
if keys [pygame.K_w]:
y-= 1 #Move up
if keys [pygame.K_s]:
y+= 1 #move down
if keys [pygame.K_a]:
x-= 1 #move left
if keys [pygame.K_d]:
x+= 1 #move right
if keys[pygame.K_SPACE]:
screen.fill(black)
# Keep X inside the left and right walls
if x < 0:
x = 0
if x > 595: # 600 minus the 5-pixel width of your pen
x = 595
# Keep Y inside the top and bottom walls
if y < 0:
y = 0
if y > 595:
y = 595
pygame.draw.rect(screen, white, (x, y, 5 ,5 ))
pygame.display.flip()