How to resolve the algorithm Brownian tree step by step in the Seed7 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Brownian tree step by step in the Seed7 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 Seed7 programming language
Source code in the seed7 programming language
$ include "seed7_05.s7i";
include "draw.s7i";
include "keybd.s7i";
const integer: SIZE is 300;
const integer: SCALE is 1;
const proc: genBrownianTree (in integer: fieldSize, in integer: numParticles) is func
local
var array array integer: world is 0 times 0 times 0;
var integer: px is 0;
var integer: py is 0;
var integer: dx is 0;
var integer: dy is 0;
var integer: i is 0;
var boolean: bumped is FALSE;
begin
world := fieldSize times fieldSize times 0;
world[rand(1, fieldSize)][rand(1, fieldSize)] := 1; # Set the seed
for i range 1 to numParticles do
# Set particle's initial position
px := rand(1, fieldSize);
py := rand(1, fieldSize);
bumped := FALSE;
repeat
# Randomly choose a direction
dx := rand(-1, 1);
dy := rand(-1, 1);
if dx + px < 1 or dx + px > fieldSize or dy + py < 1 or dy + py > fieldSize then
# Plop the particle into some other random location
px := rand(1, fieldSize);
py := rand(1, fieldSize);
elsif world[py + dy][px + dx] <> 0 then
# Bumped into something
world[py][px] := 1;
rect(SCALE * pred(px), SCALE * pred(py), SCALE, SCALE, white);
DRAW_FLUSH;
bumped := TRUE;
else
py +:= dy;
px +:= dx;
end if;
until bumped;
end for;
end func;
const proc: main is func
begin
screen(SIZE * SCALE, SIZE * SCALE);
KEYBOARD := GRAPH_KEYBOARD;
genBrownianTree(SIZE, 20000);
readln(KEYBOARD);
end func;
You may also check:How to resolve the algorithm Compound data type step by step in the PL/I programming language
You may also check:How to resolve the algorithm Permutations by swapping step by step in the J programming language
You may also check:How to resolve the algorithm Permutation test step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Largest proper divisor of n step by step in the jq programming language
You may also check:How to resolve the algorithm Knuth's algorithm S step by step in the F# programming language