Suppose the second button is pressed, therefore
filled_1 = False
filled_2 = True
filled_3 = False
filled_4 = False
Then you click on the third. In this way,
filled_1 = False
filled_2 = True
filled_3 = True
filled_4 = False
You have:
screen.fill(GREEN)
circle_1 = pygame.draw.circle(screen, BLACK, [250, 230], 7, width_1)
circle_2 = pygame.draw.circle(screen, BLACK, [250, 260], 7, width_2)
circle_3 = pygame.draw.circle(screen, BLACK, [250, 290], 7, width_3)
circle_4 = pygame.draw.circle(screen, BLACK, [250, 320], 7, width_4)
which (meanwhile) will draw two black circles.
Then you do:
if filled_1 == True:
and then
elif filled_2 == True:
filled_1 = False
filled_3 = False
filled_4 = False
width_1 = 2
width_3 = 2
width_4 = 2
so now
filled_1 = False
filled_2 = True
filled_3 = False
filled_4 = False
It is not necessary! Now
elif filled_3 == True:
elif filled_4 == True:
! , , .
:
if circle_1.collidepoint(x, y):
filled_1 = True
width_1 = 0
filled_2 = False
filled_3 = False
filled_4 = False
width_2 = 2
width_3 = 2
width_4 = 2
if filled_1 == True:
circle_1 = pygame.draw.circle(screen, BLACK, [250, 230], 7, width_1)
.
. , circle_1 . . .
.
BLACK = ( 0, 0, 0)
GREEN = ( 3, 255, 3)
pygame.Color("black")
pygame.Color(3, 255, 3)
!
thing_1 = ...
thing_2 = ...
...
other_thing_1 = ...
other_thing_2 = ...
...
:
circles = [
{
"thing": ...,
"other_thing": ...
}, {
"thing": ...,
"other_thing": ...
},
...
]
circles[1]["thing"] thing_1.
"":
import pygame
import random
pygame.init()
circles = [
{
"width": 2,
"filled": False,
"position": [250, 230]
}, {
"width": 2,
"filled": False,
"position": [250, 260]
}, {
"width": 2,
"filled": False,
"position": [250, 290]
}, {
"width": 2,
"filled": False,
"position": [250, 320]
},
]
size = [720, 575]
screen = pygame.display.set_mode(size)
done = False
clock = pygame.time.Clock()
while not done:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
x, y = event.pos
if circles[1]["bounding box"].collidepoint(x, y):
circles[1]["filled"] = True
circles[1]["width"] = 0
circles[2]["filled"] = False
circles[3]["filled"] = False
circles[4]["filled"] = False
circles[2]["width"] = 2
circles[3]["width"] = 2
circles[4]["width"] = 2
if circles[1]["filled"] == True:
circles[1]["bounding box"] = pygame.draw.circle(screen, pygame.Color("black"), [250, 230], 7, circles[1]["width"])
...
screen.fill(pygame.Color(3, 255, 3))
circles[1]["bounding box"] = pygame.draw.circle(screen, pygame.Color("black"), circles[1]["position"], 7, circles[1]["width"])
circles[2]["bounding box"] = pygame.draw.circle(screen, pygame.Color("black"), circles[2]["position"], 7, circles[2]["width"])
circles[3]["bounding box"] = pygame.draw.circle(screen, pygame.Color("black"), circles[3]["position"], 7, circles[3]["width"])
circles[4]["bounding box"] = pygame.draw.circle(screen, pygame.Color("black"), circles[4]["position"], 7, circles[4]["width"])
pygame.display.flip()
, , :
import pygame
import random
pygame.init()
circles = [
{
"width": 2,
"filled": False,
"position": [250, 230]
}, {
"width": 2,
"filled": False,
"position": [250, 260]
}, {
"width": 2,
"filled": False,
"position": [250, 290]
}, {
"width": 2,
"filled": False,
"position": [250, 320]
},
]
size = [720, 575]
screen = pygame.display.set_mode(size)
done = False
clock = pygame.time.Clock()
while not done:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
x, y = event.pos
for circle in circles:
if circle["bounding box"].collidepoint(x, y):
circle["filled"] = True
circle["width"] = 0
for othercircle in circles:
if othercircle is not circle:
othercircle["filled"] = False
othercircle["width"] = 2
if circle["filled"] == True:
circle["bounding box"] = pygame.draw.circle(screen, pygame.Color("black"), circle["position"], 7, circle["width"])
screen.fill(pygame.Color(3, 255, 3))
for circle in circles:
circle["bounding box"] = pygame.draw.circle(screen, pygame.Color("black"), circle["position"], 7, circle["width"])
pygame.display.flip()
:
: , ?
A: circles.
: , ?
A: size.
: , ?
A: . .
?:)