pygame利用三角函数画圆

十分简单,只要知道math.radians()是将角度转为弧度,以及这些三角函数的参数都是弧度就好了。
import math,sys,random,pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((600,500))
pygame.display.set_caption("Circle Demo")
screen.fill((0,0,100))

pos_x=300
pos_y=250
radius=200
angle=359

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.edit()
        keys = pygame.key.get_pressed()
        if keys[K_ESCAPE]:
            sys.edit()

        angle+=1
        angle%=360
        if angle==0:
            r=random.randint(0,255)
            g=random.randint(0,255)
            b=random.randint(0,255)
            color=r,g,b
        x=math.cos(math.radians(angle))*radius
        y=math.sin(math.radians(angle))*radius

        pos=(int(pos_x+x),int(pos_y+y))
        pygame.draw.circle(screen,color,pos,10,0)
        pygame.display.update()

你可能感兴趣的:(Python)