• Advertisement
Sign in to follow this  

[pygame] Drawing an Arc

This topic is 2900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to draw a firing cone to show a ship's weapon's range given the firing arc, weapon range, and ship's facing. I can figure and draw the lines delineating the boundries of the cone, but I can't get the arc drawn right. I think the problem lies in that I can't define the Rect correctly that'll hold the arc. Any suggestions would be appreciated.
import pygame, math


wRange = 150
wArc = 60
facing = 90

screen = pygame.display.set_mode((640,480))
bg = pygame.Surface(screen.get_size())

screen.blit(bg, (0,0))

origin = (screen.get_width()/2, screen.get_height()/2)

arcMin = facing-wArc
arcMax = facing+wArc

coordMin = (
    math.cos(math.radians(arcMin))*wRange + origin[0],
    -(math.sin(math.radians(arcMin))*wRange) + origin[1]

coordMax = (
    math.cos(math.radians(arcMax))*wRange + origin[0],
    -(math.sin(math.radians(arcMax))*wRange) + origin[1]

facingRange = (
    origin[1] + -(math.sin(math.radians(facing))*wRange)

pygame.draw.line(screen, (255,0,0), origin, coordMin)
pygame.draw.line(screen, (255,0,0), origin, coordMax)
pygame.draw.line(screen, (0,255,0), origin, facingRange)

arcLeft = coordMax[0]
arcTop = facingRange[1]
arcW = coordMin[0] - coordMax[0]
arcH = coordMax[1] - facingRange[1]

print arcLeft, arcTop, arcW, arcH

arcRect = pygame.Rect(arcLeft, arcTop, arcW, arcH)
pygame.draw.arc(screen, (255,0,0), arcRect, math.radians(arcMin), math.radians(arcMax))

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement