Home > front end >  draw arc with different arguments
draw arc with different arguments

Time:02-03

I'm using Pygame to draw some shapes on the screen. The problem is, I get those shapes from a different application, which exports a txt with the parameters of the arc, like this:

ARC1:
start_x=,
start_y=,
center_x=,
center_y=,
end_x=,
end=y=,
radius=,
start_angle=,
end_angle=

These are the parameters pygame needs to draw an arc:

surface (Surface) -- surface to draw on

color (Color or int or tuple(int, int, int, [int])) -- color to draw with, the alpha value is optional if using a tuple (RGB[A])

rect (Rect) -- rectangle to indicate the position and dimensions of the ellipse which the arc will be based on, the ellipse will be centered inside the rectangle

start_angle (float) -- start angle of the arc in radians

stop_angle (float) -- stop angle of the arc in radians

This function asks a rect, is there a way to calculate the rect with the parameters I have (from the txt) and keep its original shape and position?

CodePudding user response:

The rect argument of pygame.draw.arc specifies the bounding rectangle of the circle the arc is on:

rect -- rectangle to indicate the position and dimensions of the ellipse which the arc will be based on, the ellipse will be centered inside the rectangle

The bounding rectangle of a circle with a given center and radius is:

bounding_rect = pygame.Rect(center_x-radius, center_y-radius, radius*2, radius*2)
  • Related