Fractal Rocks

Developer(s): Blanchard Smith
Date: 1984
Type: Program
Platform(s): TS 2068
Tags: Graphics

Draws a fractal “rock” by repeated midpoint displacement, after the method in the September 1984 Scientific American. It starts with one triangle, moves the midpoint of each side by a random amount proportional to its length, joins the new points into four smaller triangles, and repeats until 1024 triangles connect 561 points. Each stage is redrawn, and the finished picture is sent to the printer with COPY.

The first DATA item in line 10 sets the roughness and the other six the corners of the starting triangle. A full run takes a little over three minutes, and every RUN gives a different rock.

Published in Syntax September 1984 (Hall of the Fractal Hackers).

Related Articles

Based on the Sep.84 Scientific American computer software issue, the first of these programs creates fractal patterns using the method described on page 156.

Image Gallery

Source Code

  10 DATA .3,80,175,255,20,0,0
  20 GO TO 90
  30 LET u=(x(k)+x(j))/2: LET v=(y(k)+y(j))/2
  40 LET r=s*(ABS (x(j)-u)+ABS (y(j)-v))
  50 LET x=INT ABS ((RND-RND)*r+u): LET y=INT ABS ((RND-RND)*r+v)
  60 IF x>255 THEN LET x=255
  70 IF y>175 THEN LET y=175
  80 PLOT x,y: LET x(i)=x: LET y(i)=y: RETURN
  90 DIM x(561): DIM y(561)
 100 READ s: FOR j=1 TO 3: READ x(j): READ y(j): NEXT j
 110 LET c=2: FOR t=1 TO 6
 120 INK 1: CLS
 130 LET a=0: FOR m=1 TO c-1
 140 FOR n=1 TO m
 150 LET i=a+n: LET j=i+m
 160 PLOT x(i),y(i): DRAW x(j)-x(i),y(j)-y(i)
 170 LET i=j+1: DRAW x(i)-x(j),y(i)-y(j)
 180 LET j=a+n: DRAW x(j)-x(i),y(j)-y(i)
 190 NEXT n: LET a=a+m: NEXT m
 200 IF t=5 THEN GO TO 9000
 210 INK 2
 220 FOR m=c TO 2 STEP -1
 230 LET b=a+a-m
 240 FOR j=a+1 TO a+m: LET i=j+j+b
 250 LET x(i)=x(j): LET y(i)=y(j)
 260 NEXT j: LET a=a-m+1: NEXT m
 270 LET c=c+c-1: LET a=1
 280 FOR m=2 TO c STEP 2
 290 FOR l=a TO a+m-1 STEP 2
 300 LET i=l+m-1: LET j=l: LET k=i+m: GO SUB 30
 310 LET i=k+1: LET j=i+1: GO SUB 30
 320 LET i=l+m: LET k=l: GO SUB 30
 330 NEXT l: LET a=j-m: NEXT m
 340 NEXT t
9000 COPY : STOP

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.