3D TEXT Demo

Anything QL Software or Programming Related.
Post Reply
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

3D TEXT Demo

Post by stevepoole »

Hi,
Today being my 69th bithday, EmmBee suggested I share this demo with you...
Best Wishes,
Steve Poole.

Code: Select all

100 :
110 CLEAR: REMark TEXT-TUMBLER. Perspective Animation. by S.Poole. v30may2000
120 rs=50: slp=0: qz=rs*TAN(RAD(slp)): scy=.5: Nb=13: DIM t(Nb,5): zz=-6
130 Xaxis=1: Yaxis=2: Zaxis=3
140 r90=RAD(90): r180=PI: r270=RAD(270): r360=PI*2: ac=512: dn=256
150 WINDOW ac,dn,0,0: PAPER 0: INK 7: CLS: WINDOW#2,512,206,0,0: INK#0,7
160 scx=.75*scy*(ac/dn): SCALE scy,-scx/2,-scy/2
170 REPeat loop
180 FOR nx=-9 TO 9 STEP 6, 3 TO -3 STEP -6
190 cx=nx: cy=scy+nx*2: cz=qz*-10: tz=qz+nx*20 : REMark cy=scy to avoid distortion!
200 tx=(rs*SIN(RAD(ng-180)))+cx: ty=(rs*COS(RAD(ng-180)))+cy: Fx=cx-tx: fy=cy-ty
210 fh=((Fx^2)+(fy^2))^.5: fz=cz-tz: c=ATAN_(fy,Fx): b=ATAN_(fz,fh)
220 RESTORE :  PAUSE 10
230 FOR f=1 TO Nb: READ t(f,Xaxis),t(f,Yaxis),t(f,Zaxis): END FOR f
240 REMark REPeat loop
250 FOR axis=3 TO 1 STEP -1
260     FOR thru=0 TO r360 STEP PI/50
270         FOR f=1 TO Nb
280             CIRCLE 0,0,1E-2
290             rotate  axis,thru,t(f,Xaxis),t(f,Yaxis),t(f,Zaxis)
300             ok=VIEW_(Rx,Ry,Rz): t(f,4)=m: t(f,5)=n
310         END FOR f: OVER -1
320         FOR j=1 TO 2
330         LINE t(1,4),t(1,5) TO t(2,4),t(2,5) TO t(3,4),t(3,5) TO t(4,4),t(4,5)
340         LINE TO t(5,4),t(5,5) TO t(6,4),t(6,5) TO t(7,4),t(7,5) TO t(8,4),t(8,5)
350         LINE TO t(1,4),t(1,5), t(9,4),t(9,5) TO t(10,4),t(10,5)
360         LINE t(11,4),t(11,5) TO t(12,4),t(12,5) TO t(13,4),t(13,5)
370         IF j=1: PAUSE 1: IF KEYROW(1): EXIT loop
380         END FOR j: OVER 0
390     END FOR thru
400 END FOR axis
410 END FOR nx
420 END REPeat loop
430 PAUSE: WINDOW 512,206,0,0: STOP
440 :
450 DEFine PROCedure rotate(axe,agl,xx,yy,zz)
460 Rx=xx: Ry=yy: Rz=zz: IF Rx=0 : IF Ry=0: IF Rz=0: RETurn
470 op=Rz: aj=Rx: IF axe=Xaxis: aj=Ry: END IF : IF axe=Zaxis: op=Ry
480 Sop=(op>0)-(op<0): Saj=(aj>0)-(aj<0): hp=((op^2)+(aj^2))^.5
490 IF Sop=0 AND Saj=0: GO TO 680
500 IF Sop=0 AND Saj>0: ang=0
510 IF Sop>0 AND Saj>0: ang=ASIN(ABS(op/hp))
520 IF Sop>0 AND Saj=0: ang=r90
530 IF Sop>0 AND Saj<0: ang=r180-ASIN(ABS(op/hp))
540 IF Sop=0 AND Saj<0: ang=r180
550 IF Sop<0 AND Saj<0: ang=r180+ASIN(ABS(op/hp))
560 IF Sop<0 AND Saj=0: ang=r270
570 IF Sop<0 AND Saj>0: ang=r360-ASIN(ABS(op/hp))
580 ang=ang+agl: IF ang<0    : ang=ang+r360: END IF
590 IF ang>=r360:ang=ang-r360: END IF
600 IF ang=0                 : Sop=0: Saj=1: op=0: aj=hp
610 IF ang>0:    IF ang<r90  : Sop=1: Saj=1: op=hp*SIN(ang): aj=hp*COS(ang)
620 IF ang=r90               : Sop=1: Saj=0: op=hp: aj=0
630 IF ang>r90 : IF ang<r180 : Sop=1: Saj=-1:ng=r180-ang:op=hp*SIN(ng):aj=hp*COS(ng)
640 IF ang=r180              : Sop=0: Saj=-1: op=0: aj=hp
650 IF ang>r180: IF ang<r270 : Sop=-1:Saj=-1:ng=ang-r180:op=hp*SIN(ng):aj=hp*COS(ng)
660 IF ang=r270              : Sop=-1: Saj=0: op=hp: aj=0
670 IF ang>r270              : Sop=-1: Saj=1:ng=r360-ang:op=hp*SIN(ng):aj=hp*COS(ng)
680 IF axe=Xaxis: Ry=aj*Saj: Rz=op*Sop: Rx=xx
690 IF axe=Yaxis: Rx=aj*Saj: Rz=op*Sop: Ry=yy
700 IF axe=Zaxis: Rx=aj*Saj: Ry=op*Sop: Rz=zz
710 END DEFine rotate
720 :
730 DEFine FuNction VIEW_(vx,vy,vz)
740 lx=vx-tx: ly=vy-ty: lh=((lx^2)+(ly^2))^.5
750 lz=vz-tz: e=ATAN_(lz,lh)-b: h=ATAN_(ly,lx)-c
760 IF h > PI: h=h-PI*2: END IF : IF h<-PI: h=h+PI*2: END IF
770 IF e > PI: e=e-PI*2: END IF : IF e<-PI: e=e+PI*2: END IF
780 m=TAN(h)*1: n=-1*TAN(e)*((m^2)+1)^.5: RETurn 1
790 END DEFine V
800 :
810 DEFine FuNction ATAN_(oo,aa)
820 so=(oo>0)-(oo<0): sa=(aa>0)-(aa<0)
830 IF (so=0 OR so='1') AND sa=0: RETurn 0: END IF
840 IF so=0   AND sa='1': RETurn r90: END IF
850 IF so=-1  AND sa=0: RETurn r180 : END IF
860 IF so=0   AND sa=-1: RETurn r270: END IF
870 oa=ATAN(aa/oo)
880 IF so='1' AND sa='1': RETurn oa: END IF
890 IF so=-1  AND (sa='1' OR sa=-1): RETurn r180+oa: END IF
900 IF so='1' AND sa=-1: RETurn r360+oa: END IF
910 END DEFine ATAN_
920 :
930 DATA -7,-6,zz, -9,-6,zz, -11,-4,zz, -11,4,zz, -9,6,zz, -5,6,zz, -3,4,zz
940 DATA -3,-2,zz, -3,-6,zz, -7,-2,zz,   3,6,zz, 3,-6,zz, 11,-6,zz


User avatar
Dave
SandySuperQDave
Posts: 2765
Joined: Sat Jan 22, 2011 6:52 am
Location: Austin, TX
Contact:

Re: 3D TEXT Demo

Post by Dave »

Happy Birthday!

Alas, I get an error in expression at line 200, JS ROM, TK2, 640K.

200 tx=(rs*SIN(RAD(ng-180)))+cx: ty=(rs*COS(RAD(ng-180)))+cy: Fx=cx-tx: fy=cy-ty


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: 3D TEXT Demo

Post by dilwyn »

Dave wrote:Happy Birthday!

Alas, I get an error in expression at line 200, JS ROM, TK2, 640K.

200 tx=(rs*SIN(RAD(ng-180)))+cx: ty=(rs*COS(RAD(ng-180)))+cy: Fx=cx-tx: fy=cy-ty
Not actually tried it on anything other than QPC2 (where it works quite well), a 5-second scan of the program implies the variable ng is used in line 200 without being assigned first - you could test this with something like replacing the CLEAR in line 110 with something like ng=0

(our old friend of default variable values?)

Might be wrong, I literally only looked at it for a few seconds.


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: 3D TEXT Demo

Post by stevepoole »

Hi Folks,
Yes, this program was written on a SGC with SMSQ. On an unexpanded system, it is much slower, so :
As Dilwyn says,
130 ..... append : ..... : ng=0
And
260 Modify to read ......STEP PI/10
370 Modify to read .... PAUSE 10

Then it works OK, but sluggishly... Which is the reason why my attempts at 3D animation in Basic in the '80s was abandoned...
On QPC2, animation is fine!
Regards,
Steve.


User avatar
Dave
SandySuperQDave
Posts: 2765
Joined: Sat Jan 22, 2011 6:52 am
Location: Austin, TX
Contact:

Re: 3D TEXT Demo

Post by Dave »

I was running it at SGC speed!!! on QemuLator on a 4.4GHz i7 Mac with a GTX 1080 Ti video card. The error wasn't slugging at all ;)


User avatar
ql_freak
Gold Card
Posts: 354
Joined: Sun Jan 18, 2015 1:29 am

Re: 3D TEXT Demo

Post by ql_freak »

I was running it (after correcting line 110) in uQLx on Windows 10 with WSL+XMing X11 server and Minerva 1.98.

It runs quite well. Speed is about 70% as on QPC2.


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
Post Reply