单击它如何使圆圈绿色
我正在尝试制作一个具有一千个小圆圈的窗户,当我单击一个圆圈时,圆圈将变绿。我是Pygame的新手。
import pygame
import random as r
pygame.init()
screen = pygame.display.set_mode([1700, 900])
pygame.display.set_caption('So many buttons')
from pygame import mixer
mixer.init()
mixer.music.load('looperman-l-2592210-0277509-vein-95bpm-blend-beats.ogg')
mixer.music.play(-1)
run = True
num = 1
def draw_circle(self):
x = r.randint(1, 1700)
y = r.randint(1, 900)
pygame.draw.circle(screen, (255, 0, 0),[x, y], 10, 0)
pygame.display.update()
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if num <= 1000:
draw_circle()
num += 1
pygame.quit()
I'm trying to make a Pygame window that has one thousand small circles and when I click one that circle will turn green. I am new to Pygame.
import pygame
import random as r
pygame.init()
screen = pygame.display.set_mode([1700, 900])
pygame.display.set_caption('So many buttons')
from pygame import mixer
mixer.init()
mixer.music.load('looperman-l-2592210-0277509-vein-95bpm-blend-beats.ogg')
mixer.music.play(-1)
run = True
num = 1
def draw_circle(self):
x = r.randint(1, 1700)
y = r.randint(1, 900)
pygame.draw.circle(screen, (255, 0, 0),[x, y], 10, 0)
pygame.display.update()
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if num <= 1000:
draw_circle()
num += 1
pygame.quit()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建代表一个圆的类。该类应具有可以绘制圆圈的方法,检测点是否在圆内的方法以及可以更改颜色的方法:
在应用程序循环之前创建圆圈并将其放在列表中:
当单击鼠标时,检测鼠标是否为圆圈并更改颜色:
在应用程序循环中绘制圆圈:
请参见ALOS 我如何在pygame中检测到碰撞?和 pygame鼠标单击检测。
最小示例:
Create a class that represents a circle. The class should have a method that can draw the circle, method that detects if a point is inside the circle and a method that can change the color:
Create circles before the application loop and put them in a list:
When the mouse is clicked, detect if the mouse is in a circle and change color:
Draw the circle in a loop in the application loop:
See alos How do I detect collision in pygame? and Pygame mouse clicking detection.
Minimal example: