How to resolve the algorithm Brownian tree step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Brownian tree step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
Generate and draw a Brownian Tree.
A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. Because of the lax rules governing the random nature of the particle's placement and motion, no two resulting trees are really expected to be the same, or even necessarily have the same general shape.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Brownian tree step by step in the FreeBASIC programming language
Source code in the freebasic programming language
' version 16-03-2017
' compile with: fbc -s gui
Const As ULong w = 400
Const As ULong w1 = w -1
Dim As Long x, y, lastx, lasty
Dim As Long count, max = w * w \ 4
ScreenRes w, w, 8 ' windowsize 400 * 400, 8bit
' hit any key to stop or mouseclick on close window [X]
WindowTitle "hit any key to stop and close the window"
Palette 0, 0 ' black
Palette 1, RGB( 1, 1, 1) ' almost black
Palette 2, RGB(255, 255, 255) ' white
Palette 3, RGB( 0, 255, 0) ' green
Line (0, 0) - (w1, w1), 0, BF ' make field black
Line (0, 0) - (w1, w1), 1, B ' draw border in almost black color
Randomize Timer
x = Int(Rnd * 11) - 5
y = Int(Rnd * 11) - 5
PSet(w \ 2 + x, w \ 2 + y), 3 ' place seed near center
Do
Do ' create new particle
x = Int(Rnd * w1) + 1
y = Int(Rnd * w1) + 1
Loop Until Point(x, y) = 0 ' black
PSet(x, y), 2
Do
lastx = x
lasty = y
Do
x = lastx + Int(Rnd * 3) -1
y = lasty + Int(Rnd * 3) -1
Loop Until Point(x, y) <> 1
If Point(x, y) = 3 Then
PSet(lastx, lasty), 3
Exit Do ' exit do loop and create new particle
End If
PSet(lastx, lasty), 0
PSet(x,y), 2
If Inkey <> "" Or Inkey = Chr(255) + "k" Then
End
End If
Loop
count += 1
Loop Until count > max
Beep : Sleep 5000
End
You may also check:How to resolve the algorithm Arithmetic derivative step by step in the J programming language
You may also check:How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the Rust programming language
You may also check:How to resolve the algorithm Ulam spiral (for primes) step by step in the Python programming language
You may also check:How to resolve the algorithm Detect division by zero step by step in the MAXScript programming language
You may also check:How to resolve the algorithm Wireworld step by step in the RISC-V Assembly programming language