Created
April 4, 2012 19:08
-
-
Save Djexus/2304825 to your computer and use it in GitHub Desktop.
A script which make a spinning circle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import pygame | |
from pygame.locals import * | |
class SpinningCircle(pygame.surface.Surface): | |
''' | |
Class which make a spinning circle | |
Usage: | |
>>> cirlce = SpinningCircle(100, (255, 0, 0)) | |
>>> circle.update() | |
''' | |
def __init__(self, radius, color, speed=0.5): | |
self.color = color | |
self.radius = radius | |
self.angle = 0 | |
self.speed = speed | |
self.thickness = int(self.radius / 25.) | |
self.portion = 360 | |
self.update() | |
def update(self): | |
super(SpinningCircle, self).__init__((self.radius * 2, self.radius * 2), SRCALPHA) | |
for i in range(self.portion): | |
angle = math.radians(self.angle + i) | |
pygame.draw.circle(self, [min(max(x * float(i) / self.radius, 0), 255) for x in self.color], (int(math.sin(angle) * (self.radius - self.thickness) + self.radius), int(math.cos(angle) * (self.radius - self.thickness) + self.radius)), self.thickness) | |
self.angle += self.speed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment