3D Fractals

Authors

Ted Knyszek

Publication

Publication Details

Issue: 17

Date

 

Pages

20-21
See all articles from T-S Horizons n17

Program to generate fractal landscapes.

5 REM Fractals
6 REM T. A. Knyszek
7 REM T-S Horizons n17 p19
10 REM Converted from Apple II to TS-2068 by Ted Knyszek
15 BORDER 1: PAPER 5: INK 0: PRINT: CLS
20 DIM D(65,33)
30 INPUT "NUMBER OF LEVELS (1-6)";LE
40 LET DS=2^LE+1
50 LET MX=DS-1: LET MY=MX/2: LET RH=PI/6: LET VT=-PI/5
51 LET RC=COS (RH): LET RS=SIN(RH)
52 LET VC=COS(VT): LET VS=SIN(VT)
60 FOR N=1 TO LE: LET L=10000/1.8^N
70 PRINT #1;AT 0,0;"WORKING ON LEVEL ";N
80 LET IB=MX/2^N:LET SK=IB*2
90 GO SUB 150: REM ASSIGN HEIGHTS ALONG X IN ARRAY
100 GO SUB 220: REM ASSIGN HEIGHTS ALONG Y IN ARRAY
110 GO SUB 290: REM ASSIGN HEIGHTS ALONG DIAG IN ARRAY
120 NEXT N
130 GO TO 640
140 REM HEIGHTS ALONG X
150 FOR T=0 TO MX-1 STEP SK
160 FOR K=IB+T TO MX STEP SK
170 LET I=K-IB: LET J=T: GO SUB 370: LET D1=D: LET I=K+IB: GO SUB 370: LET D2=D
180 LET D=(D1+D2)/2+(RND-.5)*L/2: LET I=K: LET J=T: GO SUB 420
190 NEXT K
200 NEXT T: RETURN
210 REM HEIGHTS ALONG X
220 FOR K=MX TO 1 STEP -SK
230 FOR T=IB TO K STEP SK
240 LET I=K: LET J=T+IB: GO SUB 370: LET D1=D: LET J=T-IB: GO SUB 370: LET D2=D
250 LET D=(D1+D2)/2+(RND-.5)*L/2: LET I=K: LET J=T: GO SUB 420
260 NEXT T
270 NEXT K: RETURN
280 REM HEIGHTS ALONG DIAG
290 FOR K=0 TO MX-1 STEP SK
300 FOR T=IB TO MX-K STEP SK
310 LET I=K+T-IB: LET J=T-IB: GO SUB 370: LET D1=D
320 LET I=K+T+IB: LET J=T+IB: GO SUB 370: LET D2=D
330 LET I=K+T: LET J=T: LET D=(D1+D2)/2+(RND-.5)*L/2: GO SUB 420
340 NEXT T
350 NEXT K: RETURN
360 REM RETURN DATA FROM ARRAY
370 IF J>MY THEN GO TO 390
380 LET BY=J: LET BX=I: GO TO 400
390 LET BY=MX+1-J: LET BX=MX-I
400 LET D=D(BX+1,BY+1): RETURN
410 REM PUT DATA IN ARRAY
420 IF J>MY THEN GO TO 440
430 LET BY=J: LET BX=I: GO TO 450
440 LET BY=MX+1-J: LET BX=MX-I
450 LET D(BX+1,BY+1)=D: RETURN
460 REM PUT IN SEA LEVEL HERE
470 IF XO<>-999 THEN GO TO 500
480 IF ZZ<0 THEN GO SUB 1070: LET Z2=ZZ: LET ZZ=0: GO TO 620
490 GO SUB 1090: GO TO 610
500 IF Z2>0 AND ZZ>0 THEN GO TO 610
510 IF Z2<0 AND ZZ<0 THEN LET Z2=ZZ: LET ZZ=0: GO TO 620
520 LET W3=ZZ/(ZZ-Z2): LET X3=(X2-XX)*W3+XX: LET Y3=(Y2-YY)*W3+YY: LET Z3=0
530 LET ZT=ZZ: LET YT=YY: LET XT=XX
540 IF ZZ>0 THEN GO TO 590
550 REM GOING INTO WATER
560 LET ZZ=Z3: LET YY=Y3: LET XX=X3: GO SUB 950
570 GO SUB 1070: LET ZZ=0: LET YY=YT: LET XX=XT: LET Z2=ZT: GO TO 620
580 REM COMING OUT OF WATER
590 LET ZZ=Z3: LET YY=Y3: LET XX=X3: GO SUB 950
600 GO SUB 1090: LET ZZ=ZT: LET YY=YT: LET XX=XT
610 LET Z2=ZZ
620 LET X2=XX: LET Y2=YY: RETURN
630 REM DISPLAY HERE
640 GO SUB 1110: REM SET UP PLOTTING DEVICE ON SCREEN
650 LET XS=.04: LET YS=.04: LET ZS=.04: REM SCALING FACTORS
660 FOR I=0 TO MX: LET XO=-999: FOR J=0 TO I
670 GO SUB 370: LET ZZ=D: LET YY=J/MX*10000: LET XX=I/MX*10000-YY/2
680 GO SUB 940: NEXT J: NEXT I
690 FOR J=0 TO MX: LET XO=-999: FOR I=J TO MX
700 GO SUB 370: LET ZZ=D: LET YY=J/MX*10000: LET XX=I/MX*10000-YY/2
710 GO SUB 940: NEXT I: NEXT J
720 FOR G=0 TO MX: LET XO=-999: FOR H=0 TO MX-G
730 LET I=G+H: LET J=H: GO SUB 370: LET ZZ=D: LET YY=J/MX*10000
740 LET XX=I/MX*10000-YY/2: GO SUB 940: NEXT H: NEXT G
750 GO TO 1130 :REM
760 REM
770 LET OX=XX
780 LET XX=XX*RC-YY*RS
790 LET YY=OX*RS+YY*RC
800 RETURN
850 REM
860 LET OX=XX
870 LET XX=VC*XX-VS*ZZ
880 LET ZZ=VS*OX+VC*ZZ
890 RETURN
930 REM MOVE OR PLOT
940 GO SUB 470
950 LET XX=XX*XS: LET YY=YY*YS: LET ZZ=ZZ*ZS
960 GO SUB 770
970 GO SUB 860
990 LET XP=INT(YY)+1: LET YP=INT(ZZ)
1000 GO SUB 1030
1010 RETURN
1020 REM
1030 LET XP=XP*0.55+5: LET YP=175-(24-0.7*YP)
1040 IF XO=-999 OR F1=1 THEN LET X8=XP: LET Y8=YP: LET XO=XP
1045 IF Y8>174 OR Y8<0 OR YP>174 OR YP<0 THEN RETURN
1050 PLOT X8,Y8: DRAW (XP-X8),(YP-Y8): LET X8=XP: LET Y8=YP: RETURN
1060 REM
1070 LET F1=1: RETURN
1080 REM
1090 LET F1=0: RETURN
1110 RETURN
1150 STOP

Products

 

Downloadable Media

Scroll to Top