Archimedean spiral: Difference between revisions

m
Replace deprecated functions
m (syntax highlighting fixup automation)
m (Replace deprecated functions)
 
(41 intermediate revisions by 16 users not shown)
Line 18:
=={{header|Action!}}==
Action! does not provide trigonometric functions. Therefore a simple implementation for Sin and Cos function has been provided.
<syntaxhighlight lang=Action"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
Line 74:
=={{header|Ada}}==
{{libheader|SDLAda}}
<syntaxhighlight lang=Ada"ada">with Ada.Numerics.Elementary_Functions;
 
with SDL.Video.Windows.Makers;
Line 150:
{{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;
Line 232:
********
********
</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>
 
Line 240 ⟶ 290:
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
Line 250 ⟶ 300:
=={{header|AutoHotkey}}==
Requires [https://github.com/tariqporter/Gdip GDIP]
<syntaxhighlight lang=AutoHotkey"autohotkey">if !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
Line 303 ⟶ 353:
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f ARCHIMEDEAN_SPIRAL.AWK
# converted from Applesoft BASIC
Line 382 ⟶ 432:
 
=={{header|BASIC}}==
 
 
==={{header|AmigaBASIC}}===
{{trans|Locomotive Basic}}
<syntaxhighlight lang="amigabasic">a=1.5
b=1.5
pi=3.141592
Line 397 ⟶ 445:
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang=ApplesoftBasic"applesoftbasic">110 LET H = 96
120 LET W = H + H / 2
130 HGR2
Line 419 ⟶ 467:
 
==={{header|BASIC256}}===
<syntaxhighlight lang=BASIC256"basic256">
# Basic-256 ver 1.1.4
# Archimedean Spiral
Line 432 ⟶ 480:
i = 1 : t = 0 : xn = 0 : yn = 0 # Initial values
iter = 150 : q = 30
 
 
line x,0,x,height
Line 448 ⟶ 495:
print i + chr(9) + int(x) + chr(9) + int(y) + chr(9) + int(t) # chr(9) = TAB
i += 1
 
end while
 
Line 454 ⟶ 500:
</syntaxhighlight>
 
==={{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.
<syntaxhighlight lang="basic">1 REM ARCHIMEDEAN SPIRAL
2 REM USING COMMODORE BASIC 7.0
3 REM OF THE COMMODORE 128
Line 476 ⟶ 556:
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' version 16-10-2016
' compile with: fbc -s gui
 
Line 495 ⟶ 575:
PSet(halfscrn + x, halfscrn - y), RGB(255, 255, 255)
Next
 
 
' empty keyboard buffer
Line 504 ⟶ 583:
 
==={{header|GW-BASIC}}===
<syntaxhighlight lang="gwbasic">10 A = 0
20 B = 1
30 SCREEN 1
Line 518 ⟶ 597:
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang=IS"is-BASICbasic">100 GRAPHICS LORES 2
110 OPTION ANGLE DEGREES
120 PLOT 640,360,ANGLE 90;
Line 527 ⟶ 606:
==={{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
Line 534 ⟶ 613:
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}}===
<syntaxhighlight lang=Run"run BASICbasic"> 'archimedean spiral.bas
'runs in Run Basic
'Run Basic website http://www.runbasic.com
Line 565 ⟶ 668:
 
==={{header|QBasic}}===
<syntaxhighlight lang="qbasic">SCREEN 12
WINDOW (-2.67, -2!)-(2.67, 2!)
PI = 4 * ATN(1)
Line 581 ⟶ 684:
{{trans|Applesoft BASIC}}
Works with the unexpanded (1k RAM) ZX81. The output is quite blocky, but identifiably a spiral.
<syntaxhighlight lang="basic">10 LET A=1.5
20 LET B=0.7
30 FOR T=0 TO 7*PI STEP 0.05
Line 589 ⟶ 692:
{{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"c">
#include<graphics.h>
#include<stdio.h>
Line 640 ⟶ 776:
=={{header|C sharp|C#}}==
 
<syntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Drawing;
Line 683 ⟶ 819:
=={{header|C++}}==
[[File:SpiralCpp.png|200px|thumb|right]]
<syntaxhighlight lang="cpp">
#include <windows.h>
#include <string>
Line 798 ⟶ 934:
=={{header|Clojure}}==
{{Works with| Incanter}}
<syntaxhighlight lang="clojure">
(use '(incanter core stats charts io))
 
Line 813 ⟶ 949:
 
(view (parametric-plot arq-spiral 0 (* 10 Math/PI)))
</syntaxhighlight>
 
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>
<pre> </pre>
 
=={{header|Common Lisp}}==
Line 821 ⟶ 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.
 
<syntaxhighlight 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 891 ⟶ 1,070:
 
 
</syntaxhighlight>
 
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">bgcolor 0, 0, 0
cls graphics
fgcolor 255, 255, 0
 
define pi = 3.14, size = 80
define x = 250, y = 200
define a = 1.5, b = .7
 
for t = 0 to size * pi step .1
 
let r = a + b * t
dot r * cos(t) + x, r * sin(t) + y
wait
 
next t</syntaxhighlight>
 
=={{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"focal">1.1 S A=1.5
1.2 S B=2
1.3 S N=250
Line 918 ⟶ 1,167:
{{Works with|Frege|3.23.888}}
 
<syntaxhighlight lang="frege">module Archimedean where
 
import Java.IO
Line 1,009 ⟶ 1,258:
 
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.
<syntaxhighlight lang="go">package main
 
import (
Line 1,067 ⟶ 1,362:
{{libheader|Juicy.Pixels}}
{{libheader|Rasterific}}
<syntaxhighlight lang="haskell">#!/usr/bin/env stack
-- stack --resolver lts-7.0 --install-ghc runghc --package Rasterific --package JuicyPixels
 
Line 1,099 ⟶ 1,394:
=={{header|J}}==
[[File:Archimedian spiral j.png|200px|thumb|right]]
<syntaxhighlight lang="j">require'plot'
'aspect 1' plot (*^)j.0.01*i.1400</syntaxhighlight>
 
Line 1,107 ⟶ 1,402:
[[File:archimedian_spiral.png|300px|thumb|right]]
{{works with|Java|8}}
<syntaxhighlight lang="java">import java.awt.*;
import static java.lang.Math.*;
import javax.swing.*;
Line 1,196 ⟶ 1,491:
{{Works with|Chrome}}
[[File:ASjs.png|200px|right|thumb|Output ASjs.png]]
<syntaxhighlight lang="html">
<!-- ArchiSpiral.html -->
<html>
Line 1,231 ⟶ 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.
<syntaxhighlight lang="html"><html>
<head>
<title>Archimedean spiral</title>
Line 1,240 ⟶ 1,535:
<canvas id="spiral" width="640" height="640" style="border: 2px outset;"></canvas>
<script></syntaxhighlight>
<syntaxhighlight lang="javascript">const main = strColor => intCycles => {
const
ai = 0.05,
Line 1,273 ⟶ 1,568:
length: 1 + n - m
}, (_, i) => m + i);</syntaxhighlight>
<syntaxhighlight lang="html"></script></body></html></syntaxhighlight>
 
=={{header|jq}}==
Line 1,279 ⟶ 1,574:
'''Works with gojq, the Go implementation of jq'''
====SVG version====
<syntaxhighlight lang="jq">def spiral($zero; $turns; $step):
 
def pi: 1 | atan * 4;
Line 1,312 ⟶ 1,607:
====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;
Line 1,349 ⟶ 1,644:
{{works with|Julia|0.6}}
 
<syntaxhighlight lang="julia">using UnicodePlots
 
spiral(θ, a=0, b=1) = @. b * θ * cos(θ + a), b * θ * sin(θ + a)
Line 1,379 ⟶ 1,674:
=={{header|Kotlin}}==
{{trans|Java}}
<syntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.*
Line 1,455 ⟶ 1,750:
}
}</syntaxhighlight>
 
=={{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"lua">
a=1
b=2
Line 1,483 ⟶ 1,806:
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang=M2000"m2000 Interpreterinterpreter">
module Archimedean_spiral {
smooth on ' enable GDI+
Line 1,513 ⟶ 1,836:
 
=={{header|Maple}}==
<syntaxhighlight lang=Maple"maple">
plots[polarplot](1+2*theta, theta = 0 .. 6*Pi)
</syntaxhighlight>
Line 1,519 ⟶ 1,842:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
The built-in function PolarPlot easily creates the desired plot
<syntaxhighlight lang=Mathematica"mathematica">With[{a = 5, b = 4}, PolarPlot[a + b t, {t, 0, 10 Pi}]]</syntaxhighlight>
 
=={{header|MATLAB}}==
<syntaxhighlight lang=MATLAB"matlab">a = 1;
b = 1;
turns = 2;
theta = 0:0.1:2*turns*pi;
polarplot(theta, a + b*theta);</syntaxhighlight>
 
=={{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"nim">import math
 
import gintro/[glib, gobject, gtk, gio, cairo]
Line 1,611 ⟶ 1,976:
[[File:ArchiSpiral2.png|right|thumb|Output ArchiSpiral2.png]]
 
<syntaxhighlight lang="parigp">
\\ The Archimedean spiral
\\ ArchiSpiral() - Where: lps is a number of loops, c is a direction 0/1
Line 1,644 ⟶ 2,009:
=={{header|Perl}}==
{{trans|Raku}}
<syntaxhighlight lang=Perl"perl">use Imager;
use constant PI => 3.14159265;
 
Line 1,664 ⟶ 2,029:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Archimedean_spiral.htm here].
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Archimedean_spiral.exw
Line 1,720 ⟶ 2,085:
====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.
<syntaxhighlight lang=Processing"processing">float x, y;
float theta;
float rotation;
Line 1,743 ⟶ 2,108:
====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().
<syntaxhighlight lang=Processing"processing">float theta;
float rotation;
 
Line 1,764 ⟶ 2,129:
====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().
<syntaxhighlight lang=Processing"processing">PVector pv;
float rotation;
 
Line 1,786 ⟶ 2,151:
====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.
<syntaxhighlight lang=Processing"processing">float px, py, x, y;
float theta;
float rotation;
Line 1,811 ⟶ 2,176:
====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.
<syntaxhighlight lang=Processing"processing">float x, y, px, py;
float theta;
float rotation;
Line 1,841 ⟶ 2,206:
====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.
<syntaxhighlight lang="python">theta = 0
rotation = 0.1
 
Line 1,859 ⟶ 2,224:
background(255)
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}}==
Using the '''turtle''' module.
 
<syntaxhighlight lang="python">from turtle import *
from math import *
color("blue")
Line 1,900 ⟶ 2,241:
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
 
<syntaxhighlight lang=Quackery> [ $ "turtleduck.qky" loadfile ] now!
turtle
20 frames
0 n->v
900 times
Line 1,908 ⟶ 2,249:
1 20 v+
1 36 turn ]
2drop</syntaxhighlight>
1 frames</syntaxhighlight>
 
{{out}}
 
[[File:Quackery Archimedean spiral.png]]
[https://imgur.com/YCjIAlw imgur.com/YCjIAlw]
 
=={{header|R}}==
<syntaxhighlight lang="r">with(list(s=seq(0, 10 * pi, length.out=500)),
plot((1 + s) * exp(1i * s), type="l"))</syntaxhighlight>
 
Line 1,921 ⟶ 2,263:
 
[[File:archemedian-spiral-racket.png]]
<syntaxhighlight lang="racket">#lang racket/base
(require plot
racket/math)
Line 1,948 ⟶ 2,290:
{{works with|Rakudo|2018.10}}
 
<syntaxhighlight lang=perl6"raku" line>use Image::PNG::Portable;
 
my ($w, $h) = (400, 400);
Line 1,964 ⟶ 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.
<syntaxhighlight 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 2,205 ⟶ 2,547:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
/*
+---------------------------------------------------------------------------------------------------------
Line 2,311 ⟶ 2,653:
return
</syntaxhighlight>
 
=={{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}}==
Line 2,316 ⟶ 2,670:
{{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
Line 2,340 ⟶ 2,694:
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">#[macro_use(px)]
extern crate bmp;
 
Line 2,374 ⟶ 2,728:
 
=={{header|SAS}}==
<syntaxhighlight lang="sas">data xy;
h=constant('pi')/40;
do i=0 to 400;
Line 2,391 ⟶ 2,745:
=={{header|Scala}}==
===Java Swing Interoperability===
<syntaxhighlight lang=Scala"scala">
 
object ArchimedeanSpiral extends App {
Line 2,463 ⟶ 2,817:
{{libheader|Scheme/PsTk}}
 
<syntaxhighlight lang="scheme">
(import (scheme base)
(scheme complex)
Line 2,501 ⟶ 2,855:
 
=={{header|Scilab}}==
<syntaxhighlight lang="text">a = 3;
b = 2;
 
Line 2,522 ⟶ 2,876:
=={{header|Seed7}}==
 
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "draw.s7i";
include "keybd.s7i";
Line 2,546 ⟶ 2,900:
theta +:= delta;
end while;
DRAW_FLUSHflushGraphic;
ignore(getc(KEYBOARD));
end func;</syntaxhighlight>
Line 2,552 ⟶ 2,906:
=={{header|Sidef}}==
{{trans|Raku}}
<syntaxhighlight lang="ruby">require('Imager')
define π = Num.pi
 
Line 2,570 ⟶ 2,924:
 
=={{header|Stata}}==
<syntaxhighlight lang="stata">clear all
scalar h=_pi/40
set obs 400
Line 2,581 ⟶ 2,935:
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`:
 
<syntaxhighlight lang=Tcl"tcl">package require Tk
 
# create widgets
Line 2,646 ⟶ 3,000:
draw
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}}==
{{trans|Sidef}}
{{libheader|DOME}}
<syntaxhighlight lang=ecmascript"wren">import "graphics" for Canvas, Color
import "dome" for Window
 
Line 2,703 ⟶ 3,032:
static draw(dt) {}
}</syntaxhighlight>
 
{{out}}
[[File:Wren-Archimedean_spiral.png]]
 
=={{header|XPL0}}==
Looks a lot like the C++ image.
<syntaxhighlight lang=XPL0"xpl0">real A, B, R, T, X, Y;
[SetVid($12); \set 640x480 graphics
A:= 0.0; B:= 3.0; T:= 0.0;
Line 2,716 ⟶ 3,048:
until T >= 314.159; \50 revs
]</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}}==
[[File:ArchimedeanSpiral.zk.jpg|250px|thumb|right]]
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<syntaxhighlight 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
29

edits