Brownian tree: Difference between revisions

Added Uiua solution
m (Replace deprecated functions)
(Added Uiua solution)
Line 5,419:
:Pause
:RecallGDB 0</syntaxhighlight>
 
=={{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.
 
<syntaxhighlight lang="Uiua">
S ← 80
RandInt ← ⌊×⚂
RandPoint ← ([⍥(RandInt S)2]) # [[Here] [Last pos]]
# Create SxS grid, and set the centre point as seed.
↯ S_S 0
Mid ← ↯2⌊÷2S
⍜⊡(+1) Mid
# Update the pair to be a new adjacent [[Here] [Last]]
Move ← ⊟∵(-1+⌊RandInt 3).⊢
In ← /××⊃(≥0)(<S) # Is this point in bounds?
# Given a grid return a free point pair and that grid.
SeedPair ← ⊟.⍢(RandPoint ◌)(=1⊡) RandPoint
# Find next adjacent position, or new seed if out of bounds.
Next ← ⟨SeedPair ◌|∘⟩:⟜(In ⊢)Move
# Keep moving until you hit the tree. Add the prior pos to the tree.
JoinTree ← ⍜⊡(+1)◌°⊟⍢Next (=0⊡⊢) SeedPair
# Do it multiple times.
⍜now⍥JoinTree500
 
# ◌
# &ime "png"
# &fwa "BrownianTree.png"
</syntaxhighlight>
 
 
=={{header|Visual Basic .NET}}==
Windows Forms Application.
102

edits