Sierpinski curve: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
(Added FreeBasic) |
||
Line 469: | Line 469: | ||
{{FormulaeEntry|page=https://formulae.org/?script=examples/Sierpi%C5%84ski_curve}} |
{{FormulaeEntry|page=https://formulae.org/?script=examples/Sierpi%C5%84ski_curve}} |
||
=={{header|FreeBASIC}}== |
|||
{{trans|XPL0}} |
|||
<syntaxhighlight lang="vb">#define pi 4 * Atn(1) |
|||
#define yellow Rgb(255,255,0) |
|||
Dim Shared As Integer posX, posY |
|||
Dim Shared As Single direc |
|||
Sub Dibuja(largo As Integer) |
|||
posX += Fix(largo * Cos(direc)) |
|||
posY -= Fix(largo * Sin(direc)) |
|||
Line - (posX, posY), yellow |
|||
End Sub |
|||
Sub Curva(orden As Integer, angulo As Single, long1 As Single, long2 As Single) |
|||
If orden <> 0 Then |
|||
direc += angulo |
|||
Curva(orden-1, -angulo, long1, long2) |
|||
direc -= angulo |
|||
Dibuja(long1) |
|||
direc -= angulo |
|||
Curva(orden-1, -angulo, long1, long2) |
|||
direc += angulo |
|||
End If |
|||
End Sub |
|||
Screenres 640, 480, 32 |
|||
Dim As Single ang45 = pi / 4 |
|||
Dim As Byte orden = 3 |
|||
Dim As Byte tam = 20 |
|||
direc = 0 |
|||
posX = 640/4 |
|||
posY = 3*480/4 |
|||
Pset (posX, posY) |
|||
For c As Byte = 1 To 4 |
|||
Curva(orden*2, ang45, tam/Sqr(2), 5*tam/6) |
|||
direc += ang45 |
|||
Dibuja(tam/Sqr(2)) |
|||
direc += ang45 |
|||
Next |
|||
Windowtitle "Hit any key to end program" |
|||
Sleep</syntaxhighlight> |
|||
=={{header|Go}}== |
=={{header|Go}}== |