View difference between Paste ID: CsZaBgQm and 703uvn9C
SHOW: | | - or go back to the newest paste.
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
16-
smlradius = 60; bigradius = 120; points = 160
16+
smlradius = 60; bigradius = 120; points = 90
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 
20+
# Calculate the X&Y points and put values into the array
21
angleStep = pi *2 / points
22
for a in range(0,points):
23
	smcx.append(sin(a * angleStep)*smlradius)
24
	smcy.append(cos(a * angleStep)*smlradius)
25
	bgcx.append(sin(a * angleStep)*bigradius)
26
	bgcy.append(cos(a * angleStep)*bigradius)
27
	
28
a=0; b=0 # Points a & b will be moving points of the circles
29-
a=points-1; 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
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-
	rcol=r(0,255); gcol=r(0,255);bcol=r(0,255) # Random Red Green Blue
38+
39
	# Draw the circle
40-
	# A line from point 'a' on small circle to point 'a' on big circle
40+
	screen.blit(dot, (bgcx[a]+cx-2,bgcy[a]+cy-2))
41-
	pdl(bk,[rcol,gcol,bcol],(smcx[a]+cx,smcy[a]+cy),(bgcx[a]+cx,bgcy[a]+cy))
41+
	screen.blit(dot, (smcx[a]+cx-2,smcy[a]+cy-2))
42-
	rcol=r(0,255); gcol=r(0,255);bcol=r(0,255)
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-
	# A line from Centrepoint to point 'b' on small circle
44+
	rcol=r(0,255); gcol=r(0,255); bcol=r(0,255)
45-
	pdl(bk,[rcol,gcol,bcol],(cx-2,cy-2),(smcx[b]+cx,smcy[b]+cy))
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-
	# Some dots to highlight points 'a' & 'b' on both circles
47+
	pdl(bk,[rcol,gcol,bcol],(smcx[a]+cx-2,smcy[a]+cy-2),(smcx[b]+cx-2,smcy[b]+cy-2))
48-
	screen.blit(dot,(smcx[a]+cx-2,smcy[a]+cy-2))
48+
49-
	screen.blit(dot,(bgcx[a]+cx-2,bgcy[a]+cy-2))
49+
	# Constrained points (Fixed X or Y)
50-
	screen.blit(dot,(smcx[b]+cx-2,smcy[b]+cy-2))
50+
	screen.blit(dot, (bgcx[a]+cx-2,cy-bigradius-14))
51
	screen.blit(dot, (bgcx[b]+cx-2,cy+bigradius+10))
52-
	# Another circle offset to the right with horizontal lines
52+
	screen.blit(dot, (smcx[a]+cx-2,cy-bigradius-34))
53-
	rcol=r(0,255); gcol=r(0,255);bcol=r(0,255)
53+
	screen.blit(dot, (smcx[b]+cx-2,cy+bigradius+30))
54-
	pdl(bk,[rcol,gcol,bcol],(smcx[a]+cx+250,smcy[a]+cy),(smcx[b]+cx+250,smcy[b]+cy))
54+
	screen.blit(dot, (cx-bigradius-14,bgcy[a]+cy-2))
55-
	screen.blit(dot,(smcx[a]+cx+250,smcy[a]+cy))
55+
	screen.blit(dot, (cx-bigradius-34,smcy[a]+cy-2))
56-
	screen.blit(dot,(smcx[b]+cx+250,smcy[b]+cy))
56+
	screen.blit(dot, (cx+bigradius+14,bgcy[b]+cy-2))
57-
	screen.blit(dot,(bgcx[a]+cx+250,bgcy[a]+cy))
57+
	screen.blit(dot, (cx+bigradius+34,smcy[b]+cy-2))
58-
	screen.blit(dot,(bgcx[b]+cx+250,bgcy[b]+cy))
58+
	pdl(bk,[rcol,gcol,bcol],(bgcx[a]+cx-2,cy-bigradius-14),(smcx[a]+cx-2,cy-bigradius-34))
59
	pdl(bk,[rcol,gcol,bcol],(bgcx[b]+cx-2,cy+bigradius+10),(smcx[b]+cx-2,cy+bigradius+30))
60-
	# Offset dots with fixed x or y points
60+
	pdl(bk,[rcol,gcol,bcol],(cx-bigradius-14,bgcy[a]+cy-2),(cx-bigradius-34,smcy[a]+cy-2))
61-
	screen.blit(dot,(240,smcy[a]+cy-2))
61+
	pdl(bk,[rcol,gcol,bcol],(cx+bigradius+14,bgcy[b]+cy-2),(cx+bigradius+34,smcy[b]+cy-2))
62-
	screen.blit(dot,(200,bgcy[a]+cy-2))
62+
63-
	screen.blit(dot,(smcx[a]+cx-2,460))
63+
	# Ellipse (Big and Small Radius points mixed)
64-
	screen.blit(dot,(bgcx[a]+cx-2,500))
64+
	screen.blit(dot, (bgcx[a]+cx-2+bigradius+160,smcy[a]+cy-2))
65
	screen.blit(dot, (smcx[a]+cx-2-bigradius-160,bgcy[a]+cy-2))
66-
	# Offset dots using a combo of small and big circle points (Ellipse)
66+
67-
	screen.blit(dot,(bgcx[a]+cx-2,smcy[b]+cy-2-220))
67+
	screen.blit(dot, (cx-2+bigradius+160,cy-2))
68-
	screen.blit(dot,(smcx[a]+cx-2-320,bgcy[b]+cy-2))
68+
	screen.blit(dot, (cx-2-bigradius-160,cy-2))
69
	pdl(bk,[rcol,gcol,bcol],(cx-2+bigradius+160,cy-2),(bgcx[a]+cx-2+bigradius+160,smcy[a]+cy-2))
70-
	clock.tick(100); pygame.display.update(); a=a-1; b=b+1
70+
	pdl(bk,[rcol,gcol,bcol],(cx-2-bigradius-160,cy-2),(smcx[a]+cx-2-bigradius-160,bgcy[a]+cy-2))
71-
	if a<=1: a=points-1 # Restart the loop for point A
71+
72-
	if b>=points-1: b=1 # Restart the loop for point B
72+
	# Sine and Cosine Waves
73
	screen.blit(dot, (c,smcy[a]+cy-2-bigradius-100))
74
	c=c+1
75
	if c>=800: c=0
76
	screen.blit(dot, (smcx[a]+cx-2-bigradius-100,d))
77
	d=d+1
78
	if d>=600: d=0
79
	
80
	clock.tick(200); pygame.display.update(); a=a-1; b=b+1
81
	if b>=points: b=0
82
	if a==-1: a=points-1