Chaos game: Difference between revisions
→{{header|Fōrmulæ}}
imported>Lacika7 No edit summary |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 838:
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=Zc1BCoMwEIXhfU7xL20FO1aKuMhJQhbFKgrVQAiS3L5MkW66GJj5eMwbwztEBhGTncfiEFoRHoI35aSenqHDm4wlPvdX2GaumjPlT+YQWbG0pKAgIgbYwjGRKbrHaUxI0+novZxP1j3xBe2pMjXZLf7CjbuqdlWFmvLTxnwA Run it]
<syntaxhighlight
color 900
x[] = [ 0 100 50 ]
Line 847:
y = randomf * 100
for i = 1 to 100000
move x y
rect 0.3 0.3
h =
x = (x + x[h]) / 2
y = (y + y[h]) / 2
.
</syntaxhighlight>
Line 1,175:
{{FormulaeEntry|page=https://formulae.org/?script=examples/Chaos_game}}
'''Solution'''
When using n points equally spaced over a circle we get a [https://en.wikipedia.org/wiki/N-flake Sierpiński n-gon]. However, the proportion (1/2 for a triangle) is different according to the following formula:
[[File:Fōrmulæ - Chaos game 01.png]]
[[File:Fōrmulæ - Chaos game 02.png]]
[[File:Fōrmulæ - Chaos game 03.png]]
The program is:
[[File:Fōrmulæ - Chaos game 04.png]]
'''Test cases'''
[[File:Fōrmulæ - Chaos game 05.png]]
[[File:Fōrmulæ - Chaos game 06.png]]
Notice that the Sierpiński's 4-gon is NOT the [https://en.wikipedia.org/wiki/Sierpi%C5%84ski_carpet Sierpiński carpet], it is a solid square
=={{header|FutureBasic}}==
Line 3,477 ⟶ 3,499:
XXX
</pre>
=={{header|Uiua}}==
<syntaxhighlight lang="Uiua">
Dim ← 500
Points ← [[50 ⌊÷2Dim] [-50Dim 50] [-50Dim -50Dim]]
# Uncomment to try different square or pentagonal references.
# Points ← [[50 50] [-50Dim 50] [50 -50Dim][-50Dim -50Dim]]
# Points ← [[50 ⌊÷2Dim] [⌊×0.4Dim 50] [⌊×0.4Dim -50Dim] [-50Dim 120] [-50Dim -120Dim]]
Colours ← [[1 0 0] [0 1 0] [0 0 1] [1 1 0] [1 0 1] [0 1 1]]
Rand ← ⌊×⚂
↯Dim_Dim_3 0
∧(⍜(⊡|[1 1 1]◌))Points
⊟Rand Dim Rand Dim
⍥(
Rand⧻Points
# Set next point and colour based on target.
⊃(⌊÷2+⊡:Points|⊙◌⊡:Colours)
⟜⍜⊡◌⊙:
)10000
◌
# Uncomment to save image.
# &fwa "UiuaChaosGameSerpinski.png" &ime "png"
</syntaxhighlight>
{{out}}
[[File:UiuaChaosGameSerpinski.png|thumb|center|Render using colours associated with each target point.]]
=={{header|Wren}}==
{{trans|Kotlin}}
|