repl.it
@Ari24/

10Print

Pygame

Coding Challange from Daniel Shipman in Python

fork
loading
Files
  • main.py
  • nohup.out
main.py
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
import pygame, random as r, math
pygame.init()

class line:
    def __init__(self, startx, starty, endx, endy, color=(255, 255, 255)):
        self.startx = startx
        self.starty = starty
        self.endx = endx
        self.endy = endy
        self.color = color

    def draw(self):
        pygame.draw.line(screen, self.color, (self.startx, self.starty), (self.endx, self.endy))

WIDTH, HEIGHT = 400, 400
cx, cy = WIDTH // 2, HEIGHT // 2

screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('10PRINT')

x = 0
y = 0
spacing = 20

lines = []

tmp = 0

run = True
while run:
    pygame.time.Clock().tick(30)
    screen.fill((0, 0, 0))
    for event in pygame.event.get():
        if event.type == pygame.QUIT: run = False

    if not y > HEIGHT:
        if r.uniform(0, 1) < .7:
            lines.append(line(x, y, x+spacing, y+spacing, color=(x // 2, y // 2, tmp if tmp < 255 else tmp // 2)))
        else:
            lines.append(line(x, y+spacing, x+spacing, y, color=(x // 2, y // 2, tmp if tmp < 255 else tmp // 2)))

        x += spacing
        if x > WIDTH:
            x = 0
            y += spacing

            tmp += 1

    for a_line in lines:
        a_line.draw()

    pygame.display.update()

pygame.quit()
?