Guest User

Untitled

a guest
Feb 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. # Uncomment "from drawBot" line if using setupAsModule.py
  2. # from drawBot import *
  3. from math import *
  4.  
  5. # Static variables
  6. W = 1024 # Width in pixels
  7. H = 1024 # Height in pixels
  8. FPS = 30 # Frames per seconds
  9. SECONDS = 3
  10. DURATION = 1 / FPS
  11. FRAME_COUNT = SECONDS * FPS
  12. ORIGIN = ((W/2), (H/2)) # Center of the image
  13.  
  14.  
  15. class Point(object):
  16.  
  17. def __init__(self, x, y):
  18. '''Defines x and y variables'''
  19. self.x = x * W/4
  20. self.y = y * H/4
  21.  
  22. def move(self, dx, dy):
  23. '''Determines where x and y move'''
  24. self.x = self.x + dx
  25. self.y = self.y + dy
  26.  
  27. def __str__(self):
  28. return "Point(%s,%s)"%(self.x, self.y)
  29.  
  30. def getX(self):
  31. return self.x
  32.  
  33. def getY(self):
  34. return self.y
  35.  
  36. def distance(self, other):
  37. dx = self.x - other.x
  38. dy = self.y - other.y
  39. return math.sqrt(dx**2 + dy**2)
  40.  
  41. def draw(self, r, g, b):
  42. print("draw")
  43. fill(r, g, b)
  44. strokeWidth(8)
  45. stroke(0)
  46. oval((int(self.x)-32), (int(self.y)-32), 64, 64)
  47.  
  48. def newFrame():
  49. frameDuration(DURATION)
  50. fill(0.75)
  51. rect(0, 0, W, H)
  52. # Grid BG
  53. stroke(0)
  54. strokeWidth(8)
  55. # X-axis ----
  56. line((0+(W/8), (H/2)), (W-(W/8), (H/2)))
  57. # Y-axis ----
  58. line((W/2, 0+(H/8)), (W/2, H-(H/8)))
  59. fill(None)
  60. oval(W/4, H/4, W/2, H/2)
  61.  
  62. newPage(W, H)
  63. # Main loop, renders the animation:
  64. for frame in range(FRAME_COUNT):
  65. newFrame()
  66. translate(*ORIGIN)
  67.  
  68. # Create new points
  69. redPoint = Point(1,0)
  70. yellowPoint = Point(0,1)
  71. bluePoint = Point(-1,0)
  72. greenPoint = Point((sqrt(2)/2), (sqrt(2)/2))
  73. purplePoint = Point(-(1/2), sqrt(3)/2)
  74. whitePoint = Point(0,0)
  75.  
  76. # Draw points
  77. redPoint.draw(0.9, 0.1, 0.1)
  78. yellowPoint.draw(0.9, 0.9, 0.1)
  79. bluePoint.draw(0.1, 0.5, 0.9)
  80. greenPoint.draw(0.2, 0.8, 0.2)
  81. purplePoint.draw(0.4, 0.2, 1.0)
  82. whitePoint.draw(1,1,1)
  83.  
  84. if frame < FRAME_COUNT-1:
  85. newPage(W, H)
  86.  
  87. # Save a new image in working directory
  88. saveImage("unit-circle.gif")
Add Comment
Please, Sign In to add comment