Created
November 7, 2016 22:39
-
-
Save max-kov/5593391449c50df8b79fa62bc0f02dd2 to your computer and use it in GitHub Desktop.
cycloid animation
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 pygame, math | |
pygame.init() | |
windowsSurfaceObj = pygame.display.set_mode((750,300)) | |
fpsClock = pygame.time.Clock() | |
whiteColor = (255,255,255) | |
greenColor = (0,255,0) | |
blackColor = (0,0,0) | |
circleCoords = (100,200) | |
circleRad=80 | |
curAngle = -0.5 | |
xInc=(circleRad*2*math.pi)/(2/0.01) #the circle travels a distance of 2pi*r | |
while curAngle>-2.5: | |
pygame.draw.circle(windowsSurfaceObj, whiteColor, (int(circleCoords[0]), | |
circleCoords[1]), circleRad,1) | |
pygame.draw.circle(windowsSurfaceObj, greenColor, | |
(int(circleCoords[0]+(math.cos(curAngle*math.pi)*circleRad)), | |
circleCoords[1]-int(math.sin(curAngle*math.pi)*circleRad)), | |
1,0) | |
pygame.draw.line(windowsSurfaceObj, greenColor,(int(circleCoords[0]), | |
circleCoords[1]),(int(circleCoords[0]+(math.cos(curAngle*math.pi)*circleRad)), | |
circleCoords[1]-int(math.sin(curAngle*math.pi)*circleRad)),1) | |
pygame.display.update() | |
fpsClock.tick(60) | |
pygame.draw.circle(windowsSurfaceObj, blackColor, (int(circleCoords[0]), | |
circleCoords[1]), circleRad,1) | |
pygame.draw.line(windowsSurfaceObj, blackColor,(int(circleCoords[0]), | |
circleCoords[1]),(int(circleCoords[0]+(math.cos(curAngle*math.pi)*circleRad)), | |
circleCoords[1]-int(math.sin(curAngle*math.pi)*circleRad)),1) | |
tempAngle=-0.5 | |
tempPos=100 | |
while tempAngle>curAngle: | |
pygame.draw.circle(windowsSurfaceObj, greenColor, | |
(int(tempPos+(math.cos(tempAngle*math.pi)*circleRad)), | |
circleCoords[1]-int(math.sin(tempAngle*math.pi)*circleRad)), | |
1,0) | |
tempAngle-=0.01 | |
tempPos+=xInc | |
curAngle-=0.01 | |
circleCoords=(circleCoords[0]+xInc,circleCoords[1]) | |
pygame.display.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment