第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用Pygame使這個演示繪圖游戲更新繪制圓圈?

如何使用Pygame使這個演示繪圖游戲更新繪制圓圈?

波斯汪 2022-08-02 18:43:57
我正在嘗試讓我的繪圖游戲在拖動鼠標的位置繪制一個圓圈,但這些圓圈的更新頻率不足以創(chuàng)建平滑的線條。我該如何解決這個問題?import pygamefrom random import randintwidth=800height=600pygame.init() #As necessary as import, initalizes pygameglobal gameDisplay gameDisplay = pygame.display.set_mode((width,height))#Makes windowpygame.display.set_caption('Demo')#Titles windowclock = pygame.time.Clock()#Keeps time for pygamegameDisplay.fill((0,0,255))class Draw:    def __init__(self):        self.color = (255, 0, 0)    def update(self, x, y):        self.x = x        self.y = y        pygame.draw.circle(gameDisplay, self.color, (self.x, self.y), (5))end = Falsedown = FalseLine = Draw()while not end:    x, y = pygame.mouse.get_pos()    #drawShape()    #pygame.draw.rect(gameDisplay, (0,255,0), (10, 10, 4, 4))    for event in pygame.event.get():        if event.type == pygame.MOUSEBUTTONDOWN:            down = True        if event.type == pygame.MOUSEBUTTONUP:            down = False        if down:            Line.update(x, y)        if event.type == pygame.QUIT:            end = True    lastx, lasty = pygame.mouse.get_pos()    pygame.display.update()    clock.tick(60)pygame.quit()這就是我的問題
查看完整描述

1 回答

?
撒科打諢

TA貢獻1934條經驗 獲得超2個贊

我建議從上一個鼠標位置到當前鼠標位置繪制一條線。另外,在線的起點和終點畫一個點。這會導致一個回合的開始和結束。
跟蹤鼠標 (, ) 的上一個位置,并在主應用程序循環(huán)(而不是事件循環(huán))中繪制線條:lastxlasty

例如:

https://i.stack.imgur.com/mojlK.gif

import pygame


width, height = 800, 600

pygame.init() #As necessary as import, initalizes pygame

gameDisplay = pygame.display.set_mode((width,height)) #Makes window

pygame.display.set_caption('Demo') #Titles window

clock = pygame.time.Clock() #Keeps time for pygame

gameDisplay.fill((0,0,255))


class Draw:

    def __init__(self):

        self.color = (255, 0, 0)


    def update(self, from_x, from_y, to_x, to_y):

        pygame.draw.circle(gameDisplay, self.color, (from_x, from_y), 5)

        pygame.draw.line(gameDisplay, self.color, (from_x, from_y), (to_x, to_y), 10)

        pygame.draw.circle(gameDisplay, self.color, (to_x, to_y), 5)


end = False

down = False

line = Draw()

while not end:

    for event in pygame.event.get():

        if event.type == pygame.MOUSEBUTTONDOWN:

            lastx, lasty = event.pos

            down = True

        if event.type == pygame.MOUSEBUTTONUP:

            down = False

        if event.type == pygame.QUIT:

            end = True


    x, y = pygame.mouse.get_pos() 

    if down:

        line.update(lastx, lasty, x, y)

    lastx, lasty = x, y


    pygame.display.update()

    clock.tick(60)


pygame.quit()



查看完整回答
反對 回復 2022-08-02
  • 1 回答
  • 0 關注
  • 108 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號