Brownian tree: Difference between revisions

→‎{{header|Uiua}}: updated description and comments
m (→‎{{header|Uiua}}: improved algorithm)
(→‎{{header|Uiua}}: updated description and comments)
Line 5,422:
=={{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]] 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">
Line 5,432:
 
RandInt ← ⌊×⚂
RandPoint ← ([⍥(RandInt S)2]) # [[Here] [Last pos]]
# Update the pair to be a new adjacent [[Here] [Last]]
Move ← ⊟∵(-1+⌊RandInt 3).⊢
Line 5,440:
# Find next adjacent position, or new seed if out of bounds.
Next ← ⟨SeedPair ◌|∘⟩:⟜(In ⊢)Move
# KeepStart movingfrom a new Seed Pair and move until you hit the tree. Add the prior pos to the tree.
JoinTree ← ⍜⊡(+1)◌°⊟⍢Next (=0⊡⊢) SeedPair
# Do it multiple times.
62

edits