Sierpinski pentagon: Difference between revisions

(→‎{{header|Quackery}}: fast graphics)
(→‎{{header|Wren}}: Added image)
 
(7 intermediate revisions by 5 users not shown)
Line 515:
}
}</syntaxhighlight>
 
=={{header|EasyLang}}==
{{Trans|Processing}}
[https://easylang.dev/show/#cod=pZHNrsIgEIX3PMVJ3GgbsSVpdNOHacroJemFBog/by+DqHXh3Vx2w/mYc2ZwXpNHj06sIMaJBi8mY+lidPxBI5UI4zBRAlrssFaoMbqAvUIFteE3s3cjZrJxODmLK24IRhM0zamBhBQAzLHUPRqu0/l1Z2K6lEfnMdhTdmoQIs3sER3U4VCQdK6o++z/QKts9ZZvLAdjv8g818IyJ6MpPIkcu0oNeOByp02I6B9SXYjFAv4Xnpv/Ef5T/rbhLdrlPFJI8UJVh7ZD18DlT2b0Dg== Run it]
<syntaxhighlight lang="easylang">
order = 5
#
clear
linewidth 0.2
scale = 1 / (2 + cos 72 * 2)
#
proc pentagon x y side depth . .
if depth = 0
move x y
for angle = 0 step 72 to 288
x += cos angle * side
y += sin angle * side
line x y
.
else
side *= scale
dist = side + side * cos 72 * 2
for angle = 0 step 72 to 288
x += cos angle * dist
y += sin angle * dist
pentagon x y side depth - 1
.
.
.
pentagon 25 15 50 order - 1
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
{{trans|XPL0}}
<syntaxhighlight lang="vb">#define pi 4 * Atn(1)
#define yellow Rgb(255,255,0)
 
Dim As Byte orden = 5 'can also set this to 1, 2, 3, or 4
 
Dim Shared As Single deg72
deg72 = 72 * pi / 180 '72 degrees in radians
Dim As Integer HW = 640/2
Dim As Byte tam = 20
Dim As Integer radio = HW - 2*tam
Dim Shared As Single ScaleFactor
 
Sub DrawPentagon(posX As Integer, posY As Integer, largo As Single, fondo As Byte)
Dim As Byte i
Dim As Single angulo = 3 * deg72, dist
If fondo = 0 Then
Pset (posX, posY)
For i = 0 To 4
posX += Fix(largo * Cos(angulo))
posY -= Fix(largo * Sin(angulo))
Line - (posX, posY), yellow
angulo += Deg72
Next
Else
largo *= ScaleFactor
dist = largo * (1 + Cos(Deg72) * 2)
For i = 0 To 4
posX += Fix(dist * Cos(angulo))
posY -= Fix(dist * Sin(angulo))
DrawPentagon(posX, posY, largo, fondo-1)
angulo += deg72
Next
End If
End Sub
 
Screenres 640, 640, 32
 
ScaleFactor = 1 / (2 + Cos(Deg72) * 2)
Dim As Single largo
largo = radio * Sin(Pi/5) * 2
DrawPentagon (HW, 3*tam, largo, orden-1)
 
Windowtitle "Hit any key to end program"
Sleep</syntaxhighlight>
 
=={{header|Go}}==
Line 1,625 ⟶ 1,703:
(formerly Perl 6)
{{works with|rakudo|2018-10}}
[[File:Perl6 pentaflake.svg|300x300px|thumb|right|5th order pentaflake]]
<syntaxhighlight lang="raku" line>constant $sides = 5;
constant order = 5;
Line 1,646 ⟶ 1,725:
$fh.say: '</svg>';
$fh.close;</syntaxhighlight>
 
See [http://rosettacode.org/mw/images/5/57/Perl6_pentaflake.svg 5th order pentaflake]
 
=={{header|Ruby}}==
Line 2,006 ⟶ 2,083:
{{libheader|DOME}}
Black backgound and slightly different palette to Go. Also pentagons are unfilled.
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
Line 2,069 ⟶ 2,146:
var Game = SierpinskiPentagon.new(640, 640)</syntaxhighlight>
 
{{out}}
[[File:Wren-Sierpinski_pentagon.png|400px]]
 
=={{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}}
9,476

edits