Sierpinski pentagon: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
(Added FreeBasic) |
||
Line 515: | Line 515: | ||
} |
} |
||
}</syntaxhighlight> |
}</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}}== |
=={{header|Go}}== |