所以,我是一个初级程序员,我认为用PyGame(Python)制作一个绘画程序会很酷
我在这样做时遇到了一些问题:
import pygame
class Brush:
def __init__(self, color, x, y, radius, location, center):
self.color = color
self.x = x
self.y = y
self.radius = radius
self.location = location
self.center = center
def draw(self):
pygame.draw.circle(self.location, self.color, self.center, self.radius)
def getMouse(self):
pass
pygame.init()
brushX = 400
brushY = 300
colorWhite = (255, 255, 255)
radius = 15
thickness = 0
width = 800
height = 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Paint")
brush = Brush(colorWhite, brushX, brushY, radius, screen, pos)
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
brush.draw()
pygame.display.update()
上面是我的代码
所以,我的问题是如何主动获取鼠标位置,并在类中为笔刷更改鼠标位置
谢谢
使用以下命令:
要获取鼠标的位置,它将返回一个元组,因此如果要将其分配给两个不同的变量,则可以执行以下操作:
要将其添加到代码中,您可能需要执行以下操作:
相关问题 更多 >
编程相关推荐