Archimedean spiral: Difference between revisions

Content added Content deleted
(Dialects of BASIC moved to the BASIC section.)
Line 382: Line 382:


=={{header|BASIC}}==
=={{header|BASIC}}==


==={{header|AmigaBASIC}}===
==={{header|AmigaBASIC}}===
{{trans|Locomotive Basic}}
{{trans|Locomotive Basic}}
Line 432: Line 430:
i = 1 : t = 0 : xn = 0 : yn = 0 # Initial values
i = 1 : t = 0 : xn = 0 : yn = 0 # Initial values
iter = 150 : q = 30
iter = 150 : q = 30



line x,0,x,height
line x,0,x,height
Line 448: Line 445:
print i + chr(9) + int(x) + chr(9) + int(y) + chr(9) + int(t) # chr(9) = TAB
print i + chr(9) + int(x) + chr(9) + int(y) + chr(9) + int(t) # chr(9) = TAB
i += 1
i += 1

end while
end while


imgsave "spiral-Basic-256.png", "PNG"
imgsave "spiral-Basic-256.png", "PNG"
</syntaxhighlight>
</syntaxhighlight>





==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
Line 495: Line 488:
PSet(halfscrn + x, halfscrn - y), RGB(255, 255, 255)
PSet(halfscrn + x, halfscrn - y), RGB(255, 255, 255)
Next
Next



' empty keyboard buffer
' empty keyboard buffer
Line 502: Line 494:
Sleep
Sleep
End</syntaxhighlight>
End</syntaxhighlight>

==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">
_maxPoints = 190

void local fn DoIt
window 1, @"Archimedean Spiral", (0,0,500,500)
WindowSetBackgroundColor( 1, fn ColorBlack )
pen 3, fn ColorRed
float x, y, angle
long i, a = 10, b = 10, x1 = 250, y1 = 250
for i = 0 to _maxPoints - 1
angle = 0.1 * i
x = (a + b * angle) * cos(angle) + 250
y = (a + b * angle) * sin(angle) + 250
line x1,y1 to x,y
x1 = x : y1 = y
next
end fn

fn DoIt

HandleEvents
</syntaxhighlight>
{{output}}
[[File:ArchimedeanSpiralFB.png]]


==={{header|GW-BASIC}}===
==={{header|GW-BASIC}}===
Line 534: Line 553:
60 next
60 next
70 while inkey$="":wend</syntaxhighlight>
70 while inkey$="":wend</syntaxhighlight>

==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">#MAXLOOP = 7*360
#XCENTER = 640/2
#YCENTER = 480/2
#SCALAR = 200

If OpenWindow(0, 100, 200, 640, 480, "Archimedean spiral")
If CreateImage(0, 640, 480,24,RGB(255,255,255))
If StartDrawing(ImageOutput(0))
i.f=0.0
While i<=#MAXLOOP
x.f=#XCENTER+Cos(Radian(i))*#SCALAR*i/#MAXLOOP
y.f=#YCENTER+Sin(Radian(i))*#SCALAR*i/#MAXLOOP
Plot(x,y,RGB(50,50,50))
i+0.05
Wend
StopDrawing()
EndIf
EndIf
ImageGadget(0, 0, 0, 0, 0, ImageID(0))
Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
EndIf
End</syntaxhighlight>


==={{header|Run BASIC}}===
==={{header|Run BASIC}}===
Line 589: Line 632:
{{out}}
{{out}}
Screenshot [http://edmundgriffiths.com/zx81archspiral.jpg here].
Screenshot [http://edmundgriffiths.com/zx81archspiral.jpg here].

==={{header|VBA}}===
<syntaxhighlight lang="vb">Private Sub plot_coordinate_pairs(x As Variant, y As Variant)
Dim chrt As Chart
Set chrt = ActiveSheet.Shapes.AddChart.Chart
With chrt
.ChartType = xlXYScatter
.HasLegend = False
.SeriesCollection.NewSeries
.SeriesCollection.Item(1).XValues = x
.SeriesCollection.Item(1).Values = y
End With
End Sub
Public Sub main()
Dim x(1000) As Single, y(1000) As Single
a = 1
b = 9
For i = 0 To 1000
theta = i * WorksheetFunction.Pi() / 60
r = a + b * theta
x(i) = r * Cos(theta)
y(i) = r * Sin(theta)
Next i
plot_coordinate_pairs x, y
End Sub</syntaxhighlight>

==={{header|Yabasic}}===
{{trans|Sinclair_ZX81_BASIC}}
<syntaxhighlight lang="yabasic">5 OPEN WINDOW 320, 200 : WINDOW ORIGIN "CC"
10 LET A=1.5
20 LET B=0.7
30 FOR T=0 TO 30*PI STEP 0.05
40 LET R=A+B*T
50 LINE TO R*COS(T),R*SIN(T)
60 NEXT T</syntaxhighlight>


=={{header|BQN}}==
=={{header|BQN}}==
Line 598: Line 676:


[https://mlochbaum.github.io/BQN/try.html#code=eyjigKJtYXRoLlNpbiDigKJQbG904peLKOKKosOX4oaV4oiY4omgKSDigKJtYXRoLkNvcykgLSgyw5fPgCkgw5cg8J2VqeKliijihpXDty3in5wxKTEwMH0yMDA= Try it out!]
[https://mlochbaum.github.io/BQN/try.html#code=eyjigKJtYXRoLlNpbiDigKJQbG904peLKOKKosOX4oaV4oiY4omgKSDigKJtYXRoLkNvcykgLSgyw5fPgCkgw5cg8J2VqeKliijihpXDty3in5wxKTEwMH0yMDA= Try it out!]




=={{header|C}}==
=={{header|C}}==
Line 1,009: Line 1,085:


Output is [http://funwithsoftware.org/images/2016-SpiralFrege.png here] due to [[User talk:Short Circuit#Is file uploading blocked forever?|Is file uploading blocked forever?]]
Output is [http://funwithsoftware.org/images/2016-SpiralFrege.png here] due to [[User talk:Short Circuit#Is file uploading blocked forever?|Is file uploading blocked forever?]]

=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_maxPoints = 190

void local fn DoIt
window 1, @"Archimedean Spiral", (0,0,500,500)
WindowSetBackgroundColor( 1, fn ColorBlack )
pen 3, fn ColorRed
float x, y, angle
long i, a = 10, b = 10, x1 = 250, y1 = 250
for i = 0 to _maxPoints - 1
angle = 0.1 * i
x = (a + b * angle) * cos(angle) + 250
y = (a + b * angle) * sin(angle) + 250
line x1,y1 to x,y
x1 = x : y1 = y
next
end fn

fn DoIt

HandleEvents
</syntaxhighlight>

{{output}}
[[File:ArchimedeanSpiralFB.png]]


=={{header|Go}}==
=={{header|Go}}==
Line 1,887: Line 1,935:
background(255)
background(255)
theta = 0</syntaxhighlight>
theta = 0</syntaxhighlight>

=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">#MAXLOOP = 7*360
#XCENTER = 640/2
#YCENTER = 480/2
#SCALAR = 200

If OpenWindow(0, 100, 200, 640, 480, "Archimedean spiral")
If CreateImage(0, 640, 480,24,RGB(255,255,255))
If StartDrawing(ImageOutput(0))
i.f=0.0
While i<=#MAXLOOP
x.f=#XCENTER+Cos(Radian(i))*#SCALAR*i/#MAXLOOP
y.f=#YCENTER+Sin(Radian(i))*#SCALAR*i/#MAXLOOP
Plot(x,y,RGB(50,50,50))
i+0.05
Wend
StopDrawing()
EndIf
EndIf
ImageGadget(0, 0, 0, 0, 0, ImageID(0))
Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
EndIf
End</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
Line 1,928: Line 1,952:


=={{header|Quackery}}==
=={{header|Quackery}}==

<syntaxhighlight lang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
<syntaxhighlight lang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
turtle
turtle
Line 2,674: Line 2,697:
draw
draw
vwait forever ;# go into event loop until window is closed</syntaxhighlight>
vwait forever ;# go into event loop until window is closed</syntaxhighlight>

=={{header|VBA}}==
<syntaxhighlight lang="vb">Private Sub plot_coordinate_pairs(x As Variant, y As Variant)
Dim chrt As Chart
Set chrt = ActiveSheet.Shapes.AddChart.Chart
With chrt
.ChartType = xlXYScatter
.HasLegend = False
.SeriesCollection.NewSeries
.SeriesCollection.Item(1).XValues = x
.SeriesCollection.Item(1).Values = y
End With
End Sub
Public Sub main()
Dim x(1000) As Single, y(1000) As Single
a = 1
b = 9
For i = 0 To 1000
theta = i * WorksheetFunction.Pi() / 60
r = a + b * theta
x(i) = r * Cos(theta)
y(i) = r * Sin(theta)
Next i
plot_coordinate_pairs x, y
End Sub</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 2,744: Line 2,742:
until T >= 314.159; \50 revs
until T >= 314.159; \50 revs
]</syntaxhighlight>
]</syntaxhighlight>

=={{header|Yabasic}}==
{{trans|Sinclair_ZX81_BASIC}}
<syntaxhighlight lang="yabasic">5 OPEN WINDOW 320, 200 : WINDOW ORIGIN "CC"
10 LET A=1.5
20 LET B=0.7
30 FOR T=0 TO 30*PI STEP 0.05
40 LET R=A+B*T
50 LINE TO R*COS(T),R*SIN(T)
60 NEXT T</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==