There is a discrepancy between my sdlbasic and the documentation- in theory rnd() should return a number up to 999999999, but in practice it returns a number up to 32 bit signed maxint. To solve this I have used rnd(999999999) instead of rnd().
My sdlbasic page 1 || My 2nd sdlbasic page
Alphabetical index to the sdlbasic programs on this website.
Main sdlBasic homepage || sdlBasic Online Documentation || Page with 2005 documentation as a doc file (altervista)
The small images are portions of the displayed screen.
'string art for sdlbasic (Windows, Unix etc etc) ' S Shaw, 2013 SetDisplay(800,800,16,2)
RANDOMIZE(timer) p=3.1415926 scale=350 : ofs=390 r=1 : a=6 : b=6 : dta=0 WHILE INKEY<>k_esc cls for i= 0 to 360 t=i*p/180.0 x=r*cos(t) y=r*sin(t) x2=r*cos(a*t) y2=r*sin(b*t)
line(x*scale+ofs,y*scale+ofs,x2*scale+ofs,y2*scale+ofs)
next
locate(1,1) : prints ("ESC to exit, n for next, r for random ")
WAITKEY IF INKEY=78 OR INKEY=110 THEN dta=dta+1 if dta=1 then a=2 : b=2 end if if dta=2 then a=3 : b=3 end if if dta=3 then a=100 : b=100 end if if dta=4 then a=2 : b=3 : dta=0 end if end if if inkey=82 or inkey=114 then a=int(rnd(14)+1) : b=int(rnd(18)+1) end if wait(180) wend END
' Entwistle Generation 91 from Gumowski and Mira ' functions with symmetric attractors for sdlbasic ' (Windows, Unix etc etc) ' S Shaw, 2013 ' A between -1 and 1 B between 0.9 and 1.0001
' m is a scalar SetDisplay(1000,1000,16,2) RANDOMIZE it=4500 : cy=30 : m=1 a=rnd(10000)/10000 : b=0.90 + rnd(1000)/10000 if rnd(10)<5 then a=-a end if b=b+rnd(10000)/10000000 WHILE INKEY<>k_esc sc=1 cls for t=1 to cy c=2-2*a : x=4 : y=0 : w=a*x+c*x*x/(1+x*x) for n=0 to it dot(x*m*sc+490,y*m*sc+490) z=x : x=b*y+w : u=x*x : w=a*x+c*u/(1+u) : y=w-z next sc=sc+1 next
locate(1,1) : prints ("ESC to exit, i to zoom in, o to zoom out, space for another ")
locate(40,65): fprints("a b sc ")
locate(40,66): fprints(a) : fprints(" ") : fprints(b) : fprints(" ")
fprints(sc)
WAITKEY
IF INKEY=73 OR INKEY=105 THEN
m=m*1.5
END IF
IF INKEY=79 OR INKEY=111 THEN
m=m*0.65
END IF
IF INKEY=32 THEN
a=rnd(10000)/10000 : b=0.90 + rnd(1000)/10000 : m=1
if rnd(10)<5 then
a=-a end if b=b+rnd(10000)/10000000 END IF wend END
Maurer Rose on Wikipedia || A rose is a rose maths paper.
TI99/4A Group member Mike Cavanagh passed the general algorithm to me in 1989. Click on the small sample image for a collection of images put together into one big image.
This one here is essentially asymetric but many end results are quite pleasing, and a number of different graphics appear.
'a t and t line-art for sdlbasic ' (Windows, Unix etc etc) ' S Shaw, 2013 SetDisplay(800,800,16,2)
RANDOMIZE(timer) scale=350 : ofs=390 n=4 : d=43 : flag=0 WHILE INKEY<>k_esc cls A=0 : a=a+d NEWX=ofs : NEWY=ofs WHILE A>0.001 A=A+d A=(A/360-INT(A/360))*360 : A=INT(A+0.0001) X=n*A : X=(X/360-INT(X/360))*6.283185307 R=SIN (X) T=A*0.0174532925 OLDX=NEWX : OLDY=NEWY NEWX=R*SIN(T)*scale+ofs : NEWY=R*COS(T)*scale+ofs 'do not plot first line to reduce asymetry flag=flag+1 if flag>1 then LINE(OLDY,OLDX,NEWY,NEWX) end if END WHILE
locate(1,1) : prints ("ESC to exit, r for random ")
WAITKEY
if inkey=82 or inkey=114 then
n=int((rnd(35900)/100)+1) : d=int((rnd(35900)/100)+1)
NEWX=ofs : NEWY=ofs : flag=0 end if wait(180) wend END
' image using sdlBasic (Windows, Unix etc etc) ' from ti*mes 29 p28 ' take points equidistant on a circle and join each ' point to every other point with a line. simple ' S Shaw, 2014
SetDisplay(800,800,16,2) pi=3.14159265 p=2*pi dim a[30,1] randomize cls n=int(((rnd(2600)/100))+4) WHILE INKEY<>k_esc for x=0 to n-1 a[x,0]=sin(p/n*x)*300+400 a[x,1]=cos(p/n*x)*300+400 next fprints(n) fprints(" ") for i=0 to n-1 for ii=i+1 to n-1 line(a[i,1],a[i,0],a[ii,1],a[ii,0]) next next fprints("ESC to end, any other key for another") WAITKEY ' delay for x=1 to 1000000 next cls n=int(((rnd(2600)/100))+4) WEND END
' using sdlBasic (Windows, Unix etc etc) ' from ti*mes 31 p24 ' Truchet Tiles (an idea from 1704) ' from Clifford Pickover ' "Computers Pattern Chaos and Beauty" (1990) p 329 ' S Shaw, 2014 SetDisplay(800,800,16,2) pi=3.14159265
oldd=0 randomize cls dx=20 dy=20 xoff=0 yoff=0 r=dx/2 WHILE INKEY<>k_esc for j=1 to 35*35 d=int((rnd(199999)/100000)) ' select 0 or 1 random tile design if d=1 then if oldd=0 then xoff=xoff+dx end if for i=90 to 180 step 2 x=r*cos(i/180*pi)+xoff y=r*sin(i/180*pi)+yoff dot(x,y) next xc=xoff-dx yc=yoff+dy for i=270 to 360 step 2 x=r*cos(i/180*pi)+xc y=r*sin(i/180*pi)+yc dot(x,y) next end if if d=0 then if oldd=1 then xoff=xoff-dx end if for i=0 to 90 step 2 x=r*cos(i/180*pi)+xoff y=r*sin(i/180*pi)+yoff dot(x,y) next xc=xoff+dx yc=yoff+dy for i=180 to 270 step 2 x=r*cos(i/180*pi)+xc y=r*sin(i/180*pi)+yc dot(x,y) next end if xoff=xoff+dx if xoff>700 then yoff=yoff+dy xoff=0 end if oldd=d next fprints(" ESC to end, any other key for another ") WAITKEY cls dx=20 dy=20 xoff=0 yoff=0 r=dx/2 jump=180/dx WEND END
' using sdlBasic (Windows, Unix etc etc)
' from ti*mes 31 p66 ' (an idea from Clifford Pickover ' "Computers Pattern Chaos and Beauty (1990) ' S Shaw, 2014 SetDisplay(800,800,16,2) pi=3.14159265 randomize oc=200 : scale=1 : ct=0 dim l[10] : dim r[10] : dim a[10] WHILE INKEY<>k_esc cls oldx=90 : x=90 : oldy=110 : y=110 theta=0 for i=1 to ct*1.3333333 for j=1 to sets for k=1 to r[j] theta=theta+a[j] if theta>(2*pi+.00001) then theta=theta-2*pi end if x=l[j]*sin(theta)+x y=l[j]*cos(theta)+y
line(oldx*scale+oc,oldy*scale+oc,x*scale+oc,y*scale+oc)
oldx=x : oldy=y next next next fprints("space for initial image, ESC to exit") fprints(" i and o to zoom in and out") WAITKEY cls if inkey=32 then cls ct=0 sets=int(rnd(6000)/1000)+1 for i=1 to sets l[i]=int(rnd(8000)/1000)+18 ang=rnd(360000)/1000 if ang <12.1 then ang=ang+12.15 end if if ang>350 then ang=ang-12.1 end if if ang>160 AND ang <210 then ang=ang/4 end if a[i]=ang*pi/180 r[i]=int(rnd(5000)/1000)+3 ct=ct+r[i] next fprints("any key for another, ESC to exit") fprints(" i and o to zoom in and out") end if IF INKEY=73 OR INKEY=105 THEN scale=scale*1.2 cls END IF IF INKEY=79 OR INKEY=111 THEN scale=scale*0.8 cls END IF WEND END
' using sdlBasic (Windows, Unix etc etc) ' from ti*mes 31 p66 - Plotting Randomness ' (an idea from Clifford Pickover "Computers Pattern ' Chaos and Beauty (1990)) ' S Shaw, 2014 SetDisplay(800,800,16,2) randomize cls fprints("ESC to end") box(2,2,798,798) : circle(400,400,340) x=400 : oldx=400 : y=400 : oldy=400 c=1 : sp=1 WHILE INKEY<>k_esc ' rem three alternative codings to ' rem in / rem out: ' rem using random numbers (?) c=int(rnd(8000)/1000)+1 ' rem absolutely none random sequence- use ' c=c*(c<8)+1
' rem where c runs 1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8 and so on.
' rem or spanner in the works- random with a hitch about every 80th value
' c=int(rnd(8000)/1000)+1 : sp=rnd(82)
' if sp=20 then
' c=3
' end if
' rem try changing the value of c here from 1 to 8 and see the difference.
X=X+(C=1)*-1 : X=X+(C=2)*-1 : X=X+(C=3)*-1 : X=X+(C=4)*1 : X=X+(C=5)*1 : X=X+(C=6)*1
Y=Y+(C=2)*1 : Y=Y+(C=3)*-1 : Y=Y+(C=5)*1:: Y=Y+(C=6)*-1 : Y=Y+(C=7)*1 :Y=Y+(C=8)*-1
line(oldx,oldy,x,y) : oldx=x : oldy=y locate(40,40) fprints(c) WEND END
' image using sdlBasic (Windows, Unix etc etc) ' random faces - pages 47 and 327 of Computers ' Chaos Pattern and Beauty ' by Clifford A Pickover).(1990) ' for ti by S Shaw 1990 - SDL BASIC 2014 ' headings in the book include auto-correlation ' cartoon-faces for speech, ' cartoon faces in education, cognitive ' association of coordinates with ' facial features, target-pictures for children, ' faces and cancer genes. SetDisplay(800,800,16,2) pi=3.1415926 : S=4 ' S sets scale RANDOMIZE WHILE INKEY<>k_esc cls fprints("ESC to end, other for random next") Z=150 : OX=50 : OY=50 ' select 10 features at random - 100 possibilities
P1=5+INT(RND(6))-INT(RND(6)) P2=5+INT(RND(6))-INT(RND(6)) P3=5+INT(RND(6))-INT(RND(6)) P4=5+INT(RND(6))-INT(RND(6)) P5=5+INT(RND(6))-INT(RND(6)) P6=5+INT(RND(6))-INT(RND(6)) P7=5+INT(RND(6))-INT(RND(6)) P8=5+INT(RND(6))-INT(RND(6)) P9=5+INT(RND(6))-INT(RND(6)) P10=5+INT(RND(6))-INT(RND(6)) ' head Z=150 EX=0 : EY=0 :: R=30 IF P1>5 THEN EX=(P1-5)*2 ELSEIF P1<5 THEN EY=ABS((P1-5)*2) END IF FOR T=1 TO 360 X=(R+EX)*cos(T/180*pi)+50 Y=(R+EY)*sin(T/180*pi)+50 IF T=1 THEN DOT (X*S,Z*S-Y*S) ELSE LINE(OX*S,Z*S-OY*S,X*S,Z*S-Y*S) END IF OX=X :: OY=Y NEXT ' END HEAD ' eye P2 P7 P8 Z=150 : EX=0 : EY=0 : R=5 IF P2>5 THEN EX=(P2-5)*2 ELSEIF P2<5 THEN EY=ABS((P2-5)*2) END IF P7=P7-5 : P8=(P8-5)/2 FOR T=1 TO 360 X=(R+P8+EX)*COS(T/180*pi)+40-P7 Y=(R+P8+EY)*SIN(T/180*pi)+60 IF T=1 THEN DOT(X*S,Z*S-Y*S) ELSE LINE(OX*S,Z*S-OY*S,X*S,Z*S-Y*S) END IF OX=X : OY=Y NEXT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*S-OY*S,X*S,Z*S-Y*S) : OX=X : OY=Y
NEXT NEXT WAITKEY IF INKEY=82 OR INKEY=114 THEN CLS END IF WEND END
' from Clifford Pickover via A K Dewdney ' from ti*mes 36 Popcorn 1 ' for TI99/4a by S Shaw 1992 ' S Shaw, 2014 SetDisplay(800,800,16,2) randomize
cls fprints("ESC to end, R for next") H=0.05 flag=1 WHILE INKEY<>k_esc FOR J=1 TO 30 step 0.5 FOR K=1 TO 30 step 0.5 X=-4.3+J/3 Y=-4.3+K/3 FOR N=1 TO 70 if flag=1 then XX=X-H*SIN(Y+TAN(3+Y)) YY=Y-H*SIN(X+TAN(3+X)) end if if flag=2 then XX=X-H*SIN(Y+TAN(3*Y)) YY=Y-H*SIN(X+TAN(3*X)) end if if flag=3 then XX=X-H*SIN(Y+TAN(3+Y)) YY=Y-H*SIN(X+TAN(3*X)) end if X=XX Y=YY ROW=X*50 COL=Y*50 DOT(COL+850,ROW+870) NEXT NEXT NEXT fprints(" flag=") : fprints(flag) WAITKEY IF INKEY=82 OR INKEY=114 THEN CLS : fprints("ESC to end, R for next") flag=flag+1 if flag=4 then flag=1 end if END IF WEND END
' image using sdlBasic (Windows, Unix etc etc) ' attractor
' an idea from Clifford Pickover ' Computers and the Imagination ' S Shaw, 2014 / 2017 SetDisplay(800,800,16,2) randomize cls while inkey<>k_esc ' a,b=1 is boring but try others eg a,b=2 a=2:b=1 ' starting point x,y seems to ' have little effect x=int(rnd(9999/10000)*40) y=int(rnd(9999/10000)*40)
for t=1 to 400000 v1=sin(y*b):v2=sin(x*b) v3=sin(x*a):v4=sin(y*a) ' next lines sets the shape- try varying nx=v1+v2*v2+v2*v2*v2:ny=v3+v1*v1+v1*v1*v1 ' or nx=v1+v2*v2: ny=v3+v4*v4 ' or nx=v1+v2*v2+v2*v2*v2: ny=v3+v4*v4+v1*v1*v1 x=nx: y=ny px=180*x+220:py=180*y+200 dot(px,py) next fprints("ESC to end") waitkey WEND END