Code: Alles auswählen
import pygame, sys, time, random
pygame.init()
uhr = pygame.time.Clock()
screen = pygame.display.set_mode ([1900, 1000])
screen.fill ([255, 255, 255])
z = 400
colorx = random.randint(1, 255)
colory = random.randint(1, 255)
colorz = random.randint(1, 255)
x = random.randint(1, 100)
y = random.randint(1, 100)
r = random.randint(10, 30)
x2 = random.randint(10, 30)
y2 = random.randint(10, 30)
x3 = random.randint(10, 30)
y3 = random.randint(10, 30)
x4 = random.randint(10, 30)
y4 = random.randint(10, 30)
color =((colorx, colory, colorz))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
startpos = ((200 + x, 100 + y))
endpos = ((200 + y, 150 + x))
x = x + 3
y = y + 6
pygame.draw.line(screen, color, startpos, endpos, 1)
if event.type == pygame.KEYUP:
if event.key == pygame.K_a:
startpos = ((2 + x,1 + y ))
endpos = ((2 + y, 1 + x))
y = y + 2
x = x + 4
pygame.draw.line(screen, color, startpos, endpos, 1)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_l:
startpos2 = ((2 + x , 3 + y))
endpos2 = ((z + y , 4 + z))
z = z + 4
x = x + 2
y = y + 3
pygame.draw.line(screen, color, startpos2, endpos2, 1)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
r = r + 2
radius = r
pos = ((x, y))
pygame.draw.circle(screen, color, pos, radius, 1)
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_p:
point1 = ((x2, y2))
point2 = ((x3, y3))
point3 = ((x4, y4))
pygame.draw.polygon(screen, color, point1, point2, point3, 1)
pygame.display.update()
uhr.tick(10)