home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pcmagazi
/
1985
/
11
/
fraceldo.bas
< prev
next >
Wrap
BASIC Source File
|
1985-03-06
|
5KB
|
127 lines
10 '=========================
20 ' Fractals
30 ' generate fractal curves using recursive midpoint reduction
40 ' copyright 1984, s m estvanik
50 ' 9 JULY 84
60 '==========================
70 ' m = number of points on a line
80 ' p = x location on a line
90 ' h = height at that value of p
100 DIM MP(12),P(12,12), H(12,12), T(20,200,2) ' t( nlines, pts per line)
110 DIM STACK(40,4) 'used to simulate recursion
120 '
130 KEY OFF
140 GOSUB 1000 'get values for lines
150 RANDOMIZE(VAL(RIGHT$(TIME$,2)))
160 '
170 GOSUB 2000 'preview graph
180 ' calculate fractals for each line requested
190 FOR K=1 TO NLINES STEP 2
200 N=0
210 FOR I=1 TO MP(K)-1
220 SP =1
230 STACK(SP,1)=P(K,I):STACK(SP,2)=P(K,I+1)
240 STACK(SP,3)=H(K,I):STACK(SP,4)=H(K,I+1)
250 GOSUB 2500 'call fractal calculator
260 NEXT
270 MP(K)=N 'number of points calculated
280 LOCATE K,5:PRINT "Line";K;",";MP(K);"points calculated"
290 NEXT
300 FOR K=2 TO NLINES-1 STEP 2 'interpolate
310 LOCATE 14,2,0:PRINT "Interpolating line";K;
320 IF MP(K-1)<MP(K+1) THEN MP(K)=MP(K-1) ELSE MP(K)=MP(K+1)
330 FOR I=1 TO MP(K)
340 IF T(K-1,I,1)=0 OR T(K+1,I,1)=0 GOTO 370
350 T(K,I,1)=(T(K-1,I,1)+T(K+1,I,1))/2
360 T(K,I,2)=(T(K-1,I,2)+T(K+1,I,2))/2
370 NEXT
380 NEXT
390 GOSUB 3000 'plot lines with hidden line removal
400 END
1000 '=====Eldorado Peak================== get data for lines
1010 READ NLINES,XMAX
1020 DATA 4,25
1030 NLINES=(NLINES*2)-1 'leave room for interpolations
1040 FOR I=1 TO NLINES STEP 2:READ MP(I):NEXT '# data points for each line
1050 DATA 9,8,6,6
1060 FOR K=1 TO NLINES STEP 2:FOR I=1 TO MP(K):READ H(K,I)
1070 H(K,I)=(H(K,I)-8000)/25 'scaling
1080 NEXT :NEXT
1090 YMAX=(15000 -8000) /25
1100 ' Heights for each line, starting at farthest from view
1110 DATA 12400,12900,12300,12350,11400,11700,12325,11200,10400
1120 DATA 12000,13200,13220,12000,11200,10300,10800,10000
1130 DATA 11600,12200,10800,10000,9600,9200
1140 DATA 12100,10800,11200,10400,9400,9200
1150 'horizontal distances across each line
1160 FOR K=1 TO NLINES STEP 2:FOR I=1 TO MP(K):READ P(K,I):NEXT :NEXT
1170 DATA 7,8,10,13,15,18,20,22,25
1180 DATA 1,3,5,7,10,15,20,25
1190 DATA 1,5,10,15,20,25, 1,5,10,15,20,25
1200 CLS:INPUT "Roughness (2-10)";RUFFNESS
1210 PRINT "tolerance (min"; 2* NLINES/100;")";:INPUT ;TOLERANCE
1220 YINC=60/NLINES
1230 XINC=100/NLINES 'scaling factors for transforms
1240 RETURN
2000 '=============== preview initial landscape
2002 CLS
2010 FOR K=1 TO NLINES
2020 FOR I=1 TO MP(K)
2030 T(K,I,1)=P(K,I)
2040 T(K,I,2)=H(K,I)
2050 NEXT :NEXT
2060 GOSUB 3000
2070 RETURN
2500 '======================================= fractal calculator
2510 WHILE SP>0 'as long as there are values on the stack.....
2520 T1=STACK(SP,1):T2=STACK(SP,2)
2530 H1=STACK(SP,3):H2=STACK(SP,4)
2540 SP=SP-1 'pop
2550 IF T2-T1>TOLERANCE GOTO 2610
2560 ' required resolution achieved
2570 N=N+1
2580 IF N>200 THEN PRINT "Overflow of t buffer";:STOP
2590 IF STACK(SP,0)=1 THEN T(K,N,1)=T2:T(K,N,2)=H2 ELSE T(K,N,1)=T1:T(K,N,2)=H1
2600 GOTO 2730
2610 TM=(T1+T2)/2 'midpoint
2620 PUSH =RND-.5
2630 HM=(H1+H2)/2+RUFFNESS*(T2-T1)*PUSH
2640 ' push each of the two new segments on the stack
2650 SP=SP+1
2660 STACK(SP,1)=TM:STACK(SP,2)=T2
2670 STACK(SP,3)=HM:STACK(SP,4)=H2
2680 STACK(SP,0)=2
2690 SP=SP+1
2700 STACK(SP,1)=T1:STACK(SP,2)=TM
2710 STACK(SP,3)=H1:STACK(SP,4)=HM
2720 STACK(SP,0)=1
2730 WEND
2740 RETURN
3000 '==================================== plot lines with hidden line removal
3010 SCREEN 1,0:COLOR 1,0
3020 ' pixel scale: horizontal, vertical
3030 XS=320/XMAX:YS=200/YMAX
3040 '---------transform to tilt landscape
3050 FOR K=1 TO NLINES
3060 FOR I=1 TO MP(K)
3070 ' add to each value to move away from borders
3080 T(K,I,1)=2+T(K,I,1)*XS
3090 T(K,I,2)=1+T(K,I,2)*YS 'scale
3100 NEXT
3110 NEXT
3120 PC=0
3130 FOR K=1 TO NLINES
3140 IF MP(K)<1 GOTO 3230
3150 PC=PC+1:IF PC>3 THEN PC=0 'cycle thru possible colors
3160 N=MP(K)
3170 LINE (0,200-T(K,1,2))-(T(K,1,1),200-T(K,1,2)),PC 'connect with border
3180 FOR I=1 TO N-1
3190 LINE (T(K,I,1),200-T(K,I,2))-(T(K,I+1,1),200-T(K,I+1,2)),PC
3200 NEXT
3210 LINE (T(K,N,1),200-T(K,N,2))-(319,200-T(K,N,2)),PC
3220 PAINT (T(K,2,1),199-T(K,2,2)+5),PC,PC 'remove hidden lines
3230 NEXT
3240 X$=INPUT$(1)
3250 SCREEN 0,0:WIDTH 80
3260 RETURN