summaryrefslogtreecommitdiffstats
path: root/Weekly Challenges/Week 2/10 PRINT.py
blob: a08a2f2e5c890e3a2e73c80fef80359be602958d (plain)
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
59
60
61
62
63
64
65
66
67
import pygame
import random

pygame.init()

SCREEN_WIDTH = 720
SCREEN_HEIGHT = 720

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

DRAWING_DELAY_MS = 1

NUM_COLS = 30
NUM_ROWS = 30
CELL_WIDTH = SCREEN_WIDTH / NUM_COLS
CELL_HEIGHT = SCREEN_HEIGHT / NUM_ROWS

current_col = 0
current_row = 0

DRAW_CELL_EVENT = pygame.USEREVENT
pygame.time.set_timer(DRAW_CELL_EVENT, DRAWING_DELAY_MS, NUM_COLS * NUM_ROWS)

is_running = True
while is_running:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False
        elif event.type == DRAW_CELL_EVENT:

            top = current_row * CELL_HEIGHT
            left = current_col * CELL_WIDTH
            bottom = top + CELL_HEIGHT
            right = left + CELL_WIDTH

            random_val = random.random()
            if random_val < 1/4:
                point1 = (left, top)
                point2 = (right, bottom)
            elif random_val < 2/4:
                point1 = (left, bottom)
                point2 = (right, top)
            elif random_val < 3/4:
                point1 = (left, bottom)
                point2 = (right, bottom)
            else:
                point1 = (right, top)
                point2 = (right, bottom)

            red_val = 255 * (current_col / NUM_COLS)
            green_val = 255 * (current_row / NUM_ROWS)
            blue_val = 255 - red_val
            print(red_val, green_val, blue_val)
            pygame.draw.line(screen, (red_val, green_val, blue_val), point1, point2, width=3)

            # r = pygame.Rect(current_col * CELL_WIDTH, current_row * CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT)
            # pygame.draw.rect(screen, (255,0,0), r)

            current_col += 1
            if current_col >= NUM_COLS:
                current_row += 1
                current_col = 0

    pygame.display.update()

pygame.quit()