Brownian tree: Difference between revisions
Content added Content deleted
m (→{{header|Uiua}}: improved algorithm) |
(→{{header|Uiua}}: updated description and comments) |
||
Line 5,422: | Line 5,422: | ||
=={{header|Uiua}}== |
=={{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.) |
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]] |
[[File:UiuaBrownianTree.png|thumb]] Sample with higher values than provided code. |
||
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"> |
<syntaxhighlight lang="Uiua"> |
||
Line 5,432: | Line 5,432: | ||
RandInt ← ⌊×⚂ |
RandInt ← ⌊×⚂ |
||
RandPoint ← ([⍥(RandInt S)2]) |
RandPoint ← ([⍥(RandInt S)2]) |
||
# Update the pair to be a new adjacent [[Here] [Last]] |
# Update the pair to be a new adjacent [[Here] [Last]] |
||
Move ← ⊟∵(-1+⌊RandInt 3).⊢ |
Move ← ⊟∵(-1+⌊RandInt 3).⊢ |
||
Line 5,440: | Line 5,440: | ||
# Find next adjacent position, or new seed if out of bounds. |
# Find next adjacent position, or new seed if out of bounds. |
||
Next ← ⟨SeedPair ◌|∘⟩:⟜(In ⊢)Move |
Next ← ⟨SeedPair ◌|∘⟩:⟜(In ⊢)Move |
||
# |
# Start from a new Seed Pair and move until you hit the tree. Add the prior pos to the tree. |
||
JoinTree ← ⍜⊡(+1)◌°⊟⍢Next (=0⊡⊢) SeedPair |
JoinTree ← ⍜⊡(+1)◌°⊟⍢Next (=0⊡⊢) SeedPair |
||
# Do it multiple times. |
# Do it multiple times. |