Issues with a 3D plotting routine
Posted: Fri Oct 18, 2024 4:43 pm
Hi everybody
I need some help as I don't know if I'm doing things wrong or there is an issue with the compiler.
I tried to translate into UGBASIC's syntax, but without success, the following routine written with Epyx toolkit for the Commodore 64's BASIC. It works fine with Epyx toolkit installed, and draws a 3D picture of a figure that looks like a hat.
10 RESET:MULTI:BACKGROUNDBLACK:BORDERBLACK:
20 P=160
30 Q=100:XP=144:XR=1.5*pi:YP=56:YR=1
50 ZP=64:XF=XR/XP:YF=YP/YR:ZF=XR/ZP
60 FORZI=-QTOQ-1
70 IF ZI<-ZP OR ZI>ZP GOTO150
80 ZT=ZI*XP/ZP:ZZ=ZI
90 XL=INT (.5+SQR(XP*XP-ZT*ZT))
100 FOR XI=-XLTOXL
110 XT=SQR(XI*XI+ZT*ZT)*XF:XX=XI
120 YY=(SIN(XT)+.4*SIN(3*XT))*YF
130 GOSUB 170
140 NEXT XI
150 NEXT ZI
160 GOTO 160
170 X1=XX+ZZ+P:Y1=YY-ZZ+Q
180 COLORGREEN:DOT X1,Y1
190 IF Y1=0 GOTO 220
200 COLORBLACK: LINE X1,Y1-1TOX1,0
210 RETURN
My translation is the following. I can't see what's wrong but it does not work
BITMAP ENABLE (320,200,16):CLS BLACK:
p1=160
q=100:xp=144:xr=01.5*PI:yp=56:yr=01
zp=64:xf=xr/xp:yf=yp/yr:zf=xr/zp
FOR zi=-q TO q-1
IF zi<-zp OR zi>zp THEN GOTO endloop
zt=zi*xp/zp:zz=zi
xl=INT(.5+SQR(xp^2-zt^2))
FOR xi=-xl TO xl
DEGREE
xt=(SQR(xi*xi+zt*zt)*xf)*180/PI:xx=xi
yy=(SIN (xt)+.4*SIN (3*xt))*yf
GOSUB continue
NEXT
endloop:
NEXT
loop:
GOTO loop
continue:
x1=xx+zz+p1:y1=INT(yy-zz+q)
PLOT x1,y1,GREEN
IF y1=0 THEN GOTO draw_line
draw_line:
INK BLACK:LINE x1,y1-1 TO x1,0
RETURN
I tried an alternative with a similar but shorter routine, which works fine with Tool 64 installed.
10 graphic:sclear
20 xp=144:xr=4.71238905:xf=xr/xp
30 forzi=-64to64
40 zt=zi*2.25:zs=zt*zt
50 xl=int(sqr(20736-zs)+.5)
60 forxi=0-xltoxl
70 xt=sqr(xi*xi+zs)*xf
80 yy=(sin(xt)+sin(xt*3)*0.4)*56
90 x1=xi+zi+160:y1=110+yy-zi
100 plotx1,y1,1
110 rem ify1=0thengoto120
120 rem movex1,y1-1:drawx1,0,0: rem remplacer drawx1,y1-50,0
130 next:next
140 rem goto130
My translation was unsuccessful as well unfortunately:
10 graphic:sclear
20 xp=144:xr=4.71238905:xf=xr/xp
30 forzi=-64to64
40 zt=zi*2.25:zs=zt*zt
50 xl=int(sqr(20736-zs)+.5)
60 forxi=0-xltoxl
70 xt=sqr(xi*xi+zs)*xf
80 yy=(sin(xt)+sin(xt*3)*0.4)*56
90 x1=xi+zi+160:y1=110+yy-zi
100 plotx1,y1,1
110 rem ify1=0thengoto120
120 rem movex1,y1-1:drawx1,0,0: rem remplacer drawx1,y1-50,0
130 next:next
140 rem goto130
Do you have any idea what could be wrong?
Thanks in advance
I need some help as I don't know if I'm doing things wrong or there is an issue with the compiler.
I tried to translate into UGBASIC's syntax, but without success, the following routine written with Epyx toolkit for the Commodore 64's BASIC. It works fine with Epyx toolkit installed, and draws a 3D picture of a figure that looks like a hat.
10 RESET:MULTI:BACKGROUNDBLACK:BORDERBLACK:
20 P=160
30 Q=100:XP=144:XR=1.5*pi:YP=56:YR=1
50 ZP=64:XF=XR/XP:YF=YP/YR:ZF=XR/ZP
60 FORZI=-QTOQ-1
70 IF ZI<-ZP OR ZI>ZP GOTO150
80 ZT=ZI*XP/ZP:ZZ=ZI
90 XL=INT (.5+SQR(XP*XP-ZT*ZT))
100 FOR XI=-XLTOXL
110 XT=SQR(XI*XI+ZT*ZT)*XF:XX=XI
120 YY=(SIN(XT)+.4*SIN(3*XT))*YF
130 GOSUB 170
140 NEXT XI
150 NEXT ZI
160 GOTO 160
170 X1=XX+ZZ+P:Y1=YY-ZZ+Q
180 COLORGREEN:DOT X1,Y1
190 IF Y1=0 GOTO 220
200 COLORBLACK: LINE X1,Y1-1TOX1,0
210 RETURN
My translation is the following. I can't see what's wrong but it does not work
BITMAP ENABLE (320,200,16):CLS BLACK:
p1=160
q=100:xp=144:xr=01.5*PI:yp=56:yr=01
zp=64:xf=xr/xp:yf=yp/yr:zf=xr/zp
FOR zi=-q TO q-1
IF zi<-zp OR zi>zp THEN GOTO endloop
zt=zi*xp/zp:zz=zi
xl=INT(.5+SQR(xp^2-zt^2))
FOR xi=-xl TO xl
DEGREE
xt=(SQR(xi*xi+zt*zt)*xf)*180/PI:xx=xi
yy=(SIN (xt)+.4*SIN (3*xt))*yf
GOSUB continue
NEXT
endloop:
NEXT
loop:
GOTO loop
continue:
x1=xx+zz+p1:y1=INT(yy-zz+q)
PLOT x1,y1,GREEN
IF y1=0 THEN GOTO draw_line
draw_line:
INK BLACK:LINE x1,y1-1 TO x1,0
RETURN
I tried an alternative with a similar but shorter routine, which works fine with Tool 64 installed.
10 graphic:sclear
20 xp=144:xr=4.71238905:xf=xr/xp
30 forzi=-64to64
40 zt=zi*2.25:zs=zt*zt
50 xl=int(sqr(20736-zs)+.5)
60 forxi=0-xltoxl
70 xt=sqr(xi*xi+zs)*xf
80 yy=(sin(xt)+sin(xt*3)*0.4)*56
90 x1=xi+zi+160:y1=110+yy-zi
100 plotx1,y1,1
110 rem ify1=0thengoto120
120 rem movex1,y1-1:drawx1,0,0: rem remplacer drawx1,y1-50,0
130 next:next
140 rem goto130
My translation was unsuccessful as well unfortunately:
10 graphic:sclear
20 xp=144:xr=4.71238905:xf=xr/xp
30 forzi=-64to64
40 zt=zi*2.25:zs=zt*zt
50 xl=int(sqr(20736-zs)+.5)
60 forxi=0-xltoxl
70 xt=sqr(xi*xi+zs)*xf
80 yy=(sin(xt)+sin(xt*3)*0.4)*56
90 x1=xi+zi+160:y1=110+yy-zi
100 plotx1,y1,1
110 rem ify1=0thengoto120
120 rem movex1,y1-1:drawx1,0,0: rem remplacer drawx1,y1-50,0
130 next:next
140 rem goto130
Do you have any idea what could be wrong?
Thanks in advance