-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathpygame_minimal_draw_pixels_1.py
57 lines (48 loc) · 1.63 KB
/
pygame_minimal_draw_pixels_1.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
56
57
# pygame.draw module
# https://www.pygame.org/docs/ref/draw.html
#
# Pygame: Draw single pixel
# https://stackoverflow.com/questions/10354638/pygame-draw-single-pixel/64571453#64571453
#
# GitHub - PyGameExamplesAndAnswers - Shape and contour - Draw rectangle
# https://github.com/Rabbid76/PyGameExamplesAndAnswers/blob/master/documentation/pygame/pygame_draw_shape_and_contour.md
#
# https://replit.com/@Rabbid76/PyGame-DrawPixel-1
import pygame
pygame.init()
window = pygame.display.set_mode((300, 300))
clock = pygame.time.Clock()
clock.tick()
count = 0
dt_list = []
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
window.fill('black')
rect = pygame.Rect(window.get_rect().center, (0, 0)).inflate(*([min(window.get_size())//2]*2))
for x in range(rect.width):
u = x / (rect.width - 1)
color = (round(u*255), 0, round((1-u)*255))
for y in range(rect.height):
window.set_at((rect.left + x, rect.top + y), color)
"""
for x in range(rect.width):
for y in range(rect.height):
u = x / (rect.width - 1)
v = y / (rect.height - 1)
color = (round(u*255), round(v*255), round((1-u)*(1-v)*255))
window.set_at((rect.left + x, rect.top + y), color)
"""
pygame.display.flip()
dt_list += [clock.tick()]
if len(dt_list) > 100:
del dt_list[0]
if (count % 100 == 0):
dt_sum = sum(dt_list)
if dt_sum > 0:
pygame.display.set_caption("FPS: " + str(round(len(dt_list) / sum(dt_list) * 1000)))
count += 1
pygame.quit()
exit()