Python,pygame,如何画圆弧

问题描述 投票:0回答:3

我正在尝试在pygame中绘制一条弧线,弧线的实际大小和位置并不重要,目前我得到的只是一个椭圆。

我的代码:

import pygame
import sys

pygame.init()
size = width, height = 400, 600
screen = pygame.display.set_mode(size)

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()


    screen.fill((0,0,0))

    pygame.draw.arc(screen, (255, 255, 255), (50, 50, 50, 50), 10, 20, 1)

    pygame.display.flip()

为什么画的是整圆而不是圆弧?

python pygame draw
3个回答
5
投票

来自 pygame 文档

两个角度参数是以弧度表示的初始角度和最终角度,右侧为零。

您从 10 弧度开始,然后扫至 20。我假设您打算以度为单位进行此操作。 10 弧度约为 572 度。


1
投票

您必须修复弧度值。使用 Pi = 3.14 然后更改它 例如:

pygame.draw.arc(屏幕,(255,255,255),[50,50,50,50],Pi/2,Pi,2)


0
投票

如果您希望能够计算角度并从顶部开始绘制:

import pygame
import sys

pygame.init()
size = width, height = 400, 600
screen = pygame.display.set_mode(size)

angle1 = 0
angle2 = 180

counter = 0
while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    screen.fill((0,0,0))

    pygame.draw.arc(screen, (255, 255, 255), (50, 50, 100, 100), ((angle1+90)/57), ((angle2+90)/57), 1)

    pygame.display.update()
© www.soinside.com 2019 - 2024. All rights reserved.