Archimedean spiral: Difference between revisions

m
Replace deprecated functions
m (Replace deprecated functions)
 
(93 intermediate revisions by 36 users not shown)
Line 1:
{{task}}
[[File:Archimedian spiral j.png|300px|right]]
 
The [[wp:Archimedean_spiral|Archimedean spiral]] is a spiral named after the Greek mathematician Archimedes.
Line 13 ⟶ 14:
;Task
Draw an Archimedean spiral.
<br/><br/>
 
=={{header|Action!}}==
Action! does not provide trigonometric functions. Therefore a simple implementation for Sin and Cos function has been provided.
<syntaxhighlight lang="action!">INT ARRAY SinTab=[
0 4 9 13 18 22 27 31 36 40 44 49 53 58 62 66 71 75 79 83
88 92 96 100 104 108 112 116 120 124 128 132 136 139 143
147 150 154 158 161 165 168 171 175 178 181 184 187 190
193 196 199 202 204 207 210 212 215 217 219 222 224 226
228 230 232 234 236 237 239 241 242 243 245 246 247 248
249 250 251 252 253 254 254 255 255 255 256 256 256 256]
 
INT FUNC Sin(INT a)
WHILE a<0 DO a==+360 OD
WHILE a>360 DO a==-360 OD
IF a<=90 THEN
RETURN (SinTab(a))
ELSEIF a<=180 THEN
RETURN (SinTab(180-a))
ELSEIF a<=270 THEN
RETURN (-SinTab(a-180))
ELSE
RETURN (-SinTab(360-a))
FI
RETURN (0)
 
INT FUNC Cos(INT a)
RETURN (Sin(a-90))
 
PROC DrawSpiral(INT x0,y0)
INT angle,radius,x,y
 
Plot(x0,y0)
FOR angle=0 TO 1800 STEP 5
DO
radius=angle/20
x=radius*Cos(angle)/256+x0
y=radius*Sin(angle)/256+y0
DrawTo(x,y)
OD
RETURN
 
PROC Main()
BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
 
Graphics(8+16)
Color=1
COLOR1=$0C
COLOR2=$02
 
DrawSpiral(160,96)
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Archimedean_spiral.png Screenshot from Atari 8-bit computer]
 
=={{header|Ada}}==
{{libheader|SDLAda}}
<langsyntaxhighlight Adalang="ada">with Ada.Numerics.Elementary_Functions;
 
with SDL.Video.Windows.Makers;
with SDL.Video.SurfacesRenderers.Makers;
with SDL.Video.Rectangles;
with SDL.Video.Pixel_Formats;
with SDL.Events.Events;
 
Line 35 ⟶ 89:
T_Last : constant := 100.0;
 
Win Window : SDL.Video.Windows.Window;
SurfaceRenderer : SDL.Video.SurfacesRenderers.SurfaceRenderer;
Event : SDL.Events.Events.Events;
 
procedure Plot (X, Y : Float) is
use SDL.C;
Point : constant SDL.Video.Rectangles.Rectangle
:= (X => Width / 2 + SDL.C.int (X),
Y => Height / 2 + SDL.C.int (Y),
Width => 2, Height => 2);
begin
Surface.Fill (Point, SDL.Video.Pixel_Formats.To_Pixel
(Format => Surface.Pixel_Format,
Red => 0, Green => 250, Blue => 0));
end Plot;
 
procedure Draw_Archimedean_Spiral is
use type SDL.C.int;
use Ada.Numerics.Elementary_Functions;
Pi : constant := Ada.Numerics.Pi;
Step : constant := 0.01002;
T : Float;
R : Float;
Line 61 ⟶ 104:
loop
R := A + B * T;
Renderer.Draw
Plot (X => R * Cos (T, Cycle => 2.0 * Pi),
(Point => Y(X => Width / 2 + SDL.C.int (R * SinCos (T, Cycle => 2.0 * Pi));,
Y => Height / 2 - SDL.C.int (R * Sin (T, 2.0 * Pi))));
exit when T >= T_Last;
T := T + Step;
Line 85 ⟶ 129:
end if;
 
SDL.Video.Windows.Makers.Create (Win => WinWindow,
Title => "Archimedean spiral",
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
Size => SDL.Positive_Sizes'(Width, Height),
Flags => 0);
SurfaceSDL.Video.Renderers.Makers.Create :=(Renderer, WinWindow.Get_Surface);
Renderer.Set_Draw_Colour ((0, 0, 0, 255));
 
SurfaceRenderer.Fill (SDL.Video.Rectangles.Rectangle' => (0, 0, Width, Height),);
Renderer.Set_Draw_Colour ((0, 220, 0, 255));
SDL.Video.Pixel_Formats.To_Pixel
(Format => Surface.Pixel_Format,
Red => 0, Green => 0, Blue => 0));
 
Draw_Archimedean_Spiral;
WinWindow.Update_Surface;
 
Wait;
WinWindow.Finalize;
SDL.Finalise;
end Archimedean_Spiral;</langsyntaxhighlight>
 
=={{header|ALGOL W}}==
{{Trans|AWK}}
This version doubles the characters horiontally to give a slightly more rounded shape.
<syntaxhighlight lang="algolw">begin % draw an Archimedian spiral %
% Translation of AWK which was a trnslation of Applesoft Basic program %
integer procedure max ( integer x, y ) ; begin if x > y then x else y end;
integer procedure min ( integer x, y ) ; begin if x < y then x else y end;
integer x_min, y_min, x_max, y_max, a, b, x, y;
string(255) array arr ( 1 :: 255 );
real h, w, m, s, t;
x_min := y_min := 9999;
x_max := y_max := 0;
h := 96;
w := h + h / 2;
a := 1;
b := 1;
m := 6 * PI;
s := .02;
t := s;
while t <= m do begin % build spiral %
real r;
r := a + b * t;
x := round(r * cos(t) + w);
y := round(r * sin(t) + h);
if x <= 0 or y <= 0 then begin end
else if x >= 280 then begin end
else if y >= 192 then begin end
else begin
arr( x )( y // 1 ) := "*";
x_min := min(x_min,x);
x_max := max(x_max,x);
y_min := min(y_min,y);
y_max := max(y_max,y);
t := t + s
end if__various_x_and_y_values__
end while__t_le_m ;
for i := x_min until x_max do begin
for j := y_min until y_max do begin
string(1) c;
c := arr( i )( j // 1 );
writeon( c, c )
end for_j ;
write()
end for_i
end.</syntaxhighlight>
{{out}}
<pre>
**************
******** ********
****** ****
**** ******
**** ****
**** ****
**** ****
**** ****************** **
**** **** ****** **
** **** **** ****
**** ** **** **
** **** **** **
** **** ** **
** ** ********** **** **
** **** **** **** ** **
** ** ** **** ** **
** ** **** ** ** **
** ** ** **** ** **
** ** ** ****** ** **
** ** ** **** **
** ** **** ** **
** ** ** **** **
** ** **** **** **
** ** ****** **** ****
** **** ************** **
** ** **
**** ** ****
** **** ****
**** **** ******
** ****** ******
** ******** ********
** **********
**
****
******
******
********
********
</pre>
 
=={{header|Amazing Hopper}}==
{{Trans|AmigaBASIC}}
[[File:Captura_de_pantalla_de_2022-10-07_22-57-32.png|200px|thumb|right]]
<syntaxhighlight lang="c">
#include <jambo.h>
 
Main
Set break
a=1.5, b=1.5, r=0, origen x=200, origen y=105
total = 0, Let ( total := Mul(20, M_PI) )
Cls
Loop for ( t=0, var 't' Is less equal to 'total', Let (t := Add (t, 0.005)) )
#( r = a + b * t )
Set 'origen x, origen y', # ( 200 + (2*r*sin(t)) ) » 'origen x', #( 105 + (r*cos(t)) ) » 'origen y',
Gosub 'Dibuja un segmento'
Next
Pause
End
 
Subrutines
 
Define (Dibuja un segmento, x1, y1, x2, y2)
dx=0, dy=0, paso=0, i=0, DX=0, DY=0
 
Sub(x2, x1), Sub (y2, y1), Move to ' dx, dy '
 
Let( paso := Get if( Greater equal ( Abs(dx) » (DX), Abs(dy)»(DY) ), DX, DY ) )
 
// incremento:
Div(dx, paso), Div(dy, paso), Move to ( dx, dy )
 
Color back (13)
// dibuja línea:
i = 0
Loop if ( Less equal (i, paso) )
Locate( y1, x1 ), Printnl( " " )
Add ( x1, dx), Add( y1, dy ), Move to ( x1, y1 )
++i
Back
Printnl("\OFF")
Return
 
</syntaxhighlight>
{{out}}
<pre>
Invocar como:
rxvt -g 500x250 -fn "xft:FantasqueSansMono-Regular:pixelsize=1" -e hopper jm/archi.jambo
</pre>
 
=={{header|APL}}==
 
'''Works in: [[Dyalog APL]]'''
 
Uses Dyalog's [https://sharpplot.com/ SharpPlot] integration, which works on all supported platforms.
 
<syntaxhighlight lang="apl"> 'InitCauseway' 'View' ⎕CY 'sharpplot'
InitCauseway ⍬ ⍝ initialise current namespace
sp←⎕NEW Causeway.SharpPlot
sp.DrawPolarChart {⍵(360|⍵)}⌽⍳720
View sp</syntaxhighlight>
 
[https://i.imgur.com/hZDqjjM.png See the plot on imgur.]
 
=={{header|AutoHotkey}}==
Requires [https://github.com/tariqporter/Gdip GDIP]
<syntaxhighlight lang="autohotkey">if !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
SysGet, MonitorPrimary, MonitorPrimary
SysGet, WA, MonitorWorkArea, %MonitorPrimary%
WAWidth := WARight-WALeft
WAHeight := WABottom-WATop
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(WAWidth, WAHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pPen := Gdip_CreatePen(0xffff0000, 3)
;--------------------------------
a := 1, b := 4, th := 0.1, step := 0.1
loop, 720
{
th += step
r := a + b * th
x1 := r * Cos(th)
y1 := r * Sin(th)
x1 += A_ScreenWidth/2
y1 += A_ScreenHeight/2
if (x2 && y2)
Gdip_DrawLine(G, pPen, x1, y1, x2, y2)
x2 := x1, y2 := y1
if GetKeyState("Esc", "P")
break
; next two lines are optional to watch it draw
; Sleep 10
; UpdateLayeredWindow(hwnd1, hdc, WALeft, WATop, WAWidth, WAHeight)
}
UpdateLayeredWindow(hwnd1, hdc, WALeft, WATop, WAWidth, WAHeight)
;--------------------------------
return
 
Exit:
Gdip_DeletePen(pPen)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
Return</syntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f ARCHIMEDEAN_SPIRAL.AWK
# converted from Applesoft BASIC
Line 142 ⟶ 389:
function max(x,y) { return((x > y) ? x : y) }
function min(x,y) { return((x < y) ? x : y) }
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 183 ⟶ 430:
*****
</pre>
 
=={{header|BASIC}}==
==={{header|AmigaBASIC}}===
{{trans|Locomotive Basic}}
<syntaxhighlight lang="amigabasic">a=1.5
b=1.5
pi=3.141592
 
PSET (320,100)
FOR t=0 TO 40*pi STEP .1
r=a+b*t
LINE -(320+2*r*SIN(t),100+r*COS(t))
NEXT</syntaxhighlight>
 
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight ApplesoftBasiclang="applesoftbasic">110 LET H = 96
120 LET W = H + H / 2
130 HGR2
Line 205 ⟶ 464:
280 HPLOT X,Y
290 NEXT
</syntaxhighlight>
</lang>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
<lang BASIC256>
# Basic-256 ver 1.1.4
# Archimedean Spiral
Line 221 ⟶ 480:
i = 1 : t = 0 : xn = 0 : yn = 0 # Initial values
iter = 150 : q = 30
 
 
line x,0,x,height
Line 237 ⟶ 495:
print i + chr(9) + int(x) + chr(9) + int(y) + chr(9) + int(t) # chr(9) = TAB
i += 1
 
end while
 
imgsave "spiral-Basic-256.png", "PNG"
</syntaxhighlight>
</lang>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
[[File:Archimedean_spiral_bbc_basic.jpeg|300px|right]]
<syntaxhighlight lang="bbcbasic"> A=320
VDU 23, 22, A+10; A+10; 8, 16, 16, 128
ORIGIN @size.x%, @size.y%
GCOL 7
FOR I=-(A - A MOD 100) TO A - A MOD 100 STEP 100
LINE I, -A, I, A : LINE -A, I, A, I
NEXT
 
MOVE 0, 0
GCOL 1
VDU 23, 23, 3|
FOR I=0 TO 5 * PI STEP .05
R=A / 16 * I
DRAW R * COS(I), R * SIN(I)
NEXT
</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="basic">
10 rem Archimedean spiral
20 graphics 0
30 graphics cls
40 a = 3 : b = 1.4
50 x0 = 320 : y0 = 200
60 graphics moveto x0,y0
70 for t = 0 to 40*pi step 0.2
80 r = a+b*t
90 x = r*cos(t)+320 : y = r*sin(t)+200
100 graphics lineto x,y
110 next t
120 end
</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
Commodore BASIC 2.0 lacks in-built graphics capability. This implementation is written for Commodore BASIC 7.0 that was built into the Commodore 128 computer. Should also work for Commodore BASIC 3.5.
<langsyntaxhighlight lang="basic">1 REM ARCHIMEDEAN SPIRAL
2 REM USING COMMODORE BASIC 7.0
3 REM OF THE COMMODORE 128
Line 262 ⟶ 553:
90 X0 = X : Y0 = Y
100 NEXT T
110 GOTO 110</langsyntaxhighlight>
 
==={{header|FreeBASIC}}===
<langsyntaxhighlight lang="freebasic">' version 16-10-2016
' compile with: fbc -s gui
 
Line 284 ⟶ 575:
PSet(halfscrn + x, halfscrn - y), RGB(255, 255, 255)
Next
 
 
' empty keyboard buffer
Line 290 ⟶ 580:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
 
==={{header|GW-BASIC}}===
<syntaxhighlight lang="gwbasic">10 A = 0
20 B = 1
30 SCREEN 1
40 FOR THETA = 0 TO 160 STEP .01
50 R = A + B*THETA
60 X = R*COS(THETA)
70 Y = R*SIN(THETA)
80 PSET (160+X, 100-Y),3
90 NEXT THETA
100 IF INKEY$="" THEN GOTO 100
110 SCREEN 2:SCREEN 0
120 END</syntaxhighlight>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 GRAPHICS LORES 2
110 OPTION ANGLE DEGREES
120 PLOT 640,360,ANGLE 90;
130 FOR I=2 TO 33.2 STEP .05
140 PLOT FORWARD I,LEFT 5;
150 NEXT</langsyntaxhighlight>
 
==={{header|Locomotive Basic}}===
{{trans|Commodore BASIC}}
<syntaxhighlight lang="locobasic">10 a=1.5:b=2
20 mode 2:rad:move 320,200
30 for t=0 to 40*pi step 0.2
40 r=a+b*t
50 draw r*sin(t)+320,r*cos(t)+200
60 next
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}}===
<langsyntaxhighlight Runlang="run BASICbasic"> 'archimedean spiral.bas
'runs in Run Basic
'Run Basic website http://www.runbasic.com
Line 327 ⟶ 665:
print "Thank you and Goodbye"
end
End</langsyntaxhighlight>
 
==={{header|QBASICQBasic}}===
<langsyntaxhighlight basiclang="qbasic">SCREEN 12
WINDOW (-2.67, -2!)-(2.67, 2!)
PI = 4 * ATN(1)
Line 341 ⟶ 679:
Y = (A + B * T) * SIN(T)
LINE -(X, Y)
NEXT</langsyntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
{{trans|Applesoft BASIC}}
Works with the unexpanded (1k RAM) ZX81. The output is quite blocky, but identifiably a spiral.
<langsyntaxhighlight lang="basic">10 LET A=1.5
20 LET B=0.7
30 FOR T=0 TO 7*PI STEP 0.05
40 LET R=A+B*T
50 PLOT R*COS T+32,R*SIN T+22
60 NEXT T</langsyntaxhighlight>
{{out}}
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}}==
The BQN online REPL supports some basic plotting functionality through <code>•Plot</code>. This is used to create a spiral plotting function:
 
<syntaxhighlight lang="bqn">{(•math.Sin •Plot○(⊢×↕∘≠) •math.Cos) -(2×π) × 𝕩⥊(↕÷-⟜1)100}</syntaxhighlight>
 
When called with argument 200, it is similar to the given example diagram.
 
[https://mlochbaum.github.io/BQN/try.html#code=eyjigKJtYXRoLlNpbiDigKJQbG904peLKOKKosOX4oaV4oiY4omgKSDigKJtYXRoLkNvcykgLSgyw5fPgCkgw5cg8J2VqeKliijihpXDty3in5wxKTEwMH0yMDA= Try it out!]
 
=={{header|C}}==
Interactive code which asks the parameters a and b as inputs, the number of cycles and the division steps. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
<lang C>
#include<graphics.h>
#include<stdio.h>
Line 390 ⟶ 772:
closegraph();
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
 
<syntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using System.Drawing.Drawing2D;
 
class Program
{
const int width = 380;
const int height = 380;
static PointF archimedeanPoint(int degrees)
{
const double a = 1;
const double b = 9;
double t = degrees * Math.PI / 180;
double r = a + b * t;
return new PointF { X = (float)(width / 2 + r * Math.Cos(t)), Y = (float)(height / 2 + r * Math.Sin(t)) };
}
 
static void Main(string[] args)
{
var bm = new Bitmap(width, height);
var g = Graphics.FromImage(bm);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillRectangle(new SolidBrush(Color.White), new Rectangle { X = 0, Y = 0, Width = width, Height = height });
var pen = new Pen(Color.OrangeRed, 1.5f);
 
var spiral = Enumerable.Range(0, 360 * 3).AsParallel().AsOrdered().Select(archimedeanPoint);
var p0 = new PointF(width / 2, height / 2);
foreach (var p1 in spiral)
{
g.DrawLine(pen, p0, p1);
p0 = p1;
}
g.Save(); // is this really necessary ?
bm.Save("archimedes-csharp.png");
Process.Start("archimedes-csharp.png"); // Launches default photo viewing app
}
}
</syntaxhighlight>
 
=={{header|C++}}==
[[File:SpiralCpp.png|200px|thumb|right]]
<langsyntaxhighlight lang="cpp">
#include <windows.h>
#include <string>
Line 505 ⟶ 930:
spiral s; s.draw( 16, 8 ); return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#Clojure}}==
{{Works with| Incanter}}
<syntaxhighlight lang="clojure">
(use '(incanter core stats charts io))
 
(defn Arquimidean-function
<lang csharp>using System;
[a b theta]
using System.Linq;
(+ a (* theta b)))
using System.Drawing;
using System.Diagnostics;
using System.Drawing.Drawing2D;
 
(defn transform-pl-xy [r theta]
class Program
(let [x (* r (sin theta))
{
y (* r (cos theta))]
const int width = 380;
[x y]))
const int height = 380;
static PointF archimedeanPoint(int degrees)
{
const double a = 1;
const double b = 9;
double t = degrees * Math.PI / 180;
double r = a + b * t;
return new PointF { X = (float)(width / 2 + r * Math.Cos(t)), Y = (float)(height / 2 + r * Math.Sin(t)) };
}
 
(defn arq-spiral [t] (transform-pl-xy (Arquimidean-function 0 7 t) t))
static void Main(string[] args)
{
var bm = new Bitmap(width, height);
var g = Graphics.FromImage(bm);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillRectangle(new SolidBrush(Color.White), new Rectangle { X = 0, Y = 0, Width = width, Height = height });
var pen = new Pen(Color.OrangeRed, 1.5f);
 
(view (parametric-plot arq-spiral 0 (* 10 Math/PI)))
var spiral = Enumerable.Range(0, 360 * 3).AsParallel().AsOrdered().Select(archimedeanPoint);
</syntaxhighlight>
var p0 = new PointF(width / 2, height / 2);
foreach (var p1 in spiral)
{
g.DrawLine(pen, p0, p1);
p0 = p1;
}
g.Save(); // is this really necessary ?
bm.Save("archimedes-csharp.png");
Process.Start("archimedes-csharp.png"); // Launches default photo viewing app
}
}
</lang>
 
Another version inspired by the Java below, showing how to interop with awt/swing to do simple graphics:
 
<syntaxhighlight lang="clojure">
(let [panel (proxy [javax.swing.JPanel] []
(paintComponent [g]
(proxy-super paintComponent g)
(.setStroke g (java.awt.BasicStroke. 2))
(.setRenderingHint g java.awt.RenderingHints/KEY_ANTIALIASING
java.awt.RenderingHints/VALUE_ANTIALIAS_ON)
(let [[a b] [0 (/ 1 Math/PI)]
[w h] [(.getWidth this) (.getHeight this)]
[cx cy] [(/ w 2.0) (/ h 2.0)]
margin 16
[rotations point-n] [3 (quot (min w h) 2)]
[ring-n line-n] [6 12]
scale (/ (- (min w h) (* 2 margin)) (* 2.0 ring-n))]
;; Grid
(.setColor g (java.awt.Color. 0xEEEEEE))
(doseq [i (range 1 (inc ring-n))]
(let [[posx posy] [(- cx (* i scale)) (- cy (* i scale))]]
(.drawOval g posx posy (* 2 i scale) (* 2 i scale))))
(dotimes [i line-n]
(let [theta (* 2 Math/PI (/ i (double line-n)))
[x y] [(+ cx (* scale ring-n (Math/cos theta)))
(+ cy (* scale ring-n (Math/sin theta)))]]
(.drawLine g cx cy x y)))
;; Spiral
(.setColor g (java.awt.Color. 0x202020))
(loop [i 0 [x y] [(+ cx (* a scale)) cy]]
(let [p (/ (inc i) (double point-n))
theta (* rotations 2 Math/PI p)
r (* scale (+ a (* b theta)))
[x1 y1] [(+ cx (* r (Math/cos theta)))
(- cy (* r (Math/sin theta)))]]
(.drawLine g x y x1 y1)
(when (< i (dec point-n)) (recur (inc i) [x1 y1])))))))]
(doto (javax.swing.JFrame.)
(.add (doto panel
(.setPreferredSize (java.awt.Dimension. 640 640))
(.setBackground java.awt.Color/white))
java.awt.BorderLayout/CENTER)
(.pack)
(.setVisible true)))
</syntaxhighlight>
 
=={{header|Common Lisp}}==
Line 555 ⟶ 1,000:
Common Lisp doesn't provide native graphical output. Libraries or bitmapped output could be used instead, but for this solution, the output is accomplished with character printing.
 
<langsyntaxhighlight lang="lisp">(defun draw-coords-as-text (coords size fill-char)
(let* ((min-x (apply #'min (mapcar #'car coords)))
(min-y (apply #'min (mapcar #'cdr coords)))
Line 625 ⟶ 1,070:
 
 
</syntaxhighlight>
</lang>
 
=={{header|ClojureCraft Basic}}==
<syntaxhighlight lang="basic">bgcolor 0, 0, 0
{{Works with| Incanter}}
cls graphics
<lang clojure>
fgcolor 255, 255, 0
(use '(incanter core stats charts io))
 
define pi = 3.14, size = 80
(defn Arquimidean-function
define x = 250, y = 200
[a b theta]
(+define a (*= theta1.5, b))) = .7
 
for t = 0 to size * pi step .1
(defn transform-pl-xy [r theta]
(let [x (* r (sin theta))
y (* r (cos theta))]
[x y]))
 
let r = a + b * t
(defn arq-spiral [t] (transform-pl-xy (Arquimidean-function 0 7 t) t))
dot r * cos(t) + x, r * sin(t) + y
wait
 
next t</syntaxhighlight>
(view (parametric-plot arq-spiral 0 (* 10 Math/PI)))
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Types,ExtCtrls,Graphics}}
 
 
 
<syntaxhighlight lang="Delphi">
procedure ArcSpiral(Image: TImage);
var Radius,Theta: double;
var X,Y: integer;
var Center: TPoint;
const Step = 0.2;
const Offset = 3; Spacing = 1.4;
begin
Image.Canvas.Brush.Color:=clWhite;
Image.Canvas.Rectangle(0,0,Image.Width,Image.Height);
Center:=Point(Image.Width div 2, Image.Height div 2);
Image.Canvas.MoveTo(Center.X,Center.Y);
Theta:=0;
while Theta<(40*Pi) do
begin
{Radius increases as theta increases}
Radius:=Offset+Spacing*Theta;
{Calculate position on circle}
X:=Trunc(Radius*Cos(Theta)+Center.X);
Y:=Trunc(Radius*sin(Theta)+Center.Y);
Image.Canvas.LineTo(X,Y);
Theta:=Theta+Step;
end;
end;
 
</syntaxhighlight>
 
{{out}}
[[File:DelphiASpiral.png|frame|none]]
<pre>
</pre>
 
=={{header|EasyLang}}==
 
[https://easylang.dev/show/#cod=JcwxCsAgEETRfk8xdQQRol08TSK4IAZUUG8f11TDg88kzqHz0yKMtjTg4QzNf3rkFFBwCQCk1S4euN+KBoWxVTlvTWkKlF9Xxgma4CRNHw== Run it]
 
<syntaxhighlight lang="easylang">
linewidth 0.4
x = 50
y = 50
while r < 50
line r * cos t + x r * sin t + y
r += 0.05
t += 3
.
</syntaxhighlight>
 
=={{header|FOCAL}}==
<syntaxhighlight lang="focal">1.1 S A=1.5
1.2 S B=2
1.3 S N=250
1.4 F T=1,N; D 2
1.5 X FSKP(2*N)
1.6 Q
 
2.1 S R=A+B*T; D 3
2.2 X FPT(2*T,X1+512,Y1+390)
2.3 S R=A+B*(T+1); D 4
2.4 X FVEC(2*T+1,X2-X1,Y2-Y1)
 
3.1 S X1=R*FSIN(.2*T)
3.2 S Y1=R*FCOS(.2*T)
 
4.1 S X2=R*FSIN(.2*(T+1))
</lang>
4.2 S Y2=R*FCOS(.2*(T+1))</syntaxhighlight>
<pre> </pre>
This program uses FOCAL-11 on a DEC GT40 vector graphics terminal.
 
=={{header|Frege}}==
Line 653 ⟶ 1,167:
{{Works with|Frege|3.23.888}}
 
<langsyntaxhighlight lang="frege">module Archimedean where
 
import Java.IO
Line 741 ⟶ 1,255:
drawSpiral g
f <- File.new "SpiralFrege.png"
void $ ImageIO.write buffy "png" f</langsyntaxhighlight>
 
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|Frink}}==
<syntaxhighlight lang="frink">p = new polyline
g = new graphics
a = 1
b = 1
for theta = 0 to 10 circle step 1 degree
{
r = a + b theta
x = r cos[theta]
y = r sin[theta]
p.addPoint[x,-y]
}
 
g.add[p]
g.show[]
g.write["ArchimedeanSpiralFrink.svg",800,800]</syntaxhighlight>
 
[[File:ArchimedeanSpiralFrink.svg|400 px]]
 
=={{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}}==
{{works with|go|1.9}}
Creates a PNG file using only built-in packages.
<langsyntaxhighlight lang="go">package main
 
import (
Line 795 ⟶ 1,355:
log.Fatal(err)
}
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
Line 802 ⟶ 1,362:
{{libheader|Juicy.Pixels}}
{{libheader|Rasterific}}
<langsyntaxhighlight lang="haskell">#!/usr/bin/env stack
-- stack --resolver lts-7.0 --install-ghc runghc --package Rasterific --package JuicyPixels
 
Line 828 ⟶ 1,388:
polyline points
 
writePng "SpiralHaskell.png" img</langsyntaxhighlight>
 
Output is [http://funwithsoftware.org/images/2016-SpiralHaskell.png here] due to [[User talk:Short Circuit#Is file uploading blocked forever?|Is file uploading blocked forever?]]
Line 834 ⟶ 1,394:
=={{header|J}}==
[[File:Archimedian spiral j.png|200px|thumb|right]]
<langsyntaxhighlight lang="j">require'plot'
'aspect 1' plot (*^)j.0.01*i.1400</langsyntaxhighlight>
 
<div style="clear:both"></div>
Line 842 ⟶ 1,402:
[[File:archimedian_spiral.png|300px|thumb|right]]
{{works with|Java|8}}
<langsyntaxhighlight lang="java">import java.awt.*;
import static java.lang.Math.*;
import javax.swing.*;
Line 925 ⟶ 1,485:
});
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Line 931 ⟶ 1,491:
{{Works with|Chrome}}
[[File:ASjs.png|200px|right|thumb|Output ASjs.png]]
<langsyntaxhighlight lang="html">
<!-- ArchiSpiral.html -->
<html>
Line 956 ⟶ 1,516:
}
</script></body></html>
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 966 ⟶ 1,526:
Assumes the same HTML canvas embedding as above, but is functionally composed.
Defines and logs a set of points, before rendering them to canvas.
<langsyntaxhighlight lang="html"><html>
<head>
<head><title>Archimedean spiral</title></head>
<title>Archimedean spiral</title>
<body onload="main(15)('red')">
<style>h3 {font-family:sans-serif; color:gray;}</style>
</head>
<body onload="main('red')(15)">
<h3>Archimedean spiral</h3></p>
<canvas id="spiral" width="640" height="640" style="border: 2px outset;"></canvas>
<script></langsyntaxhighlight>
<langsyntaxhighlight lang="javascript">const main = cyclesstrColor => colorintCycles => {
const
ai = 0.05,
Line 981 ⟶ 1,544:
 
points = enumFromTo(1)(
Math.PI * 2 * cyclesintCycles / ai
).map(i => [Math.cos, Math.sin].map(
f => ri * i * f(ai * i) + s
Line 994 ⟶ 1,557:
points.forEach(xy => ctx.lineTo(...xy)),
 
ctx.strokeStyle = colorstrColor,
ctx.stroke(),
points
Line 1,004 ⟶ 1,567:
Array.from({
length: 1 + n - m
}, (_, i) => m + i);</langsyntaxhighlight>
<langsyntaxhighlight lang="html"></script></body></html></langsyntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
====SVG version====
<syntaxhighlight lang="jq">def spiral($zero; $turns; $step):
 
def pi: 1 | atan * 4;
def p2: (. * 100 | round) / 100;
 
def svg:
400 as $width
| 400 as $height
| 2 as $swidth # stroke
| "blue" as $stroke
| (range($zero; $turns * 2 * pi; $step) as $theta
| (((($theta)|cos) * 2 * $theta + ($width/2)) |p2) as $x
| (((($theta)|sin) * 2 * $theta + ($height/2))|p2) as $y
| if $theta == $zero
then "<path fill='transparent' style='stroke:\($stroke); stroke-width:\($swidth)' d='M \($x) \($y)"
else " L \($x) \($y)"
end),
"' />";
 
"<svg width='100%' height='100%'
xmlns='http://www.w3.org/2000/svg'>",
svg,
"</svg>" ;
 
spiral(0; 10; 0.025)
</syntaxhighlight>
{{out}}
 
[https://ibb.co/kMSDzx1 PNG version of SVG file]
(Please feel free to upload to RC)
 
====ASCII Art Version====
{{trans|awk}}
<syntaxhighlight lang="jq">def spiral($a; $b; $step; $h):
def min($x;$y): if $x <= $y then $x else $y end;
def max($x;$y): if $x <= $y then $y else $x end;
def pi: 1 | atan * 4;
(6 * pi) as $m
| ($h * 1.5) as $w
| { x_min: 9999, y_min: 9999,
x_max: 0, y_max: 0,
arr: [] }
| reduce range($step; $m+$step; $step) as $t (.;
.r = $a + $b * $t
| ((.r * ($t|cos) + $w) | round) as $x
| ((.r * ($t|sin) + $h) | round) as $y
| if $x <= 0 or $y <= 0 then .
elif $x >= 280 then .
elif $y >= 192 then .
else .arr[$x][$y] = "*"
| .x_min = min(.x_min; $x)
| .x_max = max(.x_max; $x)
| .y_min = min(.y_min; $y)
| .y_max = max(.y_max; $y)
end )
# ... and print it
| .arr as $arr
| range(.x_min; .x_max + 1) as $i
| reduce range(.y_min; .y_max+1) as $j ( "";
. + ($arr[$i][$j] // " ") )
| "\(.)\n" ;
 
spiral(1; 1; 0.02; 96)</syntaxhighlight>
{{out}}
As for [[#awk|awk]].
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">using UnicodePlots
 
spiral(θ, a=0, b=1) = @. b * θ * cos(θ + a), b * θ * sin(θ + a)
 
x, y = spiral(1:0.1:10)
println(lineplot(x, y))</langsyntaxhighlight>
 
{{out}}
Line 1,040 ⟶ 1,674:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.*
Line 1,115 ⟶ 1,749:
f.isVisible = true
}
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="Scheme">
1) from polar to cartesian coordinates
 
x = r*cos(t) = (a+b*t)*cos(t)
y = r*sin(t) = (a+b*t)*sin(t)
 
2) define the curve
 
{def CURVE
{lambda {:a :b :t}
{* {+ :a {* :b :t}} {cos :t}}
{* {+ :a {* :b :t}} {sin :t}}
}}
-> CURVE
 
3) and draw it using SVG
 
{{SVG 580}
{g {AXES 580 580}
{polyline {@ points="{S.map {CURVE 5 4}
{S.serie 0 {* 10 {PI}} 0.1}}"
{stroke red 3}}
}}}
</syntaxhighlight>
The ouput can be seen in http://lambdaway.free.fr/lambdawalks/?view=archimedian_spiral
 
 
=={{header|Lua}}==
{{libheader|LÖVE}}
{{works with|LÖVE|11.3}}
<syntaxhighlight lang="lua">
a=1
b=2
cycles=40
step=0.001
x=0
y=0
 
function love.load()
x = love.graphics.getWidth()/2
y = love.graphics.getHeight()/2
end
 
function love.draw()
love.graphics.print("a="..a,16,16)
love.graphics.print("b="..b,16,32)
 
for i=0,cycles*math.pi,step do
love.graphics.points(x+(a + b*i)*math.cos(i),y+(a + b*i)*math.sin(i))
end
end
</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
module Archimedean_spiral {
smooth on ' enable GDI+
def r(θ)=5+3*θ
cls #002222,0
pen #FFFF00
refresh 5000
every 1000 {
\\ redifine window (console width and height) and place it to center (symbol ;)
Window 12, random(10, 18)*1000, random(8, 12)*1000;
move scale.x/2, scale.y/2
let N=2, k1=pi/120, k=k1, op=5, op1=1
for i=1 to int(1200*min.data(scale.x, scale.y)/18000)
pen op
swap op, op1
Width 3 {draw angle k, r(k)*n}
k+=k1
next
refresh 5000
\\ press space to exit loop
if keypress(32) then exit
}
pen 14
cls 5
refresh 50
}
Archimedean_spiral
</syntaxhighlight>
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">
<lang Maple>
plots[polarplot](1+2*theta, theta = 0 .. 6*Pi)
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
The built-in function PolarPlot easily creates the desired plot
<langsyntaxhighlight Mathematicalang="mathematica">With[{a = 5, b = 4}, PolarPlot[a + b t, {t, 0, 10 Pi}]]</langsyntaxhighlight>
 
=={{header|MATLAB}}==
<langsyntaxhighlight MATLABlang="matlab">a = 1;
b = 1;
turns = 2;
theta = 0:0.1:2*turns*pi;
polarplot(theta, a + b*theta);</langsyntaxhighlight>
 
=={{header|Maxima}}==
Using draw package
<syntaxhighlight lang="maxima">
archi_spi(a,b):=wxdraw2d(nticks=200,polar(a+b*theta,theta,1,10*%pi))$
archi_spi(1,1);
</syntaxhighlight>
[[File:Archi spi.png|thumb|center]]
 
=={{header|MiniScript}}==
For use with the [http://miniscript.org/MiniMicro Mini Micro].
<syntaxhighlight lang="miniscript">
clear
x0 = gfx.width / 2
y0 = gfx.height / 2
gfx.clear color.white
for t in range(0, 70 * pi, 0.1)
r = 3.2+ 1.5 * t
x = r * cos(t) + gfx.width / 2
y = r * sin(t) + gfx.height / 2
gfx.line x0, y0, x, y, color.black,2
x0 = x; y0 = y
end for
</syntaxhighlight>
 
Alternative version using a Turtle library included with the [http://miniscript.org/MiniMicro Mini Micro].
 
<syntaxhighlight lang="miniscript">
import "turtle"
radToDegrees = function(rad)
return 180 * rad / pi
end function
 
clear
print Turtle.displayNum
display(Turtle.displayNum).clear
t = new Turtle
for i in range(0, 50, 0.04)
t.forward i
t.left radToDegrees(pi/20)
end for
</syntaxhighlight>
 
=={{header|Nim}}==
{{libheader|gintro}}
<syntaxhighlight lang="nim">import math
 
import gintro/[glib, gobject, gtk, gio, cairo]
 
const
 
Width = 601
Height = 601
 
Limit = 12 * math.PI
 
Origin = (x: float(Width div 2), y: float(Height div 2))
B = floor((Width div 2) / Limit)
 
#---------------------------------------------------------------------------------------------------
 
proc draw(area: DrawingArea; context: Context) =
## Draw the spiral.
 
var theta = 0.0
var delta = 0.01
var (prevx, prevy) = Origin
 
# Clear the region.
context.moveTo(0, 0)
context.setSource(0.0, 0.0, 0.0)
context.paint()
 
# Draw the spiral.
context.setSource(1.0, 1.0, 0.0)
context.moveTo(Origin.x, Origin.y)
while theta < Limit:
let r = B * theta
let x = Origin.x + r * cos(theta) # X-coordinate on drawing area.
let y = Origin.y + r * sin(theta) # Y-coordinate on drawing area.
context.lineTo(x, y)
context.stroke()
# Set data for next round.
context.moveTo(x, y)
prevx = x
prevy = y
theta += delta
 
#---------------------------------------------------------------------------------------------------
 
proc onDraw(area: DrawingArea; context: Context; data: pointer): bool =
## Callback to draw/redraw the drawing area contents.
 
area.draw(context)
result = true
 
#---------------------------------------------------------------------------------------------------
 
proc activate(app: Application) =
## Activate the application.
 
let window = app.newApplicationWindow()
window.setSizeRequest(Width, Height)
window.setTitle("Archimedean spiral")
 
# Create the drawing area.
let area = newDrawingArea()
window.add(area)
 
# Connect the "draw" event to the callback to draw the spiral.
discard area.connect("draw", ondraw, pointer(nil))
 
window.showAll()
 
#———————————————————————————————————————————————————————————————————————————————————————————————————
 
let app = newApplication(Application, "Rosetta.spiral")
discard app.connect("activate", activate)
discard app.run()</syntaxhighlight>
 
=={{header|PARI/GP}}==
Line 1,139 ⟶ 1,976:
[[File:ArchiSpiral2.png|right|thumb|Output ArchiSpiral2.png]]
 
<langsyntaxhighlight lang="parigp">
\\ The Archimedean spiral
\\ ArchiSpiral() - Where: lps is a number of loops, c is a direction 0/1
Line 1,159 ⟶ 1,996:
ArchiSpiral(640,5,1); \\ArchiSpiral2.png
}
</langsyntaxhighlight>
{{Output}}
Line 1,171 ⟶ 2,008:
 
=={{header|Perl}}==
{{trans|Perl 6Raku}}
<langsyntaxhighlight Perllang="perl">use Imager;
use constant PI => 3.14159265;
 
Line 1,185 ⟶ 2,022:
 
$img->write(file => 'Archimedean-spiral.png');
</syntaxhighlight>
</lang>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2018.10}}
 
<lang perl6>use Image::PNG::Portable;
 
my ($w, $h) = (400, 400);
 
my $png = Image::PNG::Portable.new: :width($w), :height($h);
 
(0, .025 ... 52*π).race.map: -> \Θ {
$png.set: |((cis( Θ / π ) * Θ).reals »+« ($w/2, $h/2))».Int, 255, 0, 255;
}
 
$png.write: 'Archimedean-spiral-perl6.png';</lang>
 
=={{header|Phix}}==
{{trans|zkl}}
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
<lang Phix>--
--You demo\rosetta\can run this online [http://phix.x10.mx/p2js/Archimedean_spiral.exwhtm here].
<!--<syntaxhighlight lang="phix">(phixonline)-->
--
<span style="color: #000080;font-style:italic;">--
include pGUI.e
-- demo\rosetta\Archimedean_spiral.exw
 
-- ===================================
Ihandle dlg, canvas
--</span>
cdCanvas cddbuffer, cdcanvas
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
 
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
integer a = 0, b = 5
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span>
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cdcanvas</span>
integer {centerX,centerY} = sq_floor_div({width,height},2)
cdCanvasActivate(cddbuffer)
<span style="color: #008080;">function</span> <span style="color: #000000;">redraw_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">)</span>
for deg=0 to 360*7 do
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">w</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">),</span>
atom rad = deg*PI/180
<span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">b</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">w</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">cy</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">h</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
atom r = rad*b + a
<span style="color: #7060A8;">cdCanvasActivate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
integer x = centerX + floor(r*cos(rad))
<span style="color: #008080;">for</span> <span style="color: #000000;">deg</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">360</span><span style="color: #0000FF;">*</span><span style="color: #000000;">7</span> <span style="color: #008080;">do</span>
integer y = centerY + floor(r*sin(rad))
<span style="color: #004080;">atom</span> <span style="color: #000000;">rad</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">deg</span><span style="color: #0000FF;">*</span><span style="color: #004600;">PI</span><span style="color: #0000FF;">/</span><span style="color: #000000;">180</span><span style="color: #0000FF;">,</span>
cdCanvasPixel(cddbuffer, x, y, #00FF00)
<span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rad</span><span style="color: #0000FF;">*</span><span style="color: #000000;">b</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">a</span>
end for
<span style="color: #004080;">integer</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cx</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">*</span><span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rad</span><span style="color: #0000FF;">)),</span>
cdCanvasFlush(cddbuffer)
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cy</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">*</span><span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rad</span><span style="color: #0000FF;">))</span>
return IUP_DEFAULT
<span style="color: #7060A8;">cdCanvasPixel</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">#00FF00</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
 
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
function map_cb(Ihandle ih)
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
cdcanvas = cdCreateCanvas(CD_IUP, ih)
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
cddbuffer = cdCreateCanvas(CD_DBUFFER, cdcanvas)
cdCanvasSetBackground(cddbuffer, CD_WHITE)
<span style="color: #008080;">function</span> <span style="color: #000000;">map_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
cdCanvasSetForeground(cddbuffer, CD_RED)
<span style="color: #000000;">cdcanvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_IUP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
return IUP_DEFAULT
<span style="color: #000000;">cddbuffer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_DBUFFER</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #7060A8;">cdCanvasSetBackground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_WHITE</span><span style="color: #0000FF;">)</span>
 
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_RED</span><span style="color: #0000FF;">)</span>
function esc_close(Ihandle /*ih*/, atom c)
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
if c=K_ESC then return IUP_CLOSE end if
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
return IUP_CONTINUE
end function
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
 
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
procedure main()
<span style="color: #000000;">canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupCanvas</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"RASTERSIZE=500x500"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- initial size</span>
IupOpen()
<span style="color: #7060A8;">IupSetCallbacks</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"MAP_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"map_cb"</span><span style="color: #0000FF;">),</span>
 
<span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"redraw_cb"</span><span style="color: #0000FF;">)})</span>
canvas = IupCanvas(NULL)
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`TITLE="Archimedean spiral"`</span><span style="color: #0000FF;">)</span>
IupSetAttribute(canvas, "RASTERSIZE", "340x340") -- initial size
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"RASTERSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- release the minimum limitation</span>
 
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
dlg = IupDialog(canvas)
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
IupSetAttribute(dlg, "TITLE", "Archimedean spiral")
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
 
IupMap(dlg)
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
IupSetAttribute(canvas, "RASTERSIZE", NULL) -- release the minimum limitation
<!--</syntaxhighlight>-->
IupShowXY(dlg,IUP_CENTER,IUP_CENTER)
IupMainLoop()
IupClose()
end procedure
 
main()</lang>
 
=={{header|Processing}}==
Processing examples are animated, with a new point / segment added each draw() frame. Because Processing includes multiple built-in ways for drawing in rotating frames of reference, there are several ways to approach the Archimedean spiral problem.
===withJava pointsmode===
====with points====
When drawn with points the rotation must be very small, and initially the animation is very slow. This is because the points will move further and further apart as the radius increases.
<langsyntaxhighlight Processinglang="processing">float x, y;
float theta;
float rotation;
Line 1,286 ⟶ 2,104:
// check restart
if (x>width/2.0) frameCount=-1;
}</langsyntaxhighlight>
 
====with points, rotated====
Rotates the canvas matrix using the built-in rotate() and draws a simple point, rather than computing rotated coordinates with sin()/cos().
<langsyntaxhighlight Processinglang="processing">float theta;
float rotation;
 
Line 1,307 ⟶ 2,125:
// check restart
if (theta>width/2.0) frameCount=-1;
}</langsyntaxhighlight>
 
====with points, vector====
Rotates a vector object of increasing magnitude using the built-in PVector and draws its point, rather than computing rotated coordinates with sin()/cos().
<langsyntaxhighlight Processinglang="processing">PVector pv;
float rotation;
 
Line 1,329 ⟶ 2,147:
// check restart
if (pv.mag()>width/2.0) frameCount=-1;
}</langsyntaxhighlight>
 
====with line segments====
Draw each new line segments anchored to the previous point in order to keep the spiral visually connected no matter how much the radius expands.
<langsyntaxhighlight Processinglang="processing">float px, py, x, y;
float theta;
float rotation;
Line 1,354 ⟶ 2,172:
// check restart
if (px>width/2.0) frameCount=-1;
}</langsyntaxhighlight>
 
====with line segments, rotated====
Uses the built-in rotate() and screenX() to rotate the frame of reference and then recover the rotated screen position of each next point. Draw each new line segments anchored to the previous point in order to keep the spiral visually connected no matter how much the radius expands.
<langsyntaxhighlight Processinglang="processing">float x, y, px, py;
float theta;
float rotation;
Line 1,383 ⟶ 2,201:
py = y;
if (theta>width/2.0) frameCount=-1; // start over
}</langsyntaxhighlight>
 
==={{header|PureBasicProcessing Python mode}}===
====with points====
<lang PureBasic>#MAXLOOP = 7*360
When drawn with points the rotation must be very small, and initially the animation is very slow. This is because the points will move further and further apart as the radius increases.
#XCENTER = 640/2
<syntaxhighlight lang="python">theta = 0
#YCENTER = 480/2
rotation = 0.1
#SCALAR = 200
 
def setup():
If OpenWindow(0, 100, 200, 640, 480, "Archimedean spiral")
size(300, 300)
If CreateImage(0, 640, 480,24,RGB(255,255,255))
background(255)
If StartDrawing(ImageOutput(0))
 
i.f=0.0
def draw():
While i<=#MAXLOOP
global theta
x.f=#XCENTER+Cos(Radian(i))*#SCALAR*i/#MAXLOOP
translate(width / 2.0, height / 2.0)
y.f=#YCENTER+Sin(Radian(i))*#SCALAR*i/#MAXLOOP
x = theta * Plotcos(x,y,RGB(50,50,50)theta / PI)
y = theta * i+0.05sin(theta / PI)
point(x, Wendy)
theta = StopDrawing()theta + rotation
EndIf# check restart
if x > width / 2.0:
EndIf
background(255)
ImageGadget(0, 0, 0, 0, 0, ImageID(0))
theta = 0</syntaxhighlight>
Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
EndIf
End</lang>
 
=={{header|Python}}==
Using the '''turtle''' module.
 
<langsyntaxhighlight lang="python">from turtle import *
from math import *
color("blue")
Line 1,422 ⟶ 2,238:
goto(x, y)
up()
done()</langsyntaxhighlight>
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
turtle
20 frames
0 n->v
900 times
[ 2dup walk
1 20 v+
1 36 turn ]
2drop
1 frames</syntaxhighlight>
 
{{out}}
 
[[File:Quackery Archimedean spiral.png]]
 
=={{header|R}}==
<langsyntaxhighlight lang="r">with(list(s=seq(0, 10 * pi, length.out=500)),
plot((1 + s) * exp(1i * s), type="l"))</langsyntaxhighlight>
 
=={{header|Racket}}==
 
[[File:archemedian-spiral-racket.png]]
<langsyntaxhighlight lang="racket">#lang racket/base
(require plot
racket/math)
Line 1,452 ⟶ 2,284:
;; writes to a file so hopefully, I can post it to RC...
(plot-file (list (archemedian-spiral-renderer2d 0.0 24 4))
"images/archemidian-spiral-racket.png")</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.10}}
 
<syntaxhighlight lang="raku" line>use Image::PNG::Portable;
 
my ($w, $h) = (400, 400);
 
my $png = Image::PNG::Portable.new: :width($w), :height($h);
 
(0, .025 ... 52*π).race.map: -> \Θ {
$png.set: |((cis( Θ / π ) * Θ).reals »+« ($w/2, $h/2))».Int, 255, 0, 255;
}
 
$png.write: 'Archimedean-spiral-perl6.png';</syntaxhighlight>
 
=={{header|REXX}}==
Line 1,458 ⟶ 2,306:
 
Note: &nbsp; the value of &nbsp; <big><big> ''a'' </big></big> &nbsp; doesn't mean that much as the plot is automatically centered.
<langsyntaxhighlight lang="rexx">/*REXX pgm plots several cycles (half a spiral) of the Archimedean spiral (ASCII plot).*/
parse arg cy a b inc chr . /*obtain optional arguments from the CL*/
if cy=='' | cy=="," then cy= 3 /*Not specified? Then use the default.*/
Line 1,477 ⟶ 2,325:
y= h + r*sin(t); yy= y % 2 /* " " " Y " " */
if x<0 | y<0 | x>mw | y>mh then iterate /*Is X or Y out of bounds? Then skip.*/
if LOx==. then do; LOx= xx; HIx= xx; LOy= yy; HIy= yy
end /* [↑] find the minimums and maximums.*/
LOx= min(LOx, xx); HIx= max(HIx, xx) /*determine the X MIN and MAX. */
Line 1,486 ⟶ 2,334:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
pi: pi=3.1415926535897932384626433832795028841971693993751058209749445923078; return pi
plot: do row=HIy to LOy by -1; say substr(@.row, LOx+1); end; return
r2r: return arg(1) // (pi() * 2) /*normalize radians ───► a unit circle.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
cos: procedure; parse arg x; x= r2r(x); a= abs(x); hpi= pi * .5
numeric fuzz min(6, digits() - 3); if a=pi then return -1
if a=hpi | a=hpi*3 then return 0 if a=pi / 3 then return .5
if a=pi * 2 / 3 then return -.5; return .sinCos(1, -1)
/*──────────────────────────────────────────────────────────────────────────────────────*/
sincos: procedure; parse arg x; x= r2r(x); _= 1; a= abs(x); numeric fuzz min(5,hpi= max(1,pi digits()* -3)).5
numeric iffuzz x=pi *min(6, .5digits() - 3); then return 1;if a=pi if x==pi*1.5 then return -1
if abs(x)a=pihpi | xa=0 hpi*3 then return 0; if a=pi / 3 then return .sinCos(x, 1)5
if a=pi * 2 / 3 then return -.5; q= x*x; z= 1
do k=2 by 2 until p=z; p= z; _= -_ *q/(k*k-k); z= z+_; end; return z
/*──────────────────────────────────────────────────────────────────────────────────────*/
.sinCossin: procedure; parse arg z 1 _,ix; x= r2r(x); _= x; numeric fuzz min(5, max(1, digits() q= x*x-3))
if x=pi * .5 do k=2 by 2 until p=z;then return p= z1; _= -_*q/(k*(k+i)); z= z+_; if end;x==pi*1.5 then return z</lang>-1
if abs(x)=pi | x=0 then return 0; q= x*x; z= x
do k=2 by 2 until p=z; p= z; _= -_ *q/(k*k+k); z= z+_; end; return z</syntaxhighlight>
{{out|output|text=&nbsp; when using the following inputs: &nbsp; <tt> &nbsp; 13 &nbsp; , &nbsp; 5 &nbsp; , &nbsp; db </tt>}}
 
Line 1,700 ⟶ 2,547:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
/*
+---------------------------------------------------------------------------------------------------------
Line 1,805 ⟶ 2,652:
return
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
[[File:Archimedean.png|thumb|right|HP-48G emulator screenshot]]
{{works with|HP|48G}}
« → a b
« -20 20 DUP2 XRNG YRNG
POLAR RAD 'a+b*t' STEQ { t 0 18.9 } INDEP
ERASE DRAW { } PVIEW
{ EQ PPAR } PURGE
» » '<span style="color:blue">ARCHI</span>' STO
 
1 1 <span style="color:blue">ARCHI</span>
 
=={{header|Ruby}}==
{{libheader|RubyGems}}
{{libheader|JRubyArt}}
JRubyArt is an implementation of Processing in ruby, that uses JRuby to provide the interoperability with the java libraries.
<syntaxhighlight lang="ruby">
INCR = 0.1
attr_reader :x, :theta
 
def setup
sketch_title 'Archimedian Spiral'
@theta = 0
@x = 0
background(255)
translate(width / 2.0, height / 2.0)
begin_shape
(0..50*PI).step(INCR) do |theta|
@x = theta * cos(theta / PI)
curve_vertex(x, theta * sin(theta / PI))
end
end_shape
end
 
def settings
size(300, 300)
end
</syntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">#[macro_use(px)]
extern crate bmp;
 
Line 1,839 ⟶ 2,725:
// Save the image
let _ = img.save("archimedean_spiral.bmp").unwrap_or_else(|e| panic!("Failed to save: {}", e));
}</langsyntaxhighlight>
 
=={{header|SAS}}==
<langsyntaxhighlight lang="sas">data xy;
h=constant('pi')/40;
do i=0 to 400;
Line 1,855 ⟶ 2,741:
proc sgplot;
series x=x y=y;
run;</langsyntaxhighlight>
 
=={{header|Scala}}==
===Java Swing Interoperability===
<syntaxhighlight lang="scala">
<lang Scala>
 
object ArchimedeanSpiral extends App {
Line 1,926 ⟶ 2,812:
)
 
}</langsyntaxhighlight>
=={{header|Scilab}}==
<lang>a = 3;
b = 2;
 
theta = linspace(0,10*%pi,1000);
r = a + b .* theta;
 
//1. Plot using polar coordinates
scf(1);
polarplot(theta,r);
 
//2. Plot using rectangular coordinates
//2.1 Convert coordinates using Euler's formula
z = r .* exp(%i .* theta);
x = real(z);
y = imag(z);
 
scf(2);
plot2d(x,y);</lang>
 
=={{header|Scheme}}==
{{libheader|Scheme/PsTk}}
 
<langsyntaxhighlight lang="scheme">
(import (scheme base)
(scheme complex)
Line 1,985 ⟶ 2,852:
(draw-spiral canvas))
(tk-event-loop tk))
</syntaxhighlight>
</lang>
 
=={{header|Scilab}}==
<syntaxhighlight lang="text">a = 3;
b = 2;
 
theta = linspace(0,10*%pi,1000);
r = a + b .* theta;
 
//1. Plot using polar coordinates
scf(1);
polarplot(theta,r);
 
//2. Plot using rectangular coordinates
//2.1 Convert coordinates using Euler's formula
z = r .* exp(%i .* theta);
x = real(z);
y = imag(z);
 
scf(2);
plot2d(x,y);</syntaxhighlight>
 
=={{header|Seed7}}==
 
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "draw.s7i";
include "keybd.s7i";
Line 2,013 ⟶ 2,900:
theta +:= delta;
end while;
DRAW_FLUSHflushGraphic;
ignore(getc(KEYBOARD));
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Perl 6Raku}}
<langsyntaxhighlight lang="ruby">require('Imager')
define π = Num.pi
 
Line 2,033 ⟶ 2,920:
}
 
img.write(file => 'Archimedean_spiral.png')</langsyntaxhighlight>
Output image: [https://github.com/trizen/rc/blob/master/img/archimedean-spiral-sidef.png Archimedean spiral]
 
=={{header|Stata}}==
<langsyntaxhighlight lang="stata">clear all
scalar h=_pi/40
set obs 400
Line 2,043 ⟶ 2,930:
gen x=(1+t)*cos(t)
gen y=(1+t)*sin(t)
line y x</langsyntaxhighlight>
 
=={{header|Tcl}}==
This creates a little Tk GUI where you can interactively enter values for `a` and `b`. The spiral will be re-drawn automatically thanks to `trace`:
 
<langsyntaxhighlight Tcllang="tcl">package require Tk
 
# create widgets
Line 2,112 ⟶ 2,999:
update ;# lay out widgets before trying to draw
draw
vwait forever ;# go into event loop until window is closed</langsyntaxhighlight>
 
=={{header|VBAWren}}==
{{trans|Sidef}}
<lang vb>Private Sub plot_coordinate_pairs(x As Variant, y As Variant)
{{libheader|DOME}}
Dim chrt As Chart
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color
Set chrt = ActiveSheet.Shapes.AddChart.Chart
import "dome" for Window
With chrt
 
.ChartType = xlXYScatter
class Game {
.HasLegend = False
static init() {
.SeriesCollection.NewSeries
Window.title = "Archimedean Spiral"
.SeriesCollection.Item(1).XValues = x
.SeriesCollection.Item(1).Values__width = y400
__height = 400
End With
Canvas.resize(__width, __height)
End Sub
Window.resize(__width, __height)
Public Sub main()
var col = Color.red
Dim x(1000) As Single, y(1000) As Single
a = 1 spiral(col)
b = 9}
 
For i = 0 To 1000
static spiral(col) {
theta = i * WorksheetFunction.Pi() / 60
rvar theta = a + b * theta0
xwhile (i)theta =< r52 * Cos(thetaNum.pi) {
y(i) var x = r((theta/Num.pi).cos * Sin(theta + __width/2).truncate
var y = ((theta/Num.pi).sin * theta + __height/2).truncate
Next i
Canvas.pset(x, y, col)
plot_coordinate_pairs x, y
theta = theta + 0.025
End Sub</lang>
}
=={{header|Yabasic}}==
}
{{trans|Sinclair_ZX81_BASIC}}
 
<lang Yabasic>5 OPEN WINDOW 320, 200 : WINDOW ORIGIN "CC"
static update() {}
10 LET A=1.5
 
20 LET B=0.7
static draw(dt) {}
30 FOR T=0 TO 30*PI STEP 0.05
}</syntaxhighlight>
40 LET R=A+B*T
 
50 LINE TO R*COS(T),R*SIN(T)
{{out}}
60 NEXT T</lang>
[[File:Wren-Archimedean_spiral.png]]
 
=={{header|XPL0}}==
Looks a lot like the C++ image.
<syntaxhighlight lang="xpl0">real A, B, R, T, X, Y;
[SetVid($12); \set 640x480 graphics
A:= 0.0; B:= 3.0; T:= 0.0;
Move(320, 240); \start at center of screen
repeat R:= A + B*T;
X:= R*Cos(T); Y:= R*Sin(T);
Line(fix(X)+320, 240-fix(Y), 4\red\);
T:= T + 0.03; \increase angle (Theta)
until T >= 314.159; \50 revs
]</syntaxhighlight>
 
=={{header|zkl}}==
[[File:ArchimedeanSpiral.zk.jpg|250px|thumb|right]]
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<langsyntaxhighlight lang="zkl">fcn archimedeanSpiral(a,b,circles){
w,h:=640,640; centerX,centerY:=w/2,h/2;
bitmap:=PPM(w+1,h+1,0xFF|FF|FF); // White background
Line 2,162 ⟶ 3,063:
}
bitmap.writeJPGFile("archimedeanSpiral.jpg");
}(0,5,7);</langsyntaxhighlight>
29

edits