Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Uncomment "from drawBot" line if using setupAsModule.py
- # from drawBot import *
- from math import *
- # Static variables
- W = 1024 # Width in pixels
- H = 1024 # Height in pixels
- FPS = 30 # Frames per seconds
- SECONDS = 3
- DURATION = 1 / FPS
- FRAME_COUNT = SECONDS * FPS
- ORIGIN = ((W/2), (H/2)) # Center of the image
- class Point(object):
- def __init__(self, x, y):
- '''Defines x and y variables'''
- self.x = x * W/4
- self.y = y * H/4
- def move(self, dx, dy):
- '''Determines where x and y move'''
- self.x = self.x + dx
- self.y = self.y + dy
- def __str__(self):
- return "Point(%s,%s)"%(self.x, self.y)
- def getX(self):
- return self.x
- def getY(self):
- return self.y
- def distance(self, other):
- dx = self.x - other.x
- dy = self.y - other.y
- return math.sqrt(dx**2 + dy**2)
- def draw(self, r, g, b):
- print("draw")
- fill(r, g, b)
- strokeWidth(8)
- stroke(0)
- oval((int(self.x)-32), (int(self.y)-32), 64, 64)
- def newFrame():
- frameDuration(DURATION)
- fill(0.75)
- rect(0, 0, W, H)
- # Grid BG
- stroke(0)
- strokeWidth(8)
- # X-axis ----
- line((0+(W/8), (H/2)), (W-(W/8), (H/2)))
- # Y-axis ----
- line((W/2, 0+(H/8)), (W/2, H-(H/8)))
- fill(None)
- oval(W/4, H/4, W/2, H/2)
- newPage(W, H)
- # Main loop, renders the animation:
- for frame in range(FRAME_COUNT):
- newFrame()
- translate(*ORIGIN)
- # Create new points
- redPoint = Point(1,0)
- yellowPoint = Point(0,1)
- bluePoint = Point(-1,0)
- greenPoint = Point((sqrt(2)/2), (sqrt(2)/2))
- purplePoint = Point(-(1/2), sqrt(3)/2)
- whitePoint = Point(0,0)
- # Draw points
- redPoint.draw(0.9, 0.1, 0.1)
- yellowPoint.draw(0.9, 0.9, 0.1)
- bluePoint.draw(0.1, 0.5, 0.9)
- greenPoint.draw(0.2, 0.8, 0.2)
- purplePoint.draw(0.4, 0.2, 1.0)
- whitePoint.draw(1,1,1)
- if frame < FRAME_COUNT-1:
- newPage(W, H)
- # Save a new image in working directory
- saveImage("unit-circle.gif")
Add Comment
Please, Sign In to add comment