# Archimedean spiral

Archimedean spiral
You are encouraged to solve this task according to the task description, using any language you may know.

The Archimedean spiral is a spiral named after the Greek mathematician Archimedes.

An Archimedean spiral can be described by the equation:

${\displaystyle \,r=a+b\theta }$

with real numbers a and b.

Draw an Archimedean spiral.

## AWK

 # syntax: GAWK -f ARCHIMEDEAN_SPIRAL.AWK# converted from Applesoft BASICBEGIN {    x_min = y_min = 9999    x_max = y_max = 0    h = 96    w = h + h / 2    a = 1    b = 1    m = 6 * 3.1415926    step = .02    for (t=step; t<=m; t+=step) { # build spiral      r = a + b * t      x = int(r * cos(t) + w)      y = int(r * sin(t) + h)      if (x <= 0 || y <= 0) { continue }      if (x >= 280 ) { continue }      if (y >= 192) { continue }      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)    }    for (i=x_min; i<=x_max; i++) { # print spiral      rec = ""      for (j=y_min; j<=y_max; j++) {        rec = sprintf("%s%1s",rec,arr[i,j])      }      printf("%s\n",rec)    }    exit(0)}function max(x,y) { return((x > y) ? x : y) }function min(x,y) { return((x < y) ? x : y) }
Output:
             **********
***          ***
**              **
**                  **
**                    **
**                      **
**         *******        **
**       ***      ***       *
*       **          **      **
**      **            **      *
*      **              **     **
**     **                *      *
*      *       ****       *     *
*     *      ***  **      *     **
**     *      *     **     *      *
*      *     **      *     *      *
*      *     *       *     *      *
*     **     *      **     *      *
*     **     *     **      *     **
*      *     *            **     *
*      *     *            *      *
**     *      *          **     **
*     *      **        **      *
*      *      ***    ***      **
**     **       ******        *
*      *                    **
*      **                  **
*       **               **
**       **            **
*        ****       ***
*          ********
*
*
**
***
****
*****


## BASIC

### Applesoft BASIC

110 LET H = 96120 LET W = H + H / 2130 HGR2 140 HCOLOR= 3150 LET A = 1160 LET B = 9170 LET PI = 3.1415926535180 LET M = 10 * PI190 LET S = .02200 FOR T = S TO M STEP S210     LET R = A + B * T220     LET X = R *  COS (T) + W230     LET Y = R *  SIN (T) + H240     IF X < 0 THEN  290250     IF Y < 0 THEN  290 260     IF X > 279 THEN  290  270     IF Y > 191 THEN  290280     HPLOT X,Y290 NEXT

### BASIC256

 # Basic-256 ver 1.1.4# Archimedean Spiral width = 430 : height = 430graphsize width, heightrect 0,0, graphwidth,graphheightpenwidth 1color green x = width/2 : y = height/2            # Center of graphics windowi = 1 : t = 0 : xn = 0 : yn = 0       # Initial valuesiter = 150 : q = 30  line x,0,x,heightline 0,y,width,y  penwidth 2color red while i <= iter    t = i / q * pi    xn = (1 + (1 * t)) * cos(t) +x    yn = (1 + (1 * t)) * sin(t) +y    line x,y,xn,yn    x = xn : y = yn        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"

### 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.

1 REM       ARCHIMEDEAN SPIRAL2 REM   USING COMMODORE BASIC 7.03 REM      OF THE COMMODORE 1284 REM **********************************10 GRAPHIC 1,120 A = 1.530 B = 0.740 X0 = 160 : Y0 = 10050 FOR T = 0 TO 40*π STEP 0.260 R = A+B*T70 X = R*COS(T)+160 : Y = R*SIN(T)+10080 DRAW 1,X0,Y0 TO X,Y90 X0 = X : Y0 = Y100 NEXT T110 GOTO 110

### FreeBASIC

' version 16-10-2016' compile with: fbc -s gui Const As double      deg2rad = Atn(1) * 4 / 180    ' pi = atn(1) * 4, pi/180 Const As UInteger screensize = 600                 ' size of window in pixels     Const As Double        turns = 5                   ' number of turnsConst As UInteger   halfscrn = screensize \ 2    Const As uinteger         sf = (turns * (screensize - 100)) / halfscrn  ScreenRes screensize, screensize, 32   ' screen 600 * 600 pixels, 4 byte color Dim As Double r, x, y  For r = 0 To turns * 360 Step 0.05  x = Cos(r * deg2rad) * r / sf   y = Sin(r * deg2rad) * r / sf  PSet(halfscrn + x, halfscrn - y), RGB(255, 255, 255)  Next  ' empty keyboard buffer While InKey <> "" : WendPrint : Print "hit any key to end program"SleepEnd

### IS-BASIC

100 GRAPHICS LORES 2110 OPTION ANGLE DEGREES120 PLOT 640,360,ANGLE 90;130 FOR I=2 TO 33.2 STEP .05140   PLOT FORWARD I,LEFT 5;150 NEXT

### Run BASIC

    'archimedean spiral.bas    'runs in Run Basic    'Run Basic website http://www.runbasic.com    'From Rosettacode.org/wiki/ *** Liberty_BASIC   graphic #g, 300,300 'width and height - the center is 150  c = 255  '255 for white '0 for black  print "Welcome to the Arch-Spiral Program"   pi=acs(-1)  nLoops = 5   #g cls("blue") 'blue background color   #g color(c,c,c) 'set line color - see color above   for t=0 to 2*pi*nLoops step 0.01     'c = c - 1  'changes color parameter     x=100*t/(2*pi*nLoops)*cos(t)+150  '150x150 is the center     y=100*t/(2*pi*nLoops)*sin(t)+150      #g color(c,c,c)  'changes color     #g set(x,y)     'if c <1 then c=255  next    render #g   print "Thank you and Goodbye"  endEnd

### QBASIC

SCREEN 12WINDOW (-2.67, -2!)-(2.67, 2!)PI = 4 * ATN(1)H = PI / 40A = .2: B = .05PSET (A, 0)FOR I = 0 TO 400    T = I * H    X = (A + B * T) * COS(T)    Y = (A + B * T) * SIN(T)    LINE -(X, Y)NEXT

### Sinclair ZX81 BASIC

Translation of: Applesoft BASIC

Works with the unexpanded (1k RAM) ZX81. The output is quite blocky, but identifiably a spiral.

10 LET A=1.520 LET B=0.730 FOR T=0 TO 7*PI STEP 0.0540 LET R=A+B*T50 PLOT R*COS T+32,R*SIN T+2260 NEXT T
Output:

Screenshot here.

## C

Interactive code which asks the parameters a and b as inputs, the number of cycles and the division steps. Requires the WinBGIm library.

 #include<graphics.h>#include<stdio.h>#include<math.h> #define pi M_PI int main(){	double a,b,cycles,incr,i; 	int steps,x=500,y=500; 	printf("Enter the parameters a and b : ");	scanf("%lf%lf",&a,&b); 	printf("Enter cycles : ");	scanf("%lf",&cycles); 	printf("Enter divisional steps : ");	scanf("%d",&steps); 	incr = 1.0/steps; 	initwindow(1000,1000,"Archimedean Spiral"); 	for(i=0;i<=cycles*pi;i+=incr){		putpixel(x + (a + b*i)*cos(i),x + (a + b*i)*sin(i),15);	} 	getch(); 	closegraph();	}

## C++

 #include <windows.h>#include <string>#include <iostream> const int BMP_SIZE = 600; class myBitmap {public:    myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}    ~myBitmap() {        DeleteObject( pen ); DeleteObject( brush );        DeleteDC( hdc ); DeleteObject( bmp );    }    bool create( int w, int h ) {        BITMAPINFO bi;        ZeroMemory( &bi, sizeof( bi ) );        bi.bmiHeader.biSize        = sizeof( bi.bmiHeader );        bi.bmiHeader.biBitCount    = sizeof( DWORD ) * 8;        bi.bmiHeader.biCompression = BI_RGB;        bi.bmiHeader.biPlanes      = 1;        bi.bmiHeader.biWidth       =  w;        bi.bmiHeader.biHeight      = -h;        HDC dc = GetDC( GetConsoleWindow() );        bmp = CreateDIBSection( dc, &bi, DIB_RGB_COLORS, &pBits, NULL, 0 );        if( !bmp ) return false;        hdc = CreateCompatibleDC( dc );        SelectObject( hdc, bmp );        ReleaseDC( GetConsoleWindow(), dc );        width = w; height = h;        return true;    }    void clear( BYTE clr = 0 ) {        memset( pBits, clr, width * height * sizeof( DWORD ) );    }    void setBrushColor( DWORD bClr ) {        if( brush ) DeleteObject( brush );        brush = CreateSolidBrush( bClr );        SelectObject( hdc, brush );    }    void setPenColor( DWORD c ) {        clr = c; createPen();    }    void setPenWidth( int w ) {        wid = w; createPen();    }    void saveBitmap( std::string path ) {        BITMAPFILEHEADER fileheader;        BITMAPINFO       infoheader;        BITMAP           bitmap;        DWORD            wb;        GetObject( bmp, sizeof( bitmap ), &bitmap );        DWORD* dwpBits = new DWORD[bitmap.bmWidth * bitmap.bmHeight];        ZeroMemory( dwpBits, bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ) );        ZeroMemory( &infoheader, sizeof( BITMAPINFO ) );        ZeroMemory( &fileheader, sizeof( BITMAPFILEHEADER ) );        infoheader.bmiHeader.biBitCount = sizeof( DWORD ) * 8;        infoheader.bmiHeader.biCompression = BI_RGB;        infoheader.bmiHeader.biPlanes = 1;        infoheader.bmiHeader.biSize = sizeof( infoheader.bmiHeader );        infoheader.bmiHeader.biHeight = bitmap.bmHeight;        infoheader.bmiHeader.biWidth = bitmap.bmWidth;        infoheader.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD );        fileheader.bfType    = 0x4D42;        fileheader.bfOffBits = sizeof( infoheader.bmiHeader ) + sizeof( BITMAPFILEHEADER );        fileheader.bfSize    = fileheader.bfOffBits + infoheader.bmiHeader.biSizeImage;        GetDIBits( hdc, bmp, 0, height, ( LPVOID )dwpBits, &infoheader, DIB_RGB_COLORS );        HANDLE file = CreateFile( path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,                                   FILE_ATTRIBUTE_NORMAL, NULL );        WriteFile( file, &fileheader, sizeof( BITMAPFILEHEADER ), &wb, NULL );        WriteFile( file, &infoheader.bmiHeader, sizeof( infoheader.bmiHeader ), &wb, NULL );        WriteFile( file, dwpBits, bitmap.bmWidth * bitmap.bmHeight * 4, &wb, NULL );        CloseHandle( file );        delete [] dwpBits;    }    HDC getDC() const     { return hdc; }    int getWidth() const  { return width; }    int getHeight() const { return height; }private:    void createPen() {        if( pen ) DeleteObject( pen );        pen = CreatePen( PS_SOLID, wid, clr );        SelectObject( hdc, pen );    }    HBITMAP bmp; HDC    hdc;    HPEN    pen; HBRUSH brush;    void    *pBits; int    width, height, wid;    DWORD    clr;};class spiral {public:    spiral() {        bmp.create( BMP_SIZE, BMP_SIZE );    }    void draw( int c, int s ) {        double a = .2, b = .3, r, x, y;        int w = BMP_SIZE >> 1;        HDC dc = bmp.getDC();        for( double d = 0; d < c * 6.28318530718; d += .002 ) {            r = a + b * d; x = r * cos( d ); y = r * sin( d );            SetPixel( dc, ( int )( s * x + w ), ( int )( s * y + w ), 255 );        }        // saves the bitmap        bmp.saveBitmap( "./spiral.bmp" );    }private:    myBitmap bmp;};int main(int argc, char* argv[]) {    spiral s; s.draw( 16, 8 ); return 0;}

## C#

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    }}

## Common Lisp

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.

(defun draw-coords-as-text (coords size fill-char)  (let* ((min-x (apply #'min (mapcar #'car coords)))         (min-y (apply #'min (mapcar #'cdr coords)))         (max-x (apply #'max (mapcar #'car coords)))         (max-y (apply #'max (mapcar #'cdr coords)))         (real-size (max (+ (abs min-x) (abs max-x)) ; bounding square                         (+ (abs min-y) (abs max-y))))         (scale-factor (* (1- size) (/ 1 real-size)))         (center-x (* scale-factor -1 min-x))         (center-y (* scale-factor -1 min-y))         (intermediate-result (make-array (list size size)                                           :element-type 'char                                           :initial-element #\space)))    (dolist (c coords)      (let ((final-x (floor (+ center-x (* scale-factor (car c)))))            (final-y (floor (+ center-y (* scale-factor (cdr c))))))          (setf (aref intermediate-result final-x final-y)              fill-char)))    ; print results to output    (loop for i below (array-total-size intermediate-result) do          (when (zerop (mod i size))            (terpri))          (princ (row-major-aref intermediate-result i)))))  (defun spiral (a b step-resolution step-count)  "Returns a list of coordinates for r=a+b*theta stepping theta by step-resolution"  (loop for theta         from 0 upto (* step-count step-resolution)        by step-resolution        for r = (+ a (* b theta))        for x = (* r (cos theta))        for y = (* r (sin theta))        collect (cons x y))) (draw-coords-as-text (spiral 10 10 0.01 1500) 30 #\*); Output:; ;                         *     ;          ******          *    ;       ****    ***        **   ;     ***          **       *   ;    **             **       *  ;   **               **      *  ;   *                 **     ** ;  **                  *      * ; **       ******      *      * ; *       **    **     **     * ; *      **      *      *     * ; *     **       *      *     **; *     *        *      *     * ; *     *     * **      *     * ; *     *     ***      **     * ; *     **             *      * ; *      *            **      * ; *      **          **      ** ; **      **        **       *  ;  *       **      **       **  ;  **       ********        *   ;   *                      **   ;   **                    **    ;    **                  **     ;     **               ***      ;       **            **        ;        ****      ***          ;           *******             ;

## Clojure

Works with: Incanter
 (use '(incanter core stats charts io)) (defn Arquimidean-function  [a b theta]  (+ a (* theta b))) (defn transform-pl-xy [r theta]  (let [x (* r (sin theta))        y (* r (cos theta))]    [x y])) (defn arq-spiral [t] (transform-pl-xy (Arquimidean-function 0 7 t) t)) (view (parametric-plot arq-spiral 0 (* 10 Math/PI)))


## Frege

Translation of: Java
Works with: Frege version 3.23.888

## J

require'plot''aspect 1' plot (*^)j.0.01*i.1400

## Java

Works with: Java version 8
import java.awt.*;import static java.lang.Math.*;import javax.swing.*; public class ArchimedeanSpiral extends JPanel {     public ArchimedeanSpiral() {        setPreferredSize(new Dimension(640, 640));        setBackground(Color.white);    }     void drawGrid(Graphics2D g) {        g.setColor(new Color(0xEEEEEE));        g.setStroke(new BasicStroke(2));         double angle = toRadians(45);         int w = getWidth();        int center = w / 2;        int margin = 10;        int numRings = 8;         int spacing = (w - 2 * margin) / (numRings * 2);         for (int i = 0; i < numRings; i++) {            int pos = margin + i * spacing;            int size = w - (2 * margin + i * 2 * spacing);            g.drawOval(pos, pos, size, size);             double ia = i * angle;            int x2 = center + (int) (cos(ia) * (w - 2 * margin) / 2);            int y2 = center - (int) (sin(ia) * (w - 2 * margin) / 2);             g.drawLine(center, center, x2, y2);        }    }     void drawSpiral(Graphics2D g) {        g.setStroke(new BasicStroke(2));        g.setColor(Color.orange);         double degrees = toRadians(0.1);        double center = getWidth() / 2;        double end = 360 * 2 * 10 * degrees;        double a = 0;        double b = 20;        double c = 1;         for (double theta = 0; theta < end; theta += degrees) {            double r = a + b * pow(theta, 1 / c);            double x = r * cos(theta);            double y = r * sin(theta);            plot(g, (int) (center + x), (int) (center - y));        }    }     void plot(Graphics2D g, int x, int y) {        g.drawOval(x, y, 1, 1);    }     @Override    public void paintComponent(Graphics gg) {        super.paintComponent(gg);        Graphics2D g = (Graphics2D) gg;        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                RenderingHints.VALUE_ANTIALIAS_ON);         drawGrid(g);        drawSpiral(g);    }     public static void main(String[] args) {        SwingUtilities.invokeLater(() -> {            JFrame f = new JFrame();            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);            f.setTitle("Archimedean Spiral");            f.setResizable(false);            f.add(new ArchimedeanSpiral(), BorderLayout.CENTER);            f.pack();            f.setLocationRelativeTo(null);            f.setVisible(true);        });    }}

## JavaScript

Works with: Chrome
File:ASjs.png
Output ASjs.png
 <!-- ArchiSpiral.html --><html><head><title>Archimedean spiral</title></head><body onload="pAS(35,'navy');"><h3>Archimedean spiral</h3> <p id=bo></p><canvas id="canvId" width="640" height="640" style="border: 2px outset;"></canvas><script>// Plotting Archimedean_spiral aev 3/17/17// lps - number of loops, clr - color.function pAS(lps,clr) {  var a=.0,ai=.1,r=.0,ri=.1,as=lps*2*Math.PI,n=as/ai;  var cvs=document.getElementById("canvId");  var ctx=cvs.getContext("2d");  ctx.fillStyle="white"; ctx.fillRect(0,0,cvs.width,cvs.height);  var x=y=0, s=cvs.width/2;  ctx.beginPath();  for (var i=1; i<n; i++) {    x=r*Math.cos(a), y=r*Math.sin(a);    ctx.lineTo(x+s,y+s);    r+=ri; a+=ai;  }//fend i  ctx.strokeStyle = clr; ctx.stroke();}</script></body></html>
Output:
Page with Archimedean spiral like ASjs.png. Right-clicking on the canvas you can save
spiral as a png-file, for example.


## Julia

Works with: Julia version 0.6
using UnicodePlots spiral(θ, a=0, b=1) = @. b * θ * cos(θ + a), b * θ * sin(θ + a) x, y = spiral(1:0.1:10)println(lineplot(x, y))
Output:
       ┌────────────────────────────────────────┐
10 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠤⠤⠤⠤⠤⠤⡧⠤⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⢀⡠⠔⠊⠉⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠉⠓⠤⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⡠⠊⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠉⠢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢤⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢇⠀⠀⠀⠀⠀⠀⠀│
│⠀⡸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠔⠊⠉⠉⠙⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀│
│⠤⡧⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡴⠥⠤⠤⠤⠤⠤⡧⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡼⠤⠤⠤⠤⠤⠤⠄│
│⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠁⠀⠀⠀⠀⠀⠀⠀│
│⠀⢇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢆⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⣀⠜⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠘⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠒⠤⣀⡀⡇⠀⠀⠀⣀⣀⠤⠔⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠘⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡏⠉⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
-10 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
└────────────────────────────────────────┘
-10                                     10

## Kotlin

Translation of: Java
// version 1.1.0 import java.awt.*import javax.swing.* class ArchimedeanSpiral : JPanel() {    init {        preferredSize = Dimension(640, 640)        background = Color.white    }     private fun drawGrid(g: Graphics2D) {        g.color = Color(0xEEEEEE)        g.stroke = BasicStroke(2f)        val angle = Math.toRadians(45.0)        val w = width        val center = w / 2        val margin = 10        val numRings = 8        val spacing = (w - 2 * margin) / (numRings * 2)         for (i in 0 until numRings) {            val pos = margin + i * spacing            val size = w - (2 * margin + i * 2 * spacing)            g.drawOval(pos, pos, size, size)            val ia = i * angle            val x2 = center + (Math.cos(ia) * (w - 2 * margin) / 2).toInt()            val y2 = center - (Math.sin(ia) * (w - 2 * margin) / 2).toInt()            g.drawLine(center, center, x2, y2)        }    }     private fun drawSpiral(g: Graphics2D) {        g.stroke = BasicStroke(2f)        g.color = Color.magenta        val degrees = Math.toRadians(0.1)        val center = width / 2        val end = 360 * 2 * 10 * degrees        val a = 0.0        val b = 20.0        val c = 1.0        var theta = 0.0        while (theta < end) {            val r = a + b * Math.pow(theta, 1.0 / c)            val x = r * Math.cos(theta)            val y = r * Math.sin(theta)            plot(g, (center + x).toInt(), (center - y).toInt())            theta += degrees        }    }     private fun plot(g: Graphics2D, x: Int, y: Int) {        g.drawOval(x, y, 1, 1)    }     override fun paintComponent(gg: Graphics) {        super.paintComponent(gg)        val g = gg as Graphics2D        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)        drawGrid(g)        drawSpiral(g)    }} fun main(args: Array<String>) {    SwingUtilities.invokeLater {        val f = JFrame()        f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE        f.title = "Archimedean Spiral"        f.isResizable = false        f.add(ArchimedeanSpiral(), BorderLayout.CENTER)        f.pack()        f.setLocationRelativeTo(null)        f.isVisible = true    }}

## Maple

 plots[polarplot](1+2*theta, theta = 0 .. 6*Pi)

## Mathematica

The built-in function PolarPlot easily creates the desired plot

With[{a = 5, b = 4}, PolarPlot[a + b t, {t, 0, 10 Pi}]]

## MATLAB

a = 1;b = 1;turns = 2;theta = 0:0.1:2*turns*pi;polarplot(theta, a + b*theta);

## PARI/GP

Note: cartes2() can be found here on PARI/GP page.

Works with: PARI/GP version 2.7.4 and above
File:ArchiSpiral1.png
Output ArchiSpiral1.png
File:ArchiSpiral2.png
Output ArchiSpiral2.png
 \\ The Archimedean spiral  \\ ArchiSpiral() - Where: lps is a number of loops, c is a direction 0/1\\ (counter-clockwise/clockwise). 6/6/16 aev\\ Note: cartes2() can be found here on \\ http://rosettacode.org/wiki/Polyspiral#PARI.2FGP page.ArchiSpiral(size,lps,c=0)={my(a=.0,ai=.1,r=.0,ri=.1,as=lps*2*Pi,n=as/ai,x,y,vc,vx=List(.0),vy=vx);if(c<0||c>1, c=0); if(c, ai*=-1);print(" *** The Archimedean spiral: size=",size," loops=",lps," c=",c);for(i=1, n, vc=cartes2(r,a); x=vc[1]; y=vc[2];    listput(vx,x); listput(vy,y);    r+=ri; a+=ai;);\\fend iplothraw(Vec(vx),Vec(vy));}{\\ Executing:ArchiSpiral(640,5);   \\ArchiSpiral1.pngArchiSpiral(640,5,1); \\ArchiSpiral2.png}
Output:
> ArchiSpiral(640,5);  \\ArchiSpiral1.png
*** The Archimedean spiral: size=640 loops=5 c=0
> ArchiSpiral(640,5,1);  \\ArchiSpiral2.png
*** The Archimedean spiral: size=640 loops=5 c=1


## Perl

Translation of: Perl 6
use Imager;use constant PI => 3.14159265; my ($w,$h) = (400, 400);my $img = Imager->new(xsize =>$w, ysize => $h); for ($theta = 0; $theta < 52*PI;$theta += 0.025) {    $x =$w/2 + $theta * cos($theta/PI);    $y =$h/2 + $theta * sin($theta/PI);    $img->setpixel(x =>$x, y => $y, color => '#FF00FF');}$img->write(file => 'Archimedean-spiral.png');

## Perl 6

Works with: Rakudo version 2018.10

## Sidef

Translation of: Perl 6
require('Imager')define π = Num.pi var (w, h) = (400, 400)var img = %O<Imager>.new(xsize => w, ysize => h) for Θ in (0 .. 52*π -> by(0.025)) {    img.setpixel(        x => floor(cos(Θ / π)*Θ + w/2),        y => floor(sin(Θ / π)*Θ + h/2),        color => [255, 0, 0]    )} img.write(file => 'Archimedean_spiral.png')

Output image: Archimedean spiral

## Stata

clear allscalar h=_pi/40set obs 400gen t=_n*hgen x=(1+t)*cos(t)gen y=(1+t)*sin(t)line y x

## 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:

package require Tk # create widgetscanvas .canvasframe .controls ttk::label .legend -text " r = a + b θ "ttk::label .label_a -text "a ="ttk::entry .entry_a -textvariable attk::label .label_b -text "a ="ttk::entry .entry_b -textvariable bbutton .button -text "Redraw" -command draw # layoutgrid .canvas .controls -sticky nsewgrid .legend - -sticky ns -in .controlsgrid .label_a .entry_a -sticky nsew -in .controlsgrid .label_b .entry_b -sticky nsew -in .controlsgrid .button - -sticky ns -in .controls # make the canvas resize with the windowgrid columnconfigure . 0 -weight 1grid rowconfigure . 0 -weight 1 # spiral parameters:set a .2set b .05 proc draw {} {    variable a    variable b     # make sure inputs are valid:    if {![string is double $a] || ![string is double$b]} return    if {$a == 0 ||$b == 0} return     set w [winfo width .canvas]    set h [winfo height .canvas]    set r 0    set pi [expr {4*atan(1)}]    set step [expr {$pi /$w}]    for {set t 0} {$r < 2} {set t [expr {$t + $step}]} { set r [expr {$a + $b *$t}]        set y [expr {sin($t) *$r}]        set x [expr {cos($t) *$r}]         # transform to canvas co-ordinates        set y [expr {entier((1+$y)*$h/2)}]        set x [expr {entier((1+$x)*$w/2)}]        lappend coords $x$y    }    .canvas delete all    set id [.canvas create line \$coords -fill red]} # draw whenever parameters are changed# ";#" so extra trace arguments are ignoredtrace add variable a write {draw;#}trace add variable b write {draw;#} wm protocol . WM_DELETE_WINDOW exit ;# exit when window is closed update  ;# lay out widgets before trying to drawdrawvwait forever ;# go into event loop until window is closed

## VBA

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 WithEnd SubPublic 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, yEnd Sub

## Yabasic

Translation of: Sinclair_ZX81_BASIC
5 OPEN WINDOW 320, 200 : WINDOW ORIGIN "CC"10 LET A=1.520 LET B=0.730 FOR T=0 TO 30*PI STEP 0.0540 LET R=A+B*T50 LINE TO R*COS(T),R*SIN(T)60 NEXT T

## zkl

Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#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    foreach deg in ([0.0 .. 360*circles]){      rad:=deg.toRad();      r:=rad*b + a;      x,y:=r.toRectangular(rad);      bitmap[centerX + x, centerY + y] = 0x00|FF|00;  // Green dot   }   bitmap.writeJPGFile("archimedeanSpiral.jpg");}(0,5,7);