'Program SURFACE.BAS (c) 2007 by J. C. Sprott 'Produces 24 frames of a surface described by z=z(x,y) 'Compile this program with PowerBASIC for DOS defext a-z 'Use extended (80-bit) precision throughout dim p%(15) surface$="Torus" 'Shape to animate (Saddle, Cube, Cyl, Parab, Hyperb, Torus) nd&=10000 'Number of initial points to discard nf%=24 'Number of frames thn%=0 'Starting angle (0 to nf% -1) screen 7 call colorscale 'Reset color palette for red on cyan c$=command$ more: xmin=1e37: ymin=xmin: zmin=xmin xmax=-xmin: ymax=-ymin: zmax=-zmin n&=0 randomize 0 'Use the same random numbers for each frame do 'Loop until user presses the key if inkey$=chr$(27) then cls: end if n&>nd&/5 and n&1.6*ymm then ymm=xmm/1.6 if zmm>1.6*ymm then ymm=zmm/1.6 xav=(xmax+xmin)/2 yav=(ymax+ymin)/2 zav=(zmax+zmin)/2 cls end if select case lcase$(surface$) case "saddle": x=1-2*rnd: y=1-2*rnd: z=x*x-y*y case "cube" select case rnd case <1/3: x=sgn(rnd-.5): y=1-2*rnd: z=1-2*rnd case >2/3: x=1-2*rnd: y=sgn(rnd-.5): z=1-2*rnd case else: x=1-2*rnd: y=1-2*rnd: z=sgn(rnd-.5) end select case "cyl": x=1-2*rnd: theta=6.2832*rnd: y=cos(theta): z=sin(theta) case "parab": theta=6.2832*rnd: y=rnd*sin(theta): z=rnd*cos(theta): x=y*y+z*z case "hyperb": x=1-2*rnd: theta=6.2832*rnd: y=sqr(1+x*x)*cos(theta): z=sqr(1+x*x)*sin(theta) case "torus": theta=6.2832*rnd: phi=6.2832*rnd: x=cos(theta)*(1+.5*cos(phi)): y=sin(theta)*(1+.5*cos(phi)): z=.5*sin(phi) end select if n&>nd& then 'Assume transient has settled x1=(x-xav)/ymm 'Scales attractor to maximum y y1=(y-yav)/ymm z1=(z-zav)/ymm th=thn%*6.2832/nf% zp=18*(.5+z1*cos(th)+x1*sin(th)) if zp<2 then zp=2 if zp>15 then zp=15 xp=160+200*(x1*cos(th)-z1*sin(th))/(1.5-zp/30) yp=100-200*y1/(1.5-zp/30) if point(xp,yp)