Wally1 Posted November 10, 2013 Share Posted November 10, 2013 Does anybody remember a basic program (about 10-12 lines) involving formulas to draw a Fedora type hat in graphics 8? it was cool, I'd like to analyze it, if somebody could paste the code? thank you 1 Quote Link to comment Share on other sites More sharing options...
NuY Posted November 10, 2013 Share Posted November 10, 2013 Here you go: 11 GRAPHICS 24:COLOR 1:RESTORE 20 REM ...PROGRAM THAT PUTS A NEW PICTURE ON THE TV SCREEN GOES HERE EXCEPT SEE LINE 10 23 REM MICRO TECH UNLIM. AD IN 11/81,,,,,, COMPUTE 25 P=160:Q=100 30 XP=144:XR=1.5*3.1415927 40 YP=56:YR=1:ZP=64 50 XF=XR/XP:YF=YP/YR:ZF=XR/ZP 60 FOR ZI=-Q TO Q-1 STEP 1 70 IF ZI<-ZP OR ZI>ZP THEN GOTO 150 80 ZT=ZI*XP/ZP:ZZ=ZI 90 XL=(SQR(XP*XP-ZT*ZT)) 93 XL=INT(0.5+XL) 100 FOR XI=-XL TO XL STEP 1 105 TRAP 120 110 XT=SQR(XI*XI+ZT*ZT)*XF:XX=XI 120 YY=(SIN(XT)+0.4*SIN(3*XT))*YF 130 GOSUB 170 140 NEXT XI 145 IF PEEK(764)=42 THEN IN4O8=8:GOTO 300 150 NEXT ZI 160 GOTO 300 170 X1=(XX+ZZ+P) 180 Y1=YY-ZZ+Q:Y1=191-Y1 182 IF X1<0 OR X1>319 THEN RETURN 184 IF Y1<0 OR Y1>191 THEN RETURN 195 COLOR 1:PLOT X1,Y1 200 IF Y1>=190 THEN RETURN 210 COLOR 2:PLOT X1,Y1+1:DRAWTO X1,191 220 RETURN 230 REM ... PROGRAM TO PUT PICTURE ON TV SCREEN ENDS HERE 300 GOTO 300 Taken from Compute! issue 30 in a program to save a graphics 8 screen to disk. 3 Quote Link to comment Share on other sites More sharing options...
+MrFish Posted November 10, 2013 Share Posted November 10, 2013 Awesome! Quote Link to comment Share on other sites More sharing options...
Wally1 Posted November 10, 2013 Author Share Posted November 10, 2013 Hey, thanks a million! Wally Quote Link to comment Share on other sites More sharing options...
Hobart Posted February 22, 2015 Share Posted February 22, 2015 Some more history of that program: Atari 8-bit "Archimedes Spiral" demo - Found again! -jon 1 Quote Link to comment Share on other sites More sharing options...
+Larry Posted February 22, 2015 Share Posted February 22, 2015 Now to see (many years later) how fast we can get it to run using more modern Basics/Basic Compilers/accelerators (real hardware). -Larry Quote Link to comment Share on other sites More sharing options...
Rybags Posted February 22, 2015 Share Posted February 22, 2015 Faster line draw would help a bit. The part that erases from X,Y to X,191 could probably be changed to a smaller value which would speed it up a little. Anything that uses SIN or other trig functions will be slow. It's often a better idea to put them into an array, the granuality would need to be worked out first. Reordering and packing the lines of the Basic program also. I get the feeling we went over a lot of this in another thread in the last year or so. Quote Link to comment Share on other sites More sharing options...
bfollett Posted February 27, 2015 Share Posted February 27, 2015 (edited) I've had the folks over in the TI 99/4A forum playing with this example to get it running on that platform and they've been playing around with some optimizations. The following code cuts the time down to about a 28 minute run from the original 3 hour run. I tested it also with the Fast floating point option in Altirra and using Altirra Basic and that actually get the run time down to about 6 1/2 minutes. Not sure what a compiled Basic would accomplish. 100 DIM RR(320)120 FOR I=0 TO 320:RR(I)=193:NEXT I140 GRAPHICS 8+16:SETCOLOR 2,0,0150 XP=144:XR=4.71238905:XF=XR/XP160 FOR ZI=64 TO -64 STEP -1170 ZT=ZI*2.25:ZS=ZT*ZT180 XL=INT(SQR(20736-ZS)+0.5)190 FOR XI=0-XL TO XL200 XT=SQR(XI*XI+ZS)*XF210 YY=(SIN(XT)+SIN(XT*3)*0.4)*56220 X1=XI+ZI+160:Y1=90-YY+ZI223 IF RR(X1)<=Y1 THEN 250226 RR(X1)=Y1230 TRAP 250:COLOR 1:PLOT X1,Y1250 NEXT XI:NEXT ZI260 GOTO 260 Bob Edited February 27, 2015 by bfollett Quote Link to comment Share on other sites More sharing options...
+Stephen Posted February 27, 2015 Share Posted February 27, 2015 Lookup table for SIN function would be a huge speedup. I'm not sure if a table for SQRT could be constructed for this. Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted February 27, 2015 Share Posted February 27, 2015 What about making RR a string variable and using ascii values? Would that speed anything up? Quote Link to comment Share on other sites More sharing options...
Rybags Posted February 28, 2015 Share Posted February 28, 2015 Modified DList that only shows every 3rd scanline and blanks in-between would give probably 10-15% Then switch back to the normal one once the draw is completed. Further optimization could be to pack lines together where possible. Quote Link to comment Share on other sites More sharing options...
fujidude Posted February 28, 2015 Share Posted February 28, 2015 Run it in an emulator at full speed on a fast computer. Quote Link to comment Share on other sites More sharing options...
dmsc Posted February 28, 2015 Share Posted February 28, 2015 Hi!, I've had the folks over in the TI 99/4A forum playing with this example to get it running on that platform and they've been playing around with some optimizations. The following code cuts the time down to about a 28 minute run from the original 3 hour run. I tested it also with the Fast floating point option in Altirra and using Altirra Basic and that actually get the run time down to about 6 1/2 minutes. Not sure what a compiled Basic would accomplish. A good way to speed-up graphics is simply calculating less values :-) This interpolates the positions each 10 pixels: 100 DIM RR(320) 110 FOR I=0 TO 320:RR(I)=193:NEXT I 120 GRAPHICS 8+16:SETCOLOR 2,0,0 130 XP=144:XR=4.71238905:XF=XR/XP 140 COLOR 1:TRAP 320 150 FOR ZI=64 TO -64 STEP -1 160 ZT=ZI*2.25:ZS=ZT*ZT 170 XL=INT(SQR(20736-ZS)+0.5) 180 XT=SQR(XL*XL+ZS)*XF 190 YY=(SIN(XT)+SIN(XT*3)*0.4)*56 200 X1=-XL+ZI+160:Y1=90-YY+ZI 210 FOR XI=-XL+10 TO XL+9 STEP 10 220 XT=SQR(XI*XI+ZS)*XF 230 YY=(SIN(XT)+SIN(XT*3)*0.4)*56 240 X2=XI+ZI+160:Y2=90-YY+ZI 250 IY=(Y2-Y1)*0.1 260 XE=X2-1 270 IF XI>XL THEN XE=XL+ZI+160 280 FOR X=X1 TO XE 290 IF RR(X)<=Y1 THEN 320 300 RR(X)=Y1 310 PLOT X,Y1 320 Y1=Y1+IY:NEXT X:X1=X2:Y1=Y2 330 NEXT XI:NEXT ZI 340 GOTO 340 The runtime in TurboBasic XL is 7.5min in PAL, 8min in NTSC, down from about 39min in PAL. 1 Quote Link to comment Share on other sites More sharing options...
devwebcl Posted February 28, 2015 Share Posted February 28, 2015 (edited) Changing few lines based on the algorithm/figure symmetry we can speed-up (it should take a half of time) which remains me, Knuth quote: "premature optimization is the root of all evil." http://manillismo.blogspot.com/2015/02/espiral-de-arquimedes.html 190 FOR XI=0 TO XL 225 X11=-XI+ZI+160 231 PLOT X11,Y1 241 PLOT X11,Y1+1:DRAWTO X11,191 Edited February 28, 2015 by devwebcl Quote Link to comment Share on other sites More sharing options...
dmsc Posted February 28, 2015 Share Posted February 28, 2015 Hi!, Changing few lines based on the algorithm/figure symmetry we can speed-up (it should take a half of time) You can combine both optimizations, now runtime in TurboBasic XL (PAL) is 5min 20sec: 100 DIM RR(320) 110 FOR I=0 TO 320:RR(I)=193:NEXT I 120 GRAPHICS 8+16:SETCOLOR 2,0,0 130 XP=144:XR=4.71238905:XF=XR/XP 140 COLOR 1:TRAP 340 150 FOR ZI=64 TO -64 STEP -1 160 ZT=ZI*2.25:ZS=ZT*ZT 170 XL=INT(SQR(20736-ZS)+0.5) 180 XT=SQR(ZS)*XF 190 YY=(SIN(XT)+SIN(XT*3)*0.4)*56 200 X1=ZI+160:Y1=90-YY+ZI:Q=2*X1 210 FOR XI=10 TO XL+9 STEP 10 220 XT=SQR(XI*XI+ZS)*XF 230 YY=(SIN(XT)+SIN(XT*3)*0.4)*56 240 X2=XI+ZI+160:Y2=90-YY+ZI 250 IY=(Y2-Y1)*0.1 260 XE=X2-1 270 IF XI>XL THEN XE=XL+ZI+160 280 FOR X=X1 TO XE 290 IF RR(X)<=Y1 THEN 310 300 RR(X)=Y1:PLOT X,Y1 310 R=Q-X 320 IF RR(R)<=Y1 THEN 340 330 RR(R)=Y1:PLOT R,Y1 340 Y1=Y1+IY:NEXT X:X1=X2:Y1=Y2 350 NEXT XI:NEXT ZI 360 GOTO 360 1 Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted February 28, 2015 Share Posted February 28, 2015 Wouldn't another (albeit very tiny) optimisation be to stop computing XL+9 at the top of the FOR loop and instead define a variable equal to XL+9 beforehand? Quote Link to comment Share on other sites More sharing options...
Rybags Posted February 28, 2015 Share Posted February 28, 2015 It's the only reference I can see for it... the destination for loops is only calculated at the first iteration, ie if the value of XL changes during the loop it makes no difference to the exit criteria. Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted February 28, 2015 Share Posted February 28, 2015 I wasn't sure if that was the case: thanks. I don't recall too much about the workings of BASIC. Quote Link to comment Share on other sites More sharing options...
devwebcl Posted February 28, 2015 Share Posted February 28, 2015 ZI can be optimized as well The problem is the order for drawing it Quote Link to comment Share on other sites More sharing options...
bfollett Posted February 28, 2015 Share Posted February 28, 2015 The original new code I posted produced the same output as the original code in the article. I just ran the new code with both new optimizations in post #15 and there is some compromise going on. The output definitely isn't as smooth, but yes it's so much faster. Screen shots from new code and new code with optimizations. Bob Quote Link to comment Share on other sites More sharing options...
ClausB Posted February 28, 2015 Share Posted February 28, 2015 (edited) I always thought the sinc function was prettier than the fat hat. Here's the program I wrote back in the day. It takes about 40 minutes (emulated). Edited February 28, 2015 by ClausB 3 Quote Link to comment Share on other sites More sharing options...
+Larry Posted February 28, 2015 Share Posted February 28, 2015 The original new code I posted produced the same output as the original code in the article. I just ran the new code with both new optimizations in post #15 and there is some compromise going on. The output definitely isn't as smooth, but yes it's so much faster. Screen shots from new code and new code with optimizations. Bob Yes, at some point, it's no longer the same thing. The output should look the same -- not an approximation (IMO). -Larry 2 Quote Link to comment Share on other sites More sharing options...
dmsc Posted February 28, 2015 Share Posted February 28, 2015 Hi!, The original new code I posted produced the same output as the original code in the article. I just ran the new code with both new optimizations in post #15 and there is some compromise going on. The output definitely isn't as smooth, but yes it's so much faster. Screen shots from new code and new code with optimization Yes, my code only calculates the complex function once each 10 pixels and interpolates the values, this is the reason for the 7x speedup. You can interpolate over shorter intervals for a closer approximation. Another possibility would be to use quadratic interpolation, this needs one more add in the inner loop but will look smoother, and by using cubic interpolation the plotted curve can be made completely smooth. Quote Link to comment Share on other sites More sharing options...
devwebcl Posted February 28, 2015 Share Posted February 28, 2015 The original new code I posted produced the same output as the original code in the article. I just ran the new code with both new optimizations in post #15 and there is some compromise going on. The output definitely isn't as smooth, but yes it's so much faster. Screen shots from new code and new code with optimizations. Bob Try using my optimization on post #14. The result is the same http://manillismo.blogspot.com/2015/02/espiral-de-arquimedes.html Quote Link to comment Share on other sites More sharing options...
devwebcl Posted February 28, 2015 Share Posted February 28, 2015 I have a new optimization avoid some add operators: http://manillismo.blogspot.com/2015/02/arquimedes-2.html 160 FOR ZI=96 TO 224 170 ZT=(ZI-160)*2.25:ZS=ZT*ZT 220 X1=XI+ZI:Y1=-70-YY+ZI 225 X11=-XI+ZI Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.