REM *** ZOOMER-ROTATOR by balroq 2002
setrgb 0,70,60,80
open window 640,512
dim py(900),pz(900),cs(720),sn(720)
dim pr(320,320),pg(320,320),pb(320,320)

' *** GENERATE VERTEX
for y=1 to 30
 for x=1 to 30
 a=a+1
 py(a)=x-15
 pz(a)=y-15
 next x
next y

' GENERATE 320*320 16-BIT PICTURE TO RAM
setrgb 1,0,0,0
fill rect 159,95 to 482,418
for x=0 to 320
 for y=0 to 320
 a=0
 for e=0 to 240 step 80
 if x>e and x<e+41 then
  if y<40 a=32
  if y>79 and y<121 a=32
  if y>159 and y<201 a=32
  if y>241 and y<281 a=32
 elseif x>e+40 and x<e+81 then
  if y>39 and y<81 a=32
  if y>119 and y<161 a=32
  if y>199 and y<241 a=32
  if y>279 a=32
 fi
 next e
 pr(x,y)=127+cos(y/35)*127-a
 pg(x,y)=(127+sin((x+y)/18.1)*127+y*.8)/2-a
 pb(x,y)=127+sin(x/15)*127-a
 setrgb 1,pr(x,y),pg(x,y),pb(x,y)
 rect 160+x,96+y to 161+x,97+y
 next y
next x
wait 2
clear window

' GENERATE SINE TABLE
for ang=0 to 720
 cs(ang)=cos(ang*pi/360)
 sn(ang)=sin(ang*pi/360)
next ang

' *** DRAW SOME GRAPHICS
setrgb 1,0,0,0
for a=1 to 0 step -1
 setdrawbuf a
 fill rect 199,151 to 441,393
 text 199,406,"Zoomer-Rotator by balroq"
next a

' *** MAIN LOOP
label loop
setdispbuf bu:bu=1-bu:setdrawbuf bu
mm=mm+.15
rx=360+cos(mm/5)*360
zm=200+cos(mm/3)*180
dx=200:dy=152
mx=160+cos(mm/4)*160
my=160+sin(mm/9)*160
for p=1 to 900
 nx=cs(rx)*pz(p)-sn(rx)*py(p)
 ny=cs(rx)*py(p)+sn(rx)*pz(p)
 nz=cs(180)*nx+zm
 tx=160+nx*300/nz+mx
 ty=160+ny*300/nz+my
 while(tx<0):tx=tx+320:wend
 while(ty<0):ty=ty+320:wend
 while(tx>320):tx=tx-320:wend
 while(ty>320):ty=ty-320:wend
 setrgb 1,pr(tx,ty),pg(tx,ty),pb(tx,ty)
 fill rect dx,dy to 8+dx,8+dy
 dx=dx+8
 if dx=440 then
  dx=200
  dy=dy+8
 fi
next p
goto loop
