#okhan 4/18/00
#9C a scroll bar gives you control over the changing image
 
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(color)
 ptlb= ptL
 ptrt= ptB
 ptrb= makePt(getX(ptB), getY(ptL))
 ptlt= makePt(getX(ptL), getY(ptB))
 drawPoly (ptlb, ptrb, ptrt, ptlt)

#-----------------------------------------
g.paper(100)
while 1:
  mx=g.getMouse(1)
  my=g.getMouse(2)
  mz=g.getMouse(3)
  seed1=g.getTime(4)
  factor=random(seed1,5)+1
  
  
  if mz==100:
   p2=makePt(170,my-3)
   p3=makePt(190,my+3)
   p4=makePt(179,0)
   p5=makePt(179,200)
   p6=makePt(181,0)
   p7=makePt(181,200)
   p8=makePt(160,0)
   p9=makePt(200,200)
   if mx>=160:
     for y in range(0,8):  
      for x in range(0,1):   
       pl= makePt(x*160,y*50)
       ph= makePt(160+x*160,50+y*50)
       seed1= seed1+g.getTime(4)
       factor=random(seed1,5)+1 
       frame(pl, ph, my/2, factor)
     
       g.pen(80)
       drawField(p8,p9,1)
       g.pen(20)
       drawLine(p4,p5)
       drawLine(p6,p7)
       drawField(p2,p3,1) 
       g.refresh()