-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgame4.py
More file actions
58 lines (43 loc) · 1.3 KB
/
game4.py
File metadata and controls
58 lines (43 loc) · 1.3 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
48
49
50
51
52
53
54
55
56
57
58
import pygame
import random
# Initialize the pygame
pygame.init()
# Initialize the screen
size = (800, 600)
screen = pygame.display.set_mode(size)
# Title and Icon
pygame.display.set_caption("Mouse Interactive Generative Art")
icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)
# Variables
running = True
# Main Loop
while running:
# Set the screen background
screen.fill((255,255,255))
# Generative art algorithm
for i in range(10):
# Generate random colors
red = random.randint(0,255)
green = random.randint(0,255)
blue = random.randint(0,255)
# Generate random positions
x = random.randint(0, 800)
y = random.randint(0, 600)
# Generate random sizes
width = random.randint(1, 20)
height = random.randint(1, 20)
# Draw the rectangles
pygame.draw.rect(screen, (red, green, blue), (x, y, width, height))
# Get the mouse position
mouseX, mouseY = pygame.mouse.get_pos()
# Generate a circle at the mouse position
pygame.draw.circle(screen, (255, 0, 0), (mouseX, mouseY), 10)
# Update the display
pygame.display.flip()
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Quit the game
pygame.quit()