# Python Circle Demo

Aug 22nd, 2012
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # CIRCLE DEMO
2.
3. # By Jaseman - 22nd August 2012
4.
5. import os, random, pygame; from pygame.locals import *
6. from math import sin, cos, pi
7. pygame.init(); clock = pygame.time.Clock()
8. os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
9. pygame.display.set_caption("Circle Demo")
10. screen=pygame.display.set_mode((800,600),0,32)
11.
12. bk=pygame.Surface((800,600)); bk.fill((0,64,0))
13. dot=pygame.Surface((4,4)); dot.set_colorkey([0,0,0])
14. pygame.draw.circle(dot,(255,255,255),(2,2),2,0)
15.
17. # Variable Arrays To Store X&Y points for a small and big circle
18. smcx = []; smcy = []; bgcx = []; bgcy = []
19.
20. # Calculate the X&Y points and put values into the array
21. angleStep = pi *2 / points
22. for a in range(0,points):
27.
28. a=0; b=0 # Points a & b will be moving points of the circles
29. c=0; d=0 # Points for sine and cosine waves
30. cx=800/2; cy=600/2 # Centre of the screen
31. r=random.randint; pdl=pygame.draw.line # Abbreviations for commands
32.
33. run = 1
34. while run == 1:
35.
36. screen.blit(bk,(0,0)) # Draw the background surface
37. screen.blit(dot,(cx-2,cy-2)) # Centrepoint
38.
39. # Draw the circle
40. screen.blit(dot, (bgcx[a]+cx-2,bgcy[a]+cy-2))
41. screen.blit(dot, (smcx[a]+cx-2,smcy[a]+cy-2))
42. screen.blit(dot, (bgcx[b]+cx-2,bgcy[b]+cy-2))
43. screen.blit(dot, (smcx[b]+cx-2,smcy[b]+cy-2))
44. rcol=r(0,255); gcol=r(0,255); bcol=r(0,255)
45. pdl(bk,[rcol,gcol,bcol],(bgcx[a]+cx-2,bgcy[a]+cy-2),(smcx[a]+cx-2,smcy[a]+cy-2))
46. pdl(bk,[rcol,gcol,bcol],(bgcx[b]+cx-2,bgcy[b]+cy-2),(smcx[b]+cx-2,smcy[b]+cy-2))
47. pdl(bk,[rcol,gcol,bcol],(smcx[a]+cx-2,smcy[a]+cy-2),(smcx[b]+cx-2,smcy[b]+cy-2))
48.
49. # Constrained points (Fixed X or Y)
62.
63. # Ellipse (Big and Small Radius points mixed)
66.
71.
72. # Sine and Cosine Waves