home *** CD-ROM | disk | FTP | other *** search
AmigaBASIC Source Code | 1987-04-02 | 5.0 KB | 244 lines |
- CLEAR,25000
- CLEAR,40000
- DEFINT h-n
- DEF FNf1(x,y)=x*x+y*y
- DEF FNf2(x,y)=y*y-x*x
- DEF FNf3(x,y)=SQR(y*y+x*x)*2
- DEF FNf4(x,y)=SQR(y*y+x*x-2)*2
- DEF FNf5(x,y)=SQR(y*y-x*x-1)
- DEF FNf6(x,y)=SQR(1-x*x-y*y)
-
- SCREEN 1,640,400,4,4
- WINDOW 2,"",,0,1
- COLOR 10,2
-
- Make.Choice:
- CLS
- LOCATE 4,35:PRINT "3-D GRAPHICS"
- LOCATE 6,11:PRINT "A translation to the Amiga of the programs from the article"
- LOCATE 7,28:PRINT "Graphing Quadric Surfaces"
- LOCATE 8,39:PRINT "by"
- LOCATE 9,34:PRINT "George Haroney"
- LOCATE 10,25:PRINT "Byte Magazine, Dec. 1986, p. 215"
- LOCATE 12,37:PRINT "PICK ONE"
- LOCATE 14,30:PRINT "1. Parabloid"
- LOCATE 15,30:PRINT "2. Hyperbolic Parabloid"
- LOCATE 16,30:PRINT "3. Cone"
- LOCATE 17,30:PRINT "4. Hyperbloid of One Sheet"
- LOCATE 18,30:PRINT "5. Hyperbloid of Two Sheets"
- LOCATE 19,30:PRINT "6. Ellipsoid"
- LOCATE 20,30:PRINT "7. Quit"
- LOCATE 22,30:INPUT "(1-7)";choice
- IF choice=7 THEN WINDOW CLOSE 2:SCREEN CLOSE 1:END
- CLS
- pi=4*ATN(1)
- dr=pi/180
- hmin=0:hmax=631
- lmin=0:lmax=386
- hres=hmax-hmin:lres=lmax-lmin
- hc=hmin+INT(hres/2)
- IF choice=1 THEN
- lc=lmin+INT(19*lres/20)
- ELSE
- lc=lmin+INT(lres/2)
- END IF
-
- IF choice=1 THEN
- scaleh=24:scalev=4
- ELSEIF choice=2 THEN
- scaleh=30:scalev=7
- ELSEIF choice=3 THEN
- scaleh=16:scalev=8
- ELSEIF choice=4 THEN
- scaleh=16:scalev=14
- ELSEIF choice=5 THEN
- scaleh=6:scalev=6
- ELSEIF choice=6 THEN
- scaleh=100:scalev=100
- END IF
-
- c1=ATN((lc-lmin)/(hmax-hc))
- c2=pi-ATN((lc-lmin)/(hc-hmin))
- c3=pi+ATN((lmax-lc)/(hc-hmin))
- c4=2*pi-ATN((lmax-lc)/(hmax-hc))
- LOCATE 5,10:PRINT "Choices of 15,-15,90 will roughly approximate the magazine"
- LOCATE 6,10:PRINT "photos, but there are many other pictures just as interesting."
- LOCATE 10,10:PRINT "The Amiga will beep when the drawing has been completed."
- LOCATE 11,10:PRINT "Click the left mouse button to return to the main menu."
- LOCATE 15,10:INPUT "Angles for x,y,z axes ";degx,degy,degz
- CLS
- degrees=degx
- GOSUB degrees.to.radians
- sinxa=SIN(a):cosxa=COS(a)
- REM gosub draw.axis
- degrees=degy
- GOSUB degrees.to.radians
- sinya=SIN(a):cosya=COS(a)
- REM gosub draw.axis
- degrees=degz
- GOSUB degrees.to.radians
- sinza=SIN(a):cosza=COS(a)
- REM gosub draw.axis
- IF choice=1 THEN
- GOSUB Parabloid
- ELSEIF choice=2 THEN
- GOSUB Hyperbolic.Parabloid
- ELSEIF choice=3 THEN
- GOSUB Cone
- ELSEIF choice=4 THEN
- GOSUB OneSheet.Hyperbloid
- ELSEIF choice=5 THEN
- GOSUB TwoSheet.Hyperbloid
- ELSEIF choice=6 THEN
- GOSUB Ellipsoid
- END IF
-
- BEEP
- FOR dl=1 TO 30:NEXT dl
- BEEP
- WaitforClick:IF NOT MOUSE(0) THEN WaitforClick
- GOTO Make.Choice
-
- Parabloid:
- FOR ty=-6 TO 6 STEP 0.2
- kolor=13
- FOR tx=0 TO 6 STEP 0.2
- tz=FNf1(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- NEXT tx
- kolor=12
- FOR tx=-6 TO 0 STEP 0.075
- tz=FNf1(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- NEXT tx,ty
- RETURN
-
- Hyperbolic.Parabloid:
- FOR ty=-5 TO 5 STEP 0.2
- kolor=13
- FOR tx=0 TO 5 STEP 0.2
- tz=FNf2(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- NEXT tx
- kolor=12
- FOR tx=-5 TO 0 STEP 0.05
- tz=FNf2(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- NEXT tx,ty
- RETURN
-
- Cone:
- FOR ty=-6 TO 6 STEP 0.375
- kolor=13
- FOR tx=0 TO 6 STEP 0.25
- tz=FNf3(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- tz=-FNf3(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- NEXT tx
- kolor=12
- FOR tx=-6 TO 0 STEP 0.1
- tz=FNf3(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- tz=-FNf3(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- NEXT tx,ty
- RETURN
-
- OneSheet.Hyperbloid:
- FOR ty=-4 TO 4 STEP 0.25
- FOR tx=-4 TO 4 STEP 0.1
- IF tx*tx+ty*ty<2 THEN move.on :ELSE tz=FNf4(tx,ty)
- GOSUB project.and.scale
- IF tx<0 THEN kolor=12 :ELSE kolor=13
- PSET(mh,mv),kolor
- tz=-tz
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- move.on:
- NEXT tx
- NEXT ty
- RETURN
-
- TwoSheet.Hyperbloid:
- FOR ty=-20 TO 20 STEP 1
- FOR tx=-20 TO 20 STEP 0.15
- IF tx*tx+1>ty*ty THEN move.on1 :ELSE tz=FNf5(tx,ty)
- GOSUB project.and.scale
- IF tx<0 THEN kolor=12 :ELSE kolor=13
- PSET(mh,mv),kolor
- tz=-tz
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- move.on1:
- NEXT tx
- NEXT ty
- RETURN
-
- Ellipsoid:
- FOR ty=-0.99 TO 1 STEP 0.075
- kolor=13
- FOR tx=0.01 TO 1 STEP 0.015
- IF tx*tx+ty*ty>=1 THEN skip :ELSE tz=FNf6(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- tz=-tz
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- skip:
- NEXT tx
- kolor=12
- FOR tx=-1 TO 0 STEP 0.0075
- IF tx*tx+ty*ty>=1 THEN move.on2 :ELSE tz=FNf6(tx,ty)
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- tz=-tz
- GOSUB project.and.scale
- PSET(mh,mv),kolor
- move.on2:
- NEXT tx,ty
- RETURN
-
- draw.axis:
- tana=TAN(a)
- GOSUB get.endpoint
- h1=hz:l1=lz
- degrees=degrees+180:GOSUB degrees.to.radians
- GOSUB get.endpoint
- h2=hz:l2=lz
- LINE(h1,l1)-(h2,l2),kolor
- RETURN
-
- degrees.to.radians:
- WHILE degrees<0
- degrees=degrees+360
- WEND
- WHILE degrees>=360
- degrees=degrees-360
- WEND
- a=degrees*dr
- RETURN
-
- get.endpoint:
- IF a<=c1 OR a>c4 THEN hz=hmax:lz=lc-(hmax-hc)*tana:RETURN
- IF a<=c2 THEN lz=lmin:hz=hc+(lc-lmin)/tana:RETURN
- IF a<=c3 THEN hz=hmin:lz=lc+(hc-hmin)*tana:RETURN
- IF a<=c4 THEN lz=lmax:hz=hc-(lmax-lc)/tana
- RETURN
-
- project.and.scale:
- px=tx*cosxa+ty*cosya+tz*cosza
- py=tx*sinxa+ty*sinya+tz*sinza
- mh=INT(hc+px*scaleh)
- mv=INT(lc-py*scalev)
- RETURN
-
-