【发布时间】:2015-07-21 23:45:35
【问题描述】:
我目前正在尝试创建一个数字速度计。由于尝试控制表盘时遇到的问题,该项目已戛然而止。我的变量 radial_pos 旨在计算速度计每个刻度的精确 x,y 坐标,如果用户按下 K_UP,radial_pos 将增加加 1 以显示速度计的下一个刻度。但是,恐怕我已经学习了找到圆坐标的概念已经太多年了,更不用说理解它以能够相应地增加它了。到目前为止,这是我的代码:
import pygame, sys
from pygame.locals import *
pygame.init()
#Screen Resolution
width = 1080
height = 720
#Instrument Characteristics
color = (255,255,255)
background = (0,0,0)
radius_speedometer = 100
weight_speedometer = radius_speedometer-5
#Window Measurements
screen= pygame.display.set_mode((width,height),0,32)
pos_center_x = width/2
pos_center_y = height/2
#Speedometer Dial Position
pos_speedometer_dial_x = pos_center_x - 60
pos_speedometer_dial_y = pos_center_y +60
#Radial Position (hint: ticks on the clock)
'''
radial_pos = ...
'''
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_DOWN:
radial_pos=-1
if event.key==K_UP:
radial_pos=+1
if event.type==KEYUP:
if event.key==K_DOWN:
radial_pos=0
if event.key==K_UP:
radial_pos=0
screen.lock()
#Speedometer Ring
pygame.draw.circle(screen, color, (pos_center_x,pos_center_y), radius_speedometer)
pygame.draw.circle(screen, background, (pos_center_x,pos_center_y), weight_speedometer)
#Speedometer Dial
pygame.draw.line(screen, color, (pos_center_x,pos_center_y), (pos_speedometer_dial_x, pos_speedometer_dial_y),5)
screen.unlock()
pygame.display.update()
如果有人对此特定问题有任何建议,将不胜感激。感谢您的宝贵时间。
【问题讨论】:
-
你给我们的代码太多了。下次尝试将其归结为minimal reproducible example。
标签: math pygame coordinates trigonometry