[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] New way for drawing an arc
- To: pygame-users@xxxxxxxx
- Subject: [pygame] New way for drawing an arc
- From: Silver <rockachu2@xxxxxxxxx>
- Date: Thu, 05 Jan 2012 15:36:40 -0800
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Thu, 05 Jan 2012 18:36:51 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type; bh=xUaAam+AVq5FmNbsRpZXTIJl5keDXFIjAlGihIgDGIQ=; b=JWuPKQ4iM03lHS3I3vHAKjnQUWXEslv2UoAJyI5kEBw6Dg/OnmqkSjpb0SXcncIITY t0iiiaqcWj2Vek5rAEvaAyzEwd4aWEoFDa8iB7614ftBvNWYGfqen/2e1mLX5zueyL7J d0exde/lcKJRtCJQkn6gRviJPGwGtlJD8qaLM=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1
I recently figured out how to draw an arc in pygame without moire holes
and allowing stuff like antialiasing. Just if any of your are interested.
The script is a little slow.
Also: atan issues where the arc starts out from the left instead of top.
I can't seem to fix it.
--Rockachu2
import math
def draw_arc_matrix(matrix, pos, radius, color, width, angle1, angle2):
#print "Drawing arc at", pos, "with radius of ", radius
for x in xrange(getmatrixwidth(matrix)):
for y in xrange(getmatrixheight(matrix)):
n = ((x-pos[0])**2 )+ ((y-pos[1])**2 )
if n > (radius-width)**2:
if n < (radius)**2:
## now to check arc
#print x,y
#setpoint(matrix, [x,y], color)
angle = math.atan2(y-pos[1], x-pos[0])
angle = math.degrees(angle)+180
#print angle, angle1, angle2
if angle1 > angle2:
if angle < angle1:
if angle > angle2:
setpoint(matrix, [x,y], color)
#print x,y
else:
if angle > angle1:
if angle < angle2:
#print x,y
setpoint(matrix, [x,y], color)
def setpoint(matrix, pos, color):
matrix.set_at(pos, color)
#matrix[pos[0]][pos[1]] = color
#return matrix
def getmatrixwidth(matrix):
# reurn len(matrix)
return matrix.get_rect().width
def getmatrixheight(matrix):
# return len(matrix[0])
return matrix.get_rect().height
if __name__ == "__main__":
import pygame
pygame.init()
screen = pygame.display.set_mode((200,200))
angle = 0
anglec = 1
while True:
anglec += .1
anglec %= 360
screen.fill((0,0,0))
draw_arc_matrix(screen, (100,100), 80, (255,255,255), 10, angle, anglec)
pygame.display.update()
pygame.event.get()