Thursday, October 13, 2022

Brownian Tree in BASIC

Brownian Tree

Random values are chosen for X,Y position of new pixels, but the are only set if they are next to existing pixels.  If not the position is randomly moved til it's next to a pixel
This is really slow due to so many random numbers not being near an existing pixel. 

Limiting the random range to where they could be next to pixels should help, and I do have code to do that.  I'll post that once it's tested.




0 POKE 65497,0:PMODE4,1:PCLS0:COLOR1:SCREEN1,1

REM GET BASIC TOPRAM POINTER, SUBTRACT SIZE OF USER CODE
1 AD=PEEK(116)*256+PEEK(117)-24

REM RESERVE MEMORY FOR USR CODE
2 CLEAR 100,AD

REM VARIABLES ERASED BY CLEAR, SO REDO AD, POKE USR CODE INTO RAM
3 AD=PEEK(116)*256+PEEK(117):FOR I=0 TO 23:READ B$:A=VAL("&H"+B$):POKE AD+I,A:NEXT

REM DEFINE USR ROUTINES
4 DEFUSR0=AD:DEFUSR1=AD+12

REM ENABLE 6309 NATIVE MODE
5 A=USR0(0)

10 L=1:K=254:M=174:N=3:O=2:S=0:T=255:U=175:NP=10000:PSET(128,88)

40 FOR I=L TO NP

50 X=RND(K):Y=RND(M)

60 IF ((PPOINT(X+L,Y+L) + PPOINT(X,Y+L) + PPOINT(X+L,Y) + PPOINT(X-L,Y-L) + PPOINT(X-L,Y) + PPOINT(X,Y-L))<>0) THEN PSET(X,Y):NEXT I:GOTO100

70 X=X+RND(N)-O:Y=Y+RND(N)-O

80 IF X<L OR X>K OR Y<L OR Y>M THEN 50
90 GOTO 60
100 A=USR1(0)
110 GOTO110


11000 DATA CC,FF,FF,10,4F,5D,26,03,11,3D,01,39,CC,FF,FF,10,4F,5D,26,03,11,3D,00,39



If you aren't sure if it's doing anything, you can add the following line, but it will run even slower:

65 PSET(X,Y):PRESET(X,Y)

1 comment:

  1. The original code was from the Spectrum, and I think they reserved the bottom line for text. Here are new coordinates so the entire vertical screen can be filled:
    10 L=1:K=254:M=190:N=3:O=2:S=0:T=255:U=175:NP=10000:PSET(128,95)


    This will create additional points to start plotting from the screen edges:
    11 PSET(128,190):PSET(128,1):PSET(1,95):PSET(254,95)

    ReplyDelete