!  Fish bowl.
!
set mode "low8"
set color mix(0) 0,.2,.8
set color mix(1) 1,0,0
set color mix(2) 0,1,0
set color mix(3) .9,.5,0
set color mix(4) 1,1,0
set color mix(5) 1,0,1
set color mix(6) 0,1,1
set color mix(7) .5,.9,0

RANDOMIZE
DIM fish$(10),x(10),y(10),sx(10),sy(10)

CALL CaptureBubble(bubbles$)      !get bubble image

LET numfish = Int(rnd*3)+4
CALL CaptureFish(numfish,fish$,x,y)    !fish images

clear
FOR i = 1 to numfish              !show fish again
    BOX SHOW fish$(i) at x(i),y(i) using "xor"
NEXT i

MAT sx = 1                        !move up, right
MAT sy = 1

DO
   FOR i =1 to numfish
       BOX SHOW fish$(i) at x(i),y(i) using "xor"     !turn off old image
       CALL Move(x(i),sx(i))
       CALL Move(y(i),sy(i))      !get new spot
       BOX SHOW fish$(i) at x(i),y(i) using "xor"     !show image
       IF bub<>0 then             !update bubbles
          BOX SHOW bubbles$ at bx,by using "xor"
          LET by = Max(.05,by+rnd/40)
          BOX SHOW bubbles$ at bx,by using "xor"
          IF by>=1 then LET bub=0
       ELSE if rnd< .005 then     !time for bubbles?
          LET k = Int(numfish*rnd)+1
          LET bx = x(k)-.04
          LET by = y(k)+.05
          LET bub = 1
          BOX SHOW bubbles$ at bx,by using "xor"
       END IF
   NEXT i
LOOP
END

SUB Move(x,s)
    LET x = Min(.8,Max(.05,x+s*rnd/80))
    IF rnd<.05 then LET s = -s
END SUB

PICTURE Fish
    PLOT AREA: 0,.4; .2,.6; .5,.8; .45,.6; .7,.43; .8,.65; .9,.7; .85,.35; .9,0; .7,.27; .5,.2; .4,.1; .2,.2; .05,.25; 0,.3
    SET color "background"
    DRAW Bubble                   !use bubble for eye
END PICTURE

PICTURE Bubble
    PLOT AREA: .2,.45; .25,.4; .2,.35; .15,.4
END PICTURE

SUB CaptureBubble(bubbles$)
    set color "white"
    DRAW Bubble with scale(.05,.05) * shift(.01,.01)
    DRAW Bubble with scale(.05,.05) * shift(.01,.06)
    DRAW Bubble with scale(.07,.07) * shift(.03,.07)
    DRAW Bubble with scale(.08,.09) * shift(.02,.03)
    BOX KEEP 0,.2,0,.2 in bubbles$
    CLEAR
END SUB

SUB CaptureFish(numfish,fish$(),xa(),ya())
    ask max color cmax
    let c = int(rnd*cmax)+1
    LET x = .05
    FOR i=1 to numfish
        LET xsize = (rnd/4) + .1  !draw fish at startup
        LET ysize = (rnd/4) + .1
        IF x+xsize > 1 then
           LET x = .05
           LET y = y+.31
        END IF
        let c = mod(c,cmax)+1
        if c=0 then let c=1
        set color c
        DRAW Fish with scale(xsize,ysize) * shift(x,y)
        BOX KEEP x,x+xsize,y,y+ysize in fish$(i)
        LET xa(i) = x
        LET ya(i) = y
        LET x = x + xsize + .05
    NEXT i
END SUB
