Chaos game: Difference between revisions
→{{header|Fōrmulæ}}
(17 intermediate revisions by 10 users not shown) | |||
Line 193:
mid ancho=0, Let( mid ancho:= Div(ancho,2))
Cls
i=LIMITE
Void(pixeles)
Loop
Set(
--i
Back if (i) is not zero
Canvas-term
Cls
i=1
Iterator(++i, Leq(i,LIMITE), Colorfore([i,3]Get(pixeles)), \
Pause
End
Subrutines
EQ1:
Let(x := Div(x, 2))
Let(y := Div(y, 2))
Let(color:=9), Return
EQ2:
Let(x := Add( mid ancho, Div(Sub(mid ancho, x), 2) ) )
Let(y := Sub( alto, Div( Sub(alto, y), 2 )))
Let(color:=10), Return
EQ3:
Let(x := Sub(ancho, Div( Sub(ancho, x), 2)))
Let(y := Div(y, 2))
Let(color:=4), Return
</syntaxhighlight>
{{out}}
Line 245 ⟶ 249:
150 PSET X,Y,V
160 NEXT I</syntaxhighlight>
==={{header|Applesoft BASIC}}===
Adapted from the code given above.
Line 266 ⟶ 271:
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">#Chaos game
ancho = 500 : alto = 300
Line 298 ⟶ 302:
Refresh
ImgSave "chaos_game.jpg", "jpg"
End</syntaxhighlight>
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
<syntaxhighlight lang="qbasic">100 REM Chaos game
110 CLS
120 SCREEN 7 '320x200 EGA Color
130 X = INT(RND(1) * 200)
140 Y = INT(RND(1) * 173)
150 FOR I=1 TO 20000
160 V = INT(RND(1) * 3) + 1
170 ON V GOTO 180,210,240
180 X = X/2
190 Y = Y/2
200 GOTO 260
210 X = 100 + (100-X)/2
220 Y = 173 - (173-Y)/2
230 GOTO 260
240 X = 200 - (200-X)/2
250 Y = Y/2
260 PSET(X,Y),V
270 NEXT I
280 END</syntaxhighlight>
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "ChaosGam.bas"
110 RANDOMIZE
120 GRAPHICS HIRES 4
130 LET X=RND(800):LET Y=RND(600)
140 FOR I=1 TO 20000
150 LET VERTEX=RND(3)
160 SELECT CASE VERTEX
170 CASE 0
180 LET X=X/2
190 LET Y=Y/2
200 CASE 1
210 LET X=400+(400-X)/2
220 LET Y=600-(600-Y)/2
230 CASE 2
240 LET X=800-(800-X)/2
250 LET Y=Y/2
260 END SELECT
270 SET INK VERTEX+1
280 PLOT X,Y
290 NEXT</syntaxhighlight>
==={{header|Locomotive Basic}}===
Line 319 ⟶ 367:
150 plot x,y,v
160 next i</syntaxhighlight>
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
<syntaxhighlight lang="qbasic">100 REM Chaos game
110 CLS
120 SCREEN 2
130 X = INT(RND(1) * 256)
140 Y = INT(RND(1) * 192)
150 FOR I=1 TO 20000
160 V = INT(RND(1) * 3) + 1
170 ON V GOTO 180,220,260
180 X = X/2
190 Y = Y/2
200 V = 8 'red
210 GOTO 290
220 X = 128 + (128-X)/2
230 Y = 192 - (192-Y)/2
240 V = 3 'green
250 GOTO 290
260 X = 256 - (256-X)/2
270 Y = Y/2
280 V = 7 'blue
290 PSET(X,Y),V
300 NEXT I
310 END</syntaxhighlight>
==={{header|Sinclair ZX81 BASIC}}===
Line 765 ⟶ 838:
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=Zc1BCoMwEIXhfU7xL20FO1aKuMhJQhbFKgrVQAiS3L5MkW66GJj5eMwbwztEBhGTncfiEFoRHoI35aSenqHDm4wlPvdX2GaumjPlT+YQWbG0pKAgIgbYwjGRKbrHaUxI0+novZxP1j3xBe2pMjXZLf7CjbuqdlWFmvLTxnwA Run it]
<syntaxhighlight
color 900
x[] = [ 0 100 50 ]
y[] = [
x = randomf * 100
y = randomf * 100
for i
move x y
rect 0.3 0.3
h =
x = (x + x[h]) / 2
y = (y + y[h]) / 2
.
</syntaxhighlight>
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">; Chaos game
Line 1,098 ⟶ 1,174:
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Chaos_game}}
'''Solution'''
[[File:Fōrmulæ - Chaos game 04.png]]
'''Test case. Sierpiński triangle'''
[[File:Fōrmulæ - Chaos game 05.png]]
[[File:Fōrmulæ - Chaos game 06.png]]
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
void local fn DoIt
long w = 460, h = 400, i, x = rnd(w), y = rnd(h)
for i = 1 to 50000
select ( rnd(3)-1 )
case 1
x = w/2+(w/2-x)/2
y = h-(h-y)/2
pen ,fn ColorRed
case 2
x = w-(w-x)/2
y = y/2
pen ,fn ColorGreen
case else
x = x/2
y = y/2
pen ,fn ColorBlue
end select
line x-0.5,y-0.5,x+0.5,y+0.5
next
end fn
window 1, @"Chaos Game", (0,0,460,400)
WindowSetBackgroundColor( 1, fn ColorWhite )
fn DoIt
HandleEvents
</syntaxhighlight>
[[file:Chaos game FB.png]]
=={{header|GML}}==
Create two new objects and rename them to "Game" and "Point" respectively.
Line 1,833 ⟶ 1,948:
end
</syntaxhighlight>
=={{header|M2000 Interpreter}}==
{{trans|Locomotive Basic}}
Old style programming (GOTO, ON GOTO) inside Module. Export bitmap to Clipboard.
<syntaxhighlight lang="m2000 interpreter">
Module Chaos {
01 Read Ox as integer, Oy as Integer
02 def Screen$
05 cls 0,0 // black background, row for split screen
10 def integer x,y,i,v
20 x = 640 * rnd
30 y = 400 * rnd
40 for i=1 to 20000
50 v = rnd * 2 + 1
60 on v goto 70,100,130
70 x = x/2
80 y = y/2
90 goto 150
100 x = 320 + (320-x)/2
110 y = 400 - (400-y)/2
120 goto 150
130 x = 640 - (640-x)/2
140 y = y/2
150 pset v*2, x*twipsX+Ox,y*twipsY+Oy
160 next i
170 Move Ox, Oy
180 Copy 640*twipsX, 400*twipsY to Screen$
190 Clipboard Screen$
}
Call Chaos 3000, 3000
</syntaxhighlight>
{{output}}
[[File:Chaosgame.png|thumb]]
=={{header|Maple}}==
<syntaxhighlight lang="maple">chaosGame := proc(numPoints)
Line 2,516 ⟶ 2,668:
</syntaxhighlight>
=={{header|Quackery}}==
<syntaxhighlight lang="Quackery"> [ $ "turtleduck.qky" loadfile ] now!
[ 2 3 circle ] is dot ( --> )
[ 1 fly
-1 4 turn
1 fly
1 4 turn ] is toxy ( n n --> )
[ swap 2dup toxy
dot
1 2 turn
toxy
1 2 turn ] is plot ( n n --> )
[ 200 random
346 random
over 346 *
over 200 * < if
[ dip [ 400 + ]
692 swap - ] ] is intriangle ( --> n n )
[ 3 random
[ table
[ 2 /
dip [ 2 / ] ]
[ 2 /
dip [ 800 + 2 / ] ]
[ 692 + 2 /
dip [ 400 + 2 / ] ] ]
do ] is tovertex ( n n --> )
turtle
0 frames
-400 1 fly
1 4 turn
340 1 fly
-1 4 turn
intriangle
10000 times
[ i^ 100 mod 0= if frame
2dup plot
tovertex ]
2drop
1 frames</syntaxhighlight>
{{out}}
[[File:Quackery chaos game.png|thumb|center]]
=={{header|R}}==
Note: Find plotmat() here on RosettaCode Wiki.
Line 3,282 ⟶ 3,487:
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}}
Line 3,287 ⟶ 3,519:
{{libheader|Wren-dynamic}}
{{libheader|Wren-seq}}
<syntaxhighlight lang="
import "graphics" for Canvas, Color
import "math" for Point
Line 3,349 ⟶ 3,581:
var Game = ChaosGame.new(640, 640)</syntaxhighlight>
=={{header|X86 Assembly}}==
Sixty bytes handles it.
|