-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buletan.py
82 lines (72 loc) · 2.62 KB
/
Buletan.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pygame
from pygame import gfxdraw
class Circle:
def __init__(self, center, radius):
self.height, self.width = 800, 600
self.caption = "Circle"
self.x_center = center[0] + int(self.height / 2)
self.y_center = center[1] + int(self.width / 2)
self.radius = radius * 20
self.display = pygame.display.set_mode((self.height, self.width))
self.running = True
def run(self):
# Intiliazie PyGame
pygame.init()
display = self.display
pygame.display.set_caption(self.caption)
while self.running:
display.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
self.draw_circle()
self.fill_circle(
self.x_center, self.y_center, (255, 0, 0, 255), (255, 255, 255, 255)
)
pygame.display.update()
def circle_plot_point(self, x, y):
gfxdraw.pixel(
self.display, self.x_center + x, self.y_center + y, (255, 255, 255)
)
gfxdraw.pixel(
self.display, self.x_center - x, self.y_center + y, (255, 255, 255)
)
gfxdraw.pixel(
self.display, self.x_center + x, self.y_center - y, (255, 255, 255)
)
gfxdraw.pixel(
self.display, self.x_center - x, self.y_center - y, (255, 255, 255)
)
gfxdraw.pixel(
self.display, self.x_center + y, self.y_center + x, (255, 255, 255)
)
gfxdraw.pixel(
self.display, self.x_center - y, self.y_center + x, (255, 255, 255)
)
gfxdraw.pixel(
self.display, self.x_center + y, self.y_center - x, (255, 255, 255)
)
gfxdraw.pixel(
self.display, self.x_center - y, self.y_center - x, (255, 255, 255)
)
def draw_circle(self):
x = 0
y = self.radius
p = 1 - self.radius
self.circle_plot_point(x, y)
while x < y:
x += 1
if p < 0:
p += 2 * x + 1
else:
y -= 1
p += 2 * (x - y) + 1
self.circle_plot_point(x, y)
def fill_circle(self, x, y, fillcol, boundcol):
currcol = self.display.get_at((x, y))
if currcol != boundcol and currcol != fillcol:
gfxdraw.pixel(self.display, x, y, fillcol)
self.fill_circle(x + 1, y, fillcol, boundcol)
self.fill_circle(x, y + 1, fillcol, boundcol)
self.fill_circle(x - 1, y, fillcol, boundcol)
self.fill_circle(x, y - 1, fillcol, boundcol)