Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Brownian-tree/Seed7/brownian-tree.seed7
Normal file
53
Task/Brownian-tree/Seed7/brownian-tree.seed7
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
$ 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue