Jump to content
IGNORED

Graphics 8 Fedora Hat


Wally1

Recommended Posts

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.

  • Like 3
Link to comment
Share on other sites

  • 1 year later...

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.

Link to comment
Share on other sites

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 I
140 GRAPHICS 8+16:SETCOLOR 2,0,0
150 XP=144:XR=4.71238905:XF=XR/XP
160 FOR ZI=64 TO -64 STEP -1
170 ZT=ZI*2.25:ZS=ZT*ZT
180 XL=INT(SQR(20736-ZS)+0.5)
190 FOR XI=0-XL TO XL
200 XT=SQR(XI*XI+ZS)*XF
210 YY=(SIN(XT)+SIN(XT*3)*0.4)*56
220 X1=XI+ZI+160:Y1=90-YY+ZI
223 IF RR(X1)<=Y1 THEN 250
226 RR(X1)=Y1
230 TRAP 250:COLOR 1:PLOT X1,Y1
250 NEXT XI:NEXT ZI
260 GOTO 260

 

Bob

Edited by bfollett
Link to comment
Share on other sites

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.
  • Like 1
Link to comment
Share on other sites

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 by devwebcl
Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

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

 

 

post-18691-0-22902600-1425129509_thumb.png

post-18691-0-72967300-1425129517_thumb.png

Link to comment
Share on other sites

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

  • Like 2
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...