'An Example of a 40 line demo adhering to the rules of
'the 40 line demo competition. If you exclude these 
'comments the code comes in at 39 lines.
'it has a lightsourced, cell shaded cube and 133 3d stars
'all in realtime (C) Shockwave.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setrgb 0,4,10,4: setrgb 2,0,50,0: setrgb 3,0,30,0:open window 640,512:polys=8 
dim x(polys),y(polys),z(polys),tx(polys),ty(polys),tz(polys):str=133: dim sx(str),sy(str),sz(str):mm=0
for a=1 to str sx(a)=-1000+ran(2000):sy(a)=-1000+ran(2000):sz(a)=mm:mm=mm+10/str
next a: dim cs(360),sn(360): for ang=0 to 360
  cs(ang)=cos(ang*(pi/180)):  sn(ang)=sin(ang*(pi/180)): next ang
for a=1 to polys read x(a),y(a),z(a) : next a
data -10,10,10,10,10,10,10,-10,10,-10,-10,10,-10,10,-10,10,10,-10,10,-10,-10,-10,-10,-10:repeat
setdrawbuf dw:dw=1-dw: setdispbuf dw: clear window:for a=1 to str
col=255-sz(a)*30 : setrgb 1,50,col,50:xt=(sx(a)/sz(a))+320
yt=(sy(a)/sz(a))+256: fill rect xt,yt to xt+(10-sz(a)),yt+(10-sz(a))
 sz(a)=sz(a)-.1: if sz(a)<0 sz(a)=sz(a)+10:next a
mm=mm+.04 : size=7+5*sin(mm): gosub rotate
r=20+19*sin(mm/3) : g=20+19*cos(mm/4) : b=20+19*sin(mm/7)
f1=1 : f2=2 : f3=3 : f4=4: gosub draw
f1=5 : f2=8 : f3=7 : f4=6: gosub draw
f1=6 : f2=2 : f3=1 : f4=5: gosub draw
f1=8 : f2=4 : f3=3 : f4=7: gosub draw
f1=2 : f2=6 : f3=7 : f4=3: gosub draw
f1=8 : f2=5 : f3=1 : f4=4: gosub draw
setrgb 1,0,0,0 : text 321,257,"(C) SHOCKWAVE 40 LINE DEMO (C)","cc"
setrgb 1,255,255,255: text 320,256,"(C) SHOCKWAVE 40 LINE DEMO (C)","cc":until (and(peek("port1"),16384)<>0)
exit
label draw: vx1=tx(f1)-tx(f2):vy1= ty(f1)-ty(f2):vx2=tx(f3)-tx(f2):vy2=ty(f3)-ty(f2)
  if  (vx1*vy2-vx2*vy1)<0 then
light=-(tz(f1)+tz(f2)+tz(f3)+tz(f4))*7:setrgb 1,r+light,g+light,b+light
fill triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
fill triangle tx(f1),ty(f1) to tx(f4),ty(f4) to tx(f3),ty(f3)
setrgb 1,0,0,0
line tx(f1),ty(f1) to tx(f2),ty(f2):line tx(f2),ty(f2) to tx(f3),ty(f3):line tx(f3),ty(f3) to tx(f4),ty(f4):line tx(f4),ty(f4) to tx(f1),ty(f1)
fi: return
label rotate: for a=1 to polys
  x1=x(a):  y1=y(a):  z1=z(a)
  xx=x1:yy=y1*cs(xr)+z1*sn(xr):zz=z1*cs(xr)-y1*sn(xr):  y1=yy:x1=xx*cs(yr)-zz*sn(yr):z1=xx*sn(yr)+zz*cs(yr)
  zz=z1:xx=x1*cs(zr)-y1*sn(zr):yy=x1*sn(zr)+y1*cs(zr):  xx=size*(xx/((zz/50)+1))+320:  yy=size*(yy/((zz/50)+1))+256
  tx(a)=xx:ty(a)=yy:tz(a)=zz: next a
xr=xr+1:yr=yr+2:zr=zr+2:if xr>360 xr=xr-360
if yr>360 yr=yr-360
if zr>360 zr=zr-360
return



