RosettaCodeData/Task/Chaos-game/Maple/chaos-game.maple
2023-07-01 13:44:08 -04:00

18 lines
649 B
Text

chaosGame := proc(numPoints)
local points, i;
randomize();
use geometry in
RegularPolygon(triSideways, 3, point(cent, [0, 0]), 1);
rotation(tri, triSideways, Pi/2, counterclockwise);
randpoint(currentP, -1/2*sqrt(3)..1/2*sqrt(3), -1/2..1/2);
points := [coordinates(currentP)];
for i to numPoints do
midpoint(mid, currentP, parse(cat("rotate_triSideways_", rand(1..3)(), "_tri")));
points := [op(points), coordinates(mid)];
point(currentP, coordinates(mid));
end do:
end use;
use plottools in
plots:-display( seq([plots:-display([seq(point(points[i]), i = 1..j)])], j = 1..numelems(points) ), insequence=true);
end use;
end proc: