Brownian tree: Difference between revisions
→{{header|Locomotive Basic}}: add screenshot
m (→{{header|Uiua}}: improved algorithm) |
(→{{header|Locomotive Basic}}: add screenshot) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 2,798:
=={{header|Locomotive Basic}}==
{{trans|ZX Spectrum Basic}}
This program is ideally run in [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic] and should finish after about 20 to 25 minutes (Chrome, desktop CPU). At normal CPC speed, it would probably take several days to run when set to 10000 particles.
<syntaxhighlight lang="locobasic">10 MODE 1:DEFINT a-z:RANDOMIZE TIME:np=10000
Line 2,815 ⟶ 2,816:
1020 y=RND*400
1030 RETURN</syntaxhighlight>
=={{header|Lua}}==
The output is stored in as a ppm-image. The source code of these output-functions is located at
Line 5,422 ⟶ 5,424:
=={{header|Uiua}}==
Uiua Pad will show well-shaped arrays as images directly. If running locally you can uncomment the final few lines to save it as a file instead. (Running local is ~10 times faster too.)
▲[[File:UiuaBrownianTree.png|thumb]]
The main move loop passes round a pair of points: here and previous position, so when we hit a set cell we can just back up one.
Sample with higher values than provided code.▼
<syntaxhighlight lang="Uiua">
Line 5,432 ⟶ 5,433:
RandInt ← ⌊×⚂
RandPoint ← ([⍥(RandInt S)2])
# Update the pair to be a new adjacent [[Here] [Last]]
Move ← ⊟∵(-1+⌊RandInt 3).⊢
Line 5,440 ⟶ 5,441:
# Find next adjacent position, or new seed if out of bounds.
Next ← ⟨SeedPair ◌|∘⟩:⟜(In ⊢)Move
#
JoinTree ← ⍜⊡(+1)◌°⊟⍢Next (=0⊡⊢) SeedPair
# Do it multiple times.
Line 5,449 ⟶ 5,450:
# &fwa "BrownianTree.png"
</syntaxhighlight>
Or if you like your code terse :-)
<syntaxhighlight lang="Uiua">
S ← 80
⍜⊡(+1)↯2⌊÷2S↯S_S0
Rp ← (⊟⍥(⌊×⚂S)2)
Sd ← ⊟.⍢(Rp◌)(=1⊡) Rp
Nx ← ⟨Sd◌|∘⟩:⟜(/××⊃(≥0)(<S)⊢)⊟∵(-1+⌊×⚂3).⊢
⍜now⍥(⍜⊡(+1)◌°⊟⍢Nx(=0⊡⊢)Sd)500
</syntaxhighlight>
{{out}}
=={{header|Visual Basic .NET}}==
|