Skip to content

Instantly share code, notes, and snippets.

@max-kov
Created November 7, 2016 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-kov/5593391449c50df8b79fa62bc0f02dd2 to your computer and use it in GitHub Desktop.
Save max-kov/5593391449c50df8b79fa62bc0f02dd2 to your computer and use it in GitHub Desktop.
cycloid animation
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