Chaos game: Difference between revisions

Content added Content deleted
m (update for Julia 1+ restrictions on global scope variables)
Line 1,289: Line 1,289:


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
Run in REPL.
Run in REPL.
<lang julia>
<lang julia>using Luxor
using Luxor
width = 1000;
height = 1000;
Drawing(width, height, "./chaos.png");
t = Turtle(0, 0, true, 0, (0., 0., 0.));


function chaos()
x = rand(1:width);
width = 1000
y = rand(1:height);
height = 1000
Drawing(width, height, "./chaos.png")
t = Turtle(0, 0, true, 0, (0., 0., 0.))
x = rand(1:width)
y = rand(1:height)


for l in 1:30_000
for l in 1:30_000
v = rand(1:3);
v = rand(1:3)
if v == 1
if v == 1
x /= 2;
x /= 2
y /= 2;
y /= 2
elseif v == 2
elseif v == 2
x = width/2 + (width/2 - x)/2;
x = width/2 + (width/2 - x)/2
y = height - (height - y)/2;
y = height - (height - y)/2
else
else
x = width - (width - x)/2;
x = width - (width - x)/2
y = y / 2;
y = y / 2
end
Reposition(t, x, height-y)
Circle(t, 3)
end
end
Reposition(t, x, height-y);
Circle(t, 3);
end
end


finish();
chaos()
finish()
preview()
preview()
</lang>
</lang>