Sierpinski pentagon: Difference between revisions

Added XPL0 example.
(→‎{{header|Quackery}}: fast graphics)
(Added XPL0 example.)
Line 2,069:
var Game = SierpinskiPentagon.new(640, 640)</syntaxhighlight>
 
=={{header|XPL0}}==
{{trans|Wren}}
[[File:SierXPL0.gif|200px|thumb|right]]
<syntaxhighlight lang "XPL0">def Order = 5; \can also set this to 1, 2, 3, or 4
def Width=640, Height=640;
def Pi = 3.14159265358979323846;
def Deg72 = 72.*Pi/180.; \72 degrees in radians
def HW = Width/2;
def Margin = 20;
def Radius = HW - 2*Margin;
real ScaleFactor;
int ColorIndex;
 
proc DrawPentagon(X, Y, Side, Depth);
real X, Y, Side; int Depth;
real Angle, Dist;
int I;
[Angle:= 3. * Deg72;
if Depth = 0 then
[Move(fix(X), fix(Y));
for I:= 0 to 4 do
[X:= X + Cos(Angle) * Side;
Y:= Y - Sin(Angle) * Side;
Line(fix(X), fix(Y), ColorIndex+9);
Angle:= Angle + Deg72;
];
ColorIndex:= ColorIndex+1;
if ColorIndex >= 5 then ColorIndex:= 0;
]
else [Side:= Side * ScaleFactor;
Dist:= Side * (1. + Cos(Deg72) * 2.);
for I:= 0 to 4 do
[X:= X + Cos(Angle) * Dist;
Y:= Y - Sin(Angle) * Dist;
DrawPentagon(X, Y, Side, Depth-1);
Angle:= Angle + Deg72;
];
];
];
 
real Side;
[SetFB(Width, Height, 8);
ScaleFactor:= 1. / (2. + Cos(Deg72) * 2.);
ColorIndex:= 0;
Side:= float(Radius) * Sin(Pi/5.) * 2.;
DrawPentagon(float(HW), float(3*Margin), Side, Order-1);
]</syntaxhighlight>
=={{header|zkl}}==
{{trans|Raku}}
297

edits