#okhan 4/18/00
#9A I wanted to make a story board that showed variations in 
#a scene made up of a foreground, background and some objects.
#It is a kind of timelapse photography. It is different every 
#it is played.
   
import math 
g.norefresh()

def makePt(x,y):
 data=[]
 data.append(x)
 data.append(y)
 return data
 print data

def getX(pt):
 if len(pt)==2:
  return pt[0]
 print "Error: not a point"

def getY(pt):
 if len(pt)==2:
  return pt[1]
 print "error: not a point"
 
def drawLine(pt1, pt2):
 g.line(int(getX(pt1)), int(getY(pt1)),int(getX(pt2)), int(getY(pt2)))
  
def drawPoly (ptlb, ptrb, ptrt, ptlt):
 drawLine(ptlb, ptrb)
 drawLine(ptrb, ptrt)
 drawLine(ptrt, ptlt)
 drawLine(ptlt, ptlb)
      
def drawField(ptL, ptB, factor):
 x1=getX(ptL)
 x2=getX(ptB)
 y1=getY(ptL)
 y2=(getY(ptB)-y1)/factor+y1
 for xR in range(x1, x2):
  g.line(xR,y1,xR,y2)
#------------------------------------------
##random generator

def nextRand(val):
 return (val*3 + 234567657) % 12345676
 
def random (seedVal, maxVal):
 return (seedVal % maxVal)

#------------------------------------------
##objects

def objects(ptL, ptB, color):
 x1=getX(ptL)
 x2=getX(ptB)
 y1=getY(ptL)
 y2=getY(ptB)
 span= int((x2-x1)/10)
 seed= g.getTime(4)
 #print span
 for t in range(0,span):    
    g.pen(50-color)
    X1= (x1+10*t)+5
    #print X1
    Y1= y1+5
    #print Y2
    ranX2= random(seed, (x2-x1))
    #print ranX2
    X2= x1+ranX2       
    ranY2=random(seed, (y2-y1))
    #print ranY2
    Y2= y1+ranY2 
    g.line(X1,Y1,X2,Y2)
    seed= seed+(g.getTime(4))
 
#------------------------------------------
##frames of composition
  
def frame(ptL, ptB, color, factor):
 ##filler
 g.pen(70-color)
 drawField(ptL, ptB, 1)
 g.pen(color)
 drawField(ptL, ptB, factor)
 ##objects
 objects(ptL, ptB, color)
 ##frame
 g.pen(100)
 ptlb= ptL
 ptrt= ptB
 ptrb= makePt(getX(ptB), getY(ptL))
 ptlt= makePt(getX(ptL), getY(ptB))
 drawPoly (ptlb, ptrb, ptrt, ptlt)

#-----------------------------------------

g.paper(0) 
g.pen(100)
seed1=g.getTime(4)
factor=random(seed1,5)+1
for y in range(0,5):  
  for x in range(0,5):   
     pl= makePt(x*50,y*40)
     ph= makePt(50+x*50,40+y*40)
     seed1= seed1+g.getTime(4)
     color=random(seed1,50)
     factor=random(seed1,6)+2
     frame(pl, ph, color, factor)
  
g.refresh()