Skip to content

Instantly share code, notes, and snippets.

@sherbondy
Created November 4, 2010 19:34
Show Gist options
  • Save sherbondy/663037 to your computer and use it in GitHub Desktop.
Save sherbondy/663037 to your computer and use it in GitHub Desktop.
# lines: make lots of lines on the screen
import pippy, pygame, sys, math
from pygame.locals import *
from random import *
# XO screen is 1200x900
size = width, height = 1200, 900
# always need to init first thing
pygame.init()
# turn off the cursor
pygame.mouse.set_visible(False)
# create the window and keep track of the surface
# for drawing into
screen = pygame.display.set_mode(size)
# start the screen all black
screen.fill((0,0,0))
# we need starting endpoints for the line and seed motion vectors
start=[randint(0,size[0]), randint(0,size[1])]
end =[randint(0,size[0]), randint(0,size[1])]
# randomize the motion, 1..3 in each direction, positive or negative, but
# never 0
mvect_start = [choice((-1,1)) * randint(1,3), choice((-1,1)) * randint(1,3)]
mvect_end = [choice((-1,1)) * randint(1,3), choice((-1,1)) * randint(1,3)]
# start with a random color and color direction
color = [randint(0,255), randint(0,255), randint(0,255)]
direction = [choice((-1,1)), choice((-1,1)), choice((-1,1))]
t=10
R=60
r=-25
a=400
x=100
y=110
while pippy.pygame.next_frame():
# for event in pygame.event.get():
# if event.type == QUIT:
# sys.exit()
#elif event.type == K_SPACE:
while 1==1:
for idle_event in pygame.event.get():
if idle_event.type == QUIT:
sys.exit()
if idle_event.type == KEYDOWN:
if idle_event.key == K_ESCAPE:
sys.exit()
while idle_event.key == K_RIGHT:
t= t+.1
x =((R+r)*math.cos((r*t)/t))-(a*(math.cos((1+(r/R)*t))))+(width/2)
y =((R+r)*math.sin((r*t)/t))-(a*(math.sin((1+(r/R)*t))))+(height/2)
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3.5)
# update the display
pygame.display.flip()
#KEY 2
while idle_event.key == K_LEFT:
t= t+.1
R=60
r=55
p=59
x =(1.5)*((R+r)*math.cos(t)+p*math.cos((R+r)*t/2))+(width/2)
y =(1.5)*((R+r)*math.sin(t)+p*math.sin((R+r)*t/2))+(height/2)
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 1.5)
# update the display
pygame.display.flip()
#KEY UP
while idle_event.key == K_UP:
t= t+.1
R=77
r=24
p=22
#x =(R+r)*math.cos(t)+p*math.cos((R+r)*t/2)+(width/2)
#y =(R+r)*math.sin(t)+p*math.sin((R+r)*t/2)+(height/2)
x=(R+r)*math.cos(t)+p*math.cos((R+r)*t/r)+(width/2)
y=(R+r)*math.sin(t)+p*math.sin((R+r)*t/r)+height/2
#x =(R-r)*math.cos(t)+p*math.cos((R/r-1)*t)+width/2
#y =(R-r)*math.sin(t)+p*math.sin((R/r-1)*t)+height/2
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#KEY DOWN
while idle_event.key == K_DOWN:
t= t+.1
R=77
r=4
p=100
x= (R-r)*math.cos(t)+p*math.cos((R-r)/r*t)+width/2
y= (R-r)*math.sin(t)+p*math.cos((R-r)/r*t)+height/2
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#Key A
while idle_event.key == K_a:
t= t+.1
R=79
r=-78
p=99
x= (R-r)*math.cos(t)+p*math.cos((R-r)/r*t)+width/2
y= (R-r)*math.sin(t)+p*math.cos((R-r)/r*t)+height/2
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#Key b
while idle_event.key == K_b:
t= t+.1
R=30
r=2
p=100
x= (R-r)*math.cos(t)+p*math.cos((R-r)/r*t)+width/2
y= (R-r)*math.sin(t)+p*math.cos((R-r)/r*t)+height/2
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#Key c
while idle_event.key == K_c:
t= t+.1
R=100
r=2
p=5
x= 2*(R-r)*math.cos(t)+2*p*math.cos((R-r)/r*t)+width/2
y= 2*(R-r)*math.sin(t)+2*p*math.cos((R-r)/r*t)+height/2
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#Key d
while idle_event.key == K_d:
t= t+.1
R=79
r=-78
p=99
x =(R-r)*math.cos(t)+p*math.cos((R/r-1)*t)+width/2
y =(R-r)*math.sin(t)+p*math.sin((R/r-1)*t)+height/2
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#KEY e
while idle_event.key == K_e:
t= t+.1
R=49
r=3
p=55
x =(1.5)*((R+r)*math.cos(t)+p*math.cos((R+r)*t/2))+(width/2)
y =(1.5)*((R+r)*math.sin(t)+p*math.sin((R+r)*t/2))+(height/2)
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#KEY f
while idle_event.key == K_f:
t= t+.1
R=56
r=50
p=70
x =(1.5)*((R+r)*math.cos(t)+p*math.cos((R+r)*t/2))+(width/2)
y =(1.5)*((R+r)*math.sin(t)+p*math.sin((R+r)*t/2))+(height/2)
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#KEY g
while idle_event.key == K_g:
t= t+.1
x =50*((5-1.02)*math.cos(1.028*t/5)+2*math.cos((1-1.02/5)*t))+(width/2)
y =50*((5-1.02)*math.sin(1.028*t/5)+2*math.sin((1-1.02/5)*t))+(height/2)
for i in range(3):
color[i] = color[i] + direction[i]
for i in range(3) :
if color[i] < 0:
color[i] = 0
direction[i] = direction[i] * -1
elif color[i] >= 255 :
color[i] = 255
direction[i] = direction[i] * -1
# randomly change the color directon on occasion
if randint(0,511) == 128:
for i in range(3):
direction[i] = choice((-1,1))
# draw the line using the current values and width=3
pygame.draw.circle(screen, color, [x,y], 3)
# update the display
pygame.display.flip()
#------------------
# update the end points and the color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment