import sys
import random
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((600, 500))
pygame.display.set_caption("Drawing Rectangles")
pos_x = 300
pos_y = 250
vel_x = 2
vel_y = 1
rand1, rand2, rand3 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
color = (rand1, rand2, rand3)
while True:
for event in pygame.event.get():
if event.type in (QUIT, KEYDOWN):
sys.exit()
screen.fill((0, 0, 200))
pos_x += vel_x
pos_y += vel_y
if pos_x > 500 or pos_x < 0:
vel_x = -vel_x
rand1, rand2, rand3 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
color = (rand1, rand2, rand3)
if pos_y > 400 or pos_y < 0:
vel_y = -vel_y
rand1, rand2, rand3 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
color = (rand1, rand2, rand3)
width = 0
pos = (pos_x, pos_y, 100, 100)
pygame.draw.rect(screen, color, pos, width)
pygame.display.update()
import sys
import math
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((600, 500))
pygame.display.set_caption("The Pie Game")
myfont = pygame.font.Font(None, 60)
color = (200, 80, 60)
width = 4
x, y = 300, 250
radius = 200
position = (x - radius, y - radius, radius * 2, radius * 2)
piece1 = piece2 = piece3 = piece4 = False
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
elif event.type == KEYUP:
if event.key == pygame.K_ESCAPE:
sys.exit()
elif event.key == pygame.K_1:
piece1 = True
elif event.key == pygame.K_2:
piece2 = True
elif event.key == pygame.K_3:
piece3 = True
elif event.key == pygame.K_4:
piece4 = True
screen.fill((0, 0, 200))
textimage1 = myfont.render("1", True, color)
screen.blit(textimage1, (x + radius / 2 - 20, y - radius / 2))
textimage2 = myfont.render("2", True, color)
screen.blit(textimage2, (x - radius / 2, y - radius / 2))
textimage3 = myfont.render("3", True, color)
screen.blit(textimage3, (x - radius / 2, y + radius / 2 - 20))
textimage4 = myfont.render("4", True, color)
screen.blit(textimage4, (x + radius / 2 - 20, y + radius / 2 - 20))
if piece1:
pygame.draw.arc(screen, color, position, math.radians(0), math.radians(90), width)
pygame.draw.line(screen, color, (x, y), (x + radius, y), width)
pygame.draw.line(screen, color, (x, y), (x, y - radius), width)
if piece2:
pygame.draw.arc(screen, color, position, math.radians(90), math.radians(180), width)
pygame.draw.line(screen, color, (x, y), (x, y - radius), width)
pygame.draw.line(screen, color, (x, y), (x - radius, y), width)
if piece3:
pygame.draw.arc(screen, color, position, math.radians(180), math.radians(270), width)
pygame.draw.line(screen, color, (x, y), (x - radius, y), width)
pygame.draw.line(screen, color, (x, y), (x, y + radius), width)
if piece4:
pygame.draw.arc(screen, color, position, math.radians(270), math.radians(360), width)
pygame.draw.line(screen, color, (x, y), (x, y + radius), width)
pygame.draw.line(screen, color, (x, y), (x + radius, y), width)
if piece1 and piece2 and piece3 and piece4:
color = (0, 255, 0)
pygame.display.update()
import random
import sys
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((800, 600))
for i in range(1000):
x1, y1 = random.randint(0, 800), random.randint(0, 600)
x2, y2 = random.randint(0, 800), random.randint(0, 600)
pygame.draw.line(screen, (100, 255, 200), (x1, y1), (x2, y2), 2)
while True:
for event in pygame.event.get():
if event.type in (QUIT, KEYDOWN):
sys.exit()
pygame.display.update()