import pygame
import random


x=200
y=200
move=0
r=100
g=250
b=255
color=0

screen=pygame.display.set_mode((400,400))
clock=pygame.time.Clock()

running=True
while running:
 move=random.randint(1,12)

#exits, pursued by a bear 
 for event in pygame.event.get():
     if event.type==pygame.QUIT:
      running=False

#oscillating between colours 
 if color==0:
     g=g-1
 if color==1:
     g=g+1

#stops it falling off the edge     
 if x>=400:
  x=x-2
  screen.set_at((x,y),(r,g,b))
 if x<=0:
  x=x+2
  screen.set_at((x,y),(r,g,b))
 if y>=400:
  y=y-2
  screen.set_at((x,y),(r,g,b))
 if y<=0:
  y=y+2
  screen.set_at((x,y),(r,g,b))

#moves around 
 if move==1:
  x=x+2
  screen.set_at((x,y),(r,g,b))
 if move==2:
  x=x-2
  screen.set_at((x,y),(r,g,b))
 if move==3:
  y=y+2
  screen.set_at((x,y),(r,g,b))
 if move==4:
  y=y-2
  screen.set_at((x,y),(r,g,b))
 if move==5:
  x=x+2
  y=y+1
  screen.set_at((x,y),(r,g,b))
 if move==6:
  x=x+2
  y=y-1
  screen.set_at((x,y),(r,g,b))
 if move==7:
  x=x+1
  y=y+2
  screen.set_at((x,y),(r,g,b))
 if move==8:
  x=x+1
  y=y-2
  screen.set_at((x,y),(r,g,b))
 if move==9:
  x=x-2
  y=y+1
  screen.set_at((x,y),(r,g,b))
 if move==10:
  x=x-2
  y=y-1
  screen.set_at((x,y),(r,g,b))
 if move==11:
  x=x-1
  y=y+2
  screen.set_at((x,y),(r,g,b))
 if move==12:
  x=x-1
  y=y-2
  screen.set_at((x,y),(r,g,b))

#stops colors becoming non-existant
 if g==250:
     color=0
 if g==0:
     color=1

#displays stuff at timed intervals     
 pygame.display.flip()
 clock.tick(200)
