Archimedean spiral: Difference between revisions
Content added Content deleted
(Added Quackery) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 18: | Line 18: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
Action! does not provide trigonometric functions. Therefore a simple implementation for Sin and Cos function has been provided. |
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 |
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 |
88 92 96 100 104 108 112 116 120 124 128 132 136 139 143 |
||
Line 68: | Line 68: | ||
DO UNTIL CH#$FF OD |
DO UNTIL CH#$FF OD |
||
CH=$FF |
CH=$FF |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Archimedean_spiral.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Archimedean_spiral.png Screenshot from Atari 8-bit computer] |
||
Line 74: | Line 74: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{libheader|SDLAda}} |
{{libheader|SDLAda}} |
||
< |
<syntaxhighlight lang=Ada>with Ada.Numerics.Elementary_Functions; |
||
with SDL.Video.Windows.Makers; |
with SDL.Video.Windows.Makers; |
||
Line 145: | Line 145: | ||
Window.Finalize; |
Window.Finalize; |
||
SDL.Finalise; |
SDL.Finalise; |
||
end Archimedean_Spiral;</ |
end Archimedean_Spiral;</syntaxhighlight> |
||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
{{Trans|AWK}} |
{{Trans|AWK}} |
||
This version doubles the characters horiontally to give a slightly more rounded shape. |
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 % |
% 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 max ( integer x, y ) ; begin if x > y then x else y end; |
||
Line 191: | Line 191: | ||
write() |
write() |
||
end for_i |
end for_i |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 240: | Line 240: | ||
Uses Dyalog's [https://sharpplot.com/ SharpPlot] integration, which works on all supported platforms. |
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 |
InitCauseway ⍬ ⍝ initialise current namespace |
||
sp←⎕NEW Causeway.SharpPlot |
sp←⎕NEW Causeway.SharpPlot |
||
sp.DrawPolarChart {⍵(360|⍵)}⌽⍳720 |
sp.DrawPolarChart {⍵(360|⍵)}⌽⍳720 |
||
View sp</ |
View sp</syntaxhighlight> |
||
[https://i.imgur.com/hZDqjjM.png See the plot on imgur.] |
[https://i.imgur.com/hZDqjjM.png See the plot on imgur.] |
||
Line 250: | Line 250: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
Requires [https://github.com/tariqporter/Gdip GDIP] |
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 |
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system |
||
Line 300: | Line 300: | ||
Gdip_Shutdown(pToken) |
Gdip_Shutdown(pToken) |
||
ExitApp |
ExitApp |
||
Return</ |
Return</syntaxhighlight> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
< |
<syntaxhighlight lang=AWK> |
||
# syntax: GAWK -f ARCHIMEDEAN_SPIRAL.AWK |
# syntax: GAWK -f ARCHIMEDEAN_SPIRAL.AWK |
||
# converted from Applesoft BASIC |
# converted from Applesoft BASIC |
||
Line 339: | Line 339: | ||
function max(x,y) { return((x > y) ? x : y) } |
function max(x,y) { return((x > y) ? x : y) } |
||
function min(x,y) { return((x < y) ? x : y) } |
function min(x,y) { return((x < y) ? x : y) } |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 386: | Line 386: | ||
==={{header|AmigaBASIC}}=== |
==={{header|AmigaBASIC}}=== |
||
{{trans|Locomotive Basic}} |
{{trans|Locomotive Basic}} |
||
< |
<syntaxhighlight lang=amigabasic>a=1.5 |
||
b=1.5 |
b=1.5 |
||
pi=3.141592 |
pi=3.141592 |
||
Line 394: | Line 394: | ||
r=a+b*t |
r=a+b*t |
||
LINE -(320+2*r*SIN(t),100+r*COS(t)) |
LINE -(320+2*r*SIN(t),100+r*COS(t)) |
||
NEXT</ |
NEXT</syntaxhighlight> |
||
==={{header|Applesoft BASIC}}=== |
==={{header|Applesoft BASIC}}=== |
||
< |
<syntaxhighlight lang=ApplesoftBasic>110 LET H = 96 |
||
120 LET W = H + H / 2 |
120 LET W = H + H / 2 |
||
130 HGR2 |
130 HGR2 |
||
Line 416: | Line 416: | ||
280 HPLOT X,Y |
280 HPLOT X,Y |
||
290 NEXT |
290 NEXT |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
< |
<syntaxhighlight lang=BASIC256> |
||
# Basic-256 ver 1.1.4 |
# Basic-256 ver 1.1.4 |
||
# Archimedean Spiral |
# Archimedean Spiral |
||
Line 452: | Line 452: | ||
imgsave "spiral-Basic-256.png", "PNG" |
imgsave "spiral-Basic-256.png", "PNG" |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 459: | Line 459: | ||
==={{header|Commodore BASIC}}=== |
==={{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. |
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 |
2 REM USING COMMODORE BASIC 7.0 |
||
3 REM OF THE COMMODORE 128 |
3 REM OF THE COMMODORE 128 |
||
Line 473: | Line 473: | ||
90 X0 = X : Y0 = Y |
90 X0 = X : Y0 = Y |
||
100 NEXT T |
100 NEXT T |
||
110 GOTO 110</ |
110 GOTO 110</syntaxhighlight> |
||
==={{header|FreeBASIC}}=== |
==={{header|FreeBASIC}}=== |
||
< |
<syntaxhighlight lang=freebasic>' version 16-10-2016 |
||
' compile with: fbc -s gui |
' compile with: fbc -s gui |
||
Line 501: | Line 501: | ||
Print : Print "hit any key to end program" |
Print : Print "hit any key to end program" |
||
Sleep |
Sleep |
||
End</ |
End</syntaxhighlight> |
||
==={{header|GW-BASIC}}=== |
==={{header|GW-BASIC}}=== |
||
< |
<syntaxhighlight lang=gwbasic>10 A = 0 |
||
20 B = 1 |
20 B = 1 |
||
30 SCREEN 1 |
30 SCREEN 1 |
||
Line 515: | Line 515: | ||
100 IF INKEY$="" THEN GOTO 100 |
100 IF INKEY$="" THEN GOTO 100 |
||
110 SCREEN 2:SCREEN 0 |
110 SCREEN 2:SCREEN 0 |
||
120 END</ |
120 END</syntaxhighlight> |
||
==={{header|IS-BASIC}}=== |
==={{header|IS-BASIC}}=== |
||
< |
<syntaxhighlight lang=IS-BASIC>100 GRAPHICS LORES 2 |
||
110 OPTION ANGLE DEGREES |
110 OPTION ANGLE DEGREES |
||
120 PLOT 640,360,ANGLE 90; |
120 PLOT 640,360,ANGLE 90; |
||
130 FOR I=2 TO 33.2 STEP .05 |
130 FOR I=2 TO 33.2 STEP .05 |
||
140 PLOT FORWARD I,LEFT 5; |
140 PLOT FORWARD I,LEFT 5; |
||
150 NEXT</ |
150 NEXT</syntaxhighlight> |
||
==={{header|Locomotive Basic}}=== |
==={{header|Locomotive Basic}}=== |
||
{{trans|Commodore BASIC}} |
{{trans|Commodore BASIC}} |
||
< |
<syntaxhighlight lang=locobasic>10 a=1.5:b=2 |
||
20 mode 2:rad:move 320,200 |
20 mode 2:rad:move 320,200 |
||
30 for t=0 to 40*pi step 0.2 |
30 for t=0 to 40*pi step 0.2 |
||
Line 533: | Line 533: | ||
50 draw r*sin(t)+320,r*cos(t)+200 |
50 draw r*sin(t)+320,r*cos(t)+200 |
||
60 next |
60 next |
||
70 while inkey$="":wend</ |
70 while inkey$="":wend</syntaxhighlight> |
||
==={{header|Run BASIC}}=== |
==={{header|Run BASIC}}=== |
||
< |
<syntaxhighlight lang=Run BASIC> 'archimedean spiral.bas |
||
'runs in Run Basic |
'runs in Run Basic |
||
'Run Basic website http://www.runbasic.com |
'Run Basic website http://www.runbasic.com |
||
Line 562: | Line 562: | ||
print "Thank you and Goodbye" |
print "Thank you and Goodbye" |
||
end |
end |
||
End</ |
End</syntaxhighlight> |
||
==={{header|QBasic}}=== |
==={{header|QBasic}}=== |
||
< |
<syntaxhighlight lang=qbasic>SCREEN 12 |
||
WINDOW (-2.67, -2!)-(2.67, 2!) |
WINDOW (-2.67, -2!)-(2.67, 2!) |
||
PI = 4 * ATN(1) |
PI = 4 * ATN(1) |
||
Line 576: | Line 576: | ||
Y = (A + B * T) * SIN(T) |
Y = (A + B * T) * SIN(T) |
||
LINE -(X, Y) |
LINE -(X, Y) |
||
NEXT</ |
NEXT</syntaxhighlight> |
||
==={{header|Sinclair ZX81 BASIC}}=== |
==={{header|Sinclair ZX81 BASIC}}=== |
||
{{trans|Applesoft BASIC}} |
{{trans|Applesoft BASIC}} |
||
Works with the unexpanded (1k RAM) ZX81. The output is quite blocky, but identifiably a spiral. |
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 |
20 LET B=0.7 |
||
30 FOR T=0 TO 7*PI STEP 0.05 |
30 FOR T=0 TO 7*PI STEP 0.05 |
||
40 LET R=A+B*T |
40 LET R=A+B*T |
||
50 PLOT R*COS T+32,R*SIN T+22 |
50 PLOT R*COS T+32,R*SIN T+22 |
||
60 NEXT T</ |
60 NEXT T</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Screenshot [http://edmundgriffiths.com/zx81archspiral.jpg here]. |
Screenshot [http://edmundgriffiths.com/zx81archspiral.jpg here]. |
||
Line 593: | Line 593: | ||
The BQN online REPL supports some basic plotting functionality through <code>•Plot</code>. This is used to create a spiral plotting function: |
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. |
When called with argument 200, it is similar to the given example diagram. |
||
Line 603: | Line 603: | ||
=={{header|C}}== |
=={{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. |
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<graphics.h> |
||
#include<stdio.h> |
#include<stdio.h> |
||
Line 636: | Line 636: | ||
closegraph(); |
closegraph(); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang=csharp>using System; |
||
using System.Linq; |
using System.Linq; |
||
using System.Drawing; |
using System.Drawing; |
||
Line 679: | Line 679: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|C++}}== |
=={{header|C++}}== |
||
[[File:SpiralCpp.png|200px|thumb|right]] |
[[File:SpiralCpp.png|200px|thumb|right]] |
||
< |
<syntaxhighlight lang=cpp> |
||
#include <windows.h> |
#include <windows.h> |
||
#include <string> |
#include <string> |
||
Line 794: | Line 794: | ||
spiral s; s.draw( 16, 8 ); return 0; |
spiral s; s.draw( 16, 8 ); return 0; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
{{Works with| Incanter}} |
{{Works with| Incanter}} |
||
< |
<syntaxhighlight lang=clojure> |
||
(use '(incanter core stats charts io)) |
(use '(incanter core stats charts io)) |
||
Line 814: | Line 814: | ||
(view (parametric-plot arq-spiral 0 (* 10 Math/PI))) |
(view (parametric-plot arq-spiral 0 (* 10 Math/PI))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> </pre> |
<pre> </pre> |
||
Line 821: | Line 821: | ||
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. |
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))) |
(let* ((min-x (apply #'min (mapcar #'car coords))) |
||
(min-y (apply #'min (mapcar #'cdr coords))) |
(min-y (apply #'min (mapcar #'cdr coords))) |
||
Line 891: | Line 891: | ||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FOCAL}}== |
=={{header|FOCAL}}== |
||
< |
<syntaxhighlight lang=FOCAL>1.1 S A=1.5 |
||
1.2 S B=2 |
1.2 S B=2 |
||
1.3 S N=250 |
1.3 S N=250 |
||
Line 910: | Line 910: | ||
4.1 S X2=R*FSIN(.2*(T+1)) |
4.1 S X2=R*FSIN(.2*(T+1)) |
||
4.2 S Y2=R*FCOS(.2*(T+1))</ |
4.2 S Y2=R*FCOS(.2*(T+1))</syntaxhighlight> |
||
This program uses FOCAL-11 on a DEC GT40 vector graphics terminal. |
This program uses FOCAL-11 on a DEC GT40 vector graphics terminal. |
||
Line 918: | Line 918: | ||
{{Works with|Frege|3.23.888}} |
{{Works with|Frege|3.23.888}} |
||
< |
<syntaxhighlight lang=frege>module Archimedean where |
||
import Java.IO |
import Java.IO |
||
Line 1,006: | Line 1,006: | ||
drawSpiral g |
drawSpiral g |
||
f <- File.new "SpiralFrege.png" |
f <- File.new "SpiralFrege.png" |
||
void $ ImageIO.write buffy "png" f</ |
void $ ImageIO.write buffy "png" f</syntaxhighlight> |
||
Output is [http://funwithsoftware.org/images/2016-SpiralFrege.png here] due to [[User talk:Short Circuit#Is file uploading blocked forever?|Is file uploading blocked forever?]] |
Output is [http://funwithsoftware.org/images/2016-SpiralFrege.png here] due to [[User talk:Short Circuit#Is file uploading blocked forever?|Is file uploading blocked forever?]] |
||
Line 1,013: | Line 1,013: | ||
{{works with|go|1.9}} |
{{works with|go|1.9}} |
||
Creates a PNG file using only built-in packages. |
Creates a PNG file using only built-in packages. |
||
< |
<syntaxhighlight lang=go>package main |
||
import ( |
import ( |
||
Line 1,060: | Line 1,060: | ||
log.Fatal(err) |
log.Fatal(err) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Line 1,067: | Line 1,067: | ||
{{libheader|Juicy.Pixels}} |
{{libheader|Juicy.Pixels}} |
||
{{libheader|Rasterific}} |
{{libheader|Rasterific}} |
||
< |
<syntaxhighlight lang=haskell>#!/usr/bin/env stack |
||
-- stack --resolver lts-7.0 --install-ghc runghc --package Rasterific --package JuicyPixels |
-- stack --resolver lts-7.0 --install-ghc runghc --package Rasterific --package JuicyPixels |
||
Line 1,093: | Line 1,093: | ||
polyline points |
polyline points |
||
writePng "SpiralHaskell.png" img</ |
writePng "SpiralHaskell.png" img</syntaxhighlight> |
||
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?]] |
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 1,099: | Line 1,099: | ||
=={{header|J}}== |
=={{header|J}}== |
||
[[File:Archimedian spiral j.png|200px|thumb|right]] |
[[File:Archimedian spiral j.png|200px|thumb|right]] |
||
< |
<syntaxhighlight lang=j>require'plot' |
||
'aspect 1' plot (*^)j.0.01*i.1400</ |
'aspect 1' plot (*^)j.0.01*i.1400</syntaxhighlight> |
||
<div style="clear:both"></div> |
<div style="clear:both"></div> |
||
Line 1,107: | Line 1,107: | ||
[[File:archimedian_spiral.png|300px|thumb|right]] |
[[File:archimedian_spiral.png|300px|thumb|right]] |
||
{{works with|Java|8}} |
{{works with|Java|8}} |
||
< |
<syntaxhighlight lang=java>import java.awt.*; |
||
import static java.lang.Math.*; |
import static java.lang.Math.*; |
||
import javax.swing.*; |
import javax.swing.*; |
||
Line 1,190: | Line 1,190: | ||
}); |
}); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Line 1,196: | Line 1,196: | ||
{{Works with|Chrome}} |
{{Works with|Chrome}} |
||
[[File:ASjs.png|200px|right|thumb|Output ASjs.png]] |
[[File:ASjs.png|200px|right|thumb|Output ASjs.png]] |
||
< |
<syntaxhighlight lang=html> |
||
<!-- ArchiSpiral.html --> |
<!-- ArchiSpiral.html --> |
||
<html> |
<html> |
||
Line 1,221: | Line 1,221: | ||
} |
} |
||
</script></body></html> |
</script></body></html> |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Output}} |
{{Output}} |
||
<pre> |
<pre> |
||
Line 1,231: | Line 1,231: | ||
Assumes the same HTML canvas embedding as above, but is functionally composed. |
Assumes the same HTML canvas embedding as above, but is functionally composed. |
||
Defines and logs a set of points, before rendering them to canvas. |
Defines and logs a set of points, before rendering them to canvas. |
||
< |
<syntaxhighlight lang=html><html> |
||
<head> |
<head> |
||
<title>Archimedean spiral</title> |
<title>Archimedean spiral</title> |
||
Line 1,239: | Line 1,239: | ||
<h3>Archimedean spiral</h3></p> |
<h3>Archimedean spiral</h3></p> |
||
<canvas id="spiral" width="640" height="640" style="border: 2px outset;"></canvas> |
<canvas id="spiral" width="640" height="640" style="border: 2px outset;"></canvas> |
||
<script></ |
<script></syntaxhighlight> |
||
< |
<syntaxhighlight lang=javascript>const main = strColor => intCycles => { |
||
const |
const |
||
ai = 0.05, |
ai = 0.05, |
||
Line 1,272: | Line 1,272: | ||
Array.from({ |
Array.from({ |
||
length: 1 + n - m |
length: 1 + n - m |
||
}, (_, i) => m + i);</ |
}, (_, i) => m + i);</syntaxhighlight> |
||
< |
<syntaxhighlight lang=html></script></body></html></syntaxhighlight> |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
Line 1,279: | Line 1,279: | ||
'''Works with gojq, the Go implementation of jq''' |
'''Works with gojq, the Go implementation of jq''' |
||
====SVG version==== |
====SVG version==== |
||
< |
<syntaxhighlight lang=jq>def spiral($zero; $turns; $step): |
||
def pi: 1 | atan * 4; |
def pi: 1 | atan * 4; |
||
Line 1,304: | Line 1,304: | ||
spiral(0; 10; 0.025) |
spiral(0; 10; 0.025) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,312: | Line 1,312: | ||
====ASCII Art Version==== |
====ASCII Art Version==== |
||
{{trans|awk}} |
{{trans|awk}} |
||
< |
<syntaxhighlight lang=jq>def spiral($a; $b; $step; $h): |
||
def min($x;$y): if $x <= $y then $x else $y end; |
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 max($x;$y): if $x <= $y then $y else $x end; |
||
Line 1,342: | Line 1,342: | ||
| "\(.)\n" ; |
| "\(.)\n" ; |
||
spiral(1; 1; 0.02; 96)</ |
spiral(1; 1; 0.02; 96)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
As for [[#awk|awk]]. |
As for [[#awk|awk]]. |
||
Line 1,349: | Line 1,349: | ||
{{works with|Julia|0.6}} |
{{works with|Julia|0.6}} |
||
< |
<syntaxhighlight lang=julia>using UnicodePlots |
||
spiral(θ, a=0, b=1) = @. b * θ * cos(θ + a), b * θ * sin(θ + a) |
spiral(θ, a=0, b=1) = @. b * θ * cos(θ + a), b * θ * sin(θ + a) |
||
x, y = spiral(1:0.1:10) |
x, y = spiral(1:0.1:10) |
||
println(lineplot(x, y))</ |
println(lineplot(x, y))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,379: | Line 1,379: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang=scala>// version 1.1.0 |
||
import java.awt.* |
import java.awt.* |
||
Line 1,454: | Line 1,454: | ||
f.isVisible = true |
f.isVisible = true |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
{{libheader|LÖVE}} |
{{libheader|LÖVE}} |
||
{{works with|LÖVE|11.3}} |
{{works with|LÖVE|11.3}} |
||
< |
<syntaxhighlight lang=Lua> |
||
a=1 |
a=1 |
||
b=2 |
b=2 |
||
Line 1,480: | Line 1,480: | ||
end |
end |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
< |
<syntaxhighlight lang=M2000 Interpreter> |
||
module Archimedean_spiral { |
module Archimedean_spiral { |
||
smooth on ' enable GDI+ |
smooth on ' enable GDI+ |
||
Line 1,510: | Line 1,510: | ||
} |
} |
||
Archimedean_spiral |
Archimedean_spiral |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
< |
<syntaxhighlight lang=Maple> |
||
plots[polarplot](1+2*theta, theta = 0 .. 6*Pi) |
plots[polarplot](1+2*theta, theta = 0 .. 6*Pi) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
The built-in function PolarPlot easily creates the desired plot |
The built-in function PolarPlot easily creates the desired plot |
||
< |
<syntaxhighlight lang=Mathematica>With[{a = 5, b = 4}, PolarPlot[a + b t, {t, 0, 10 Pi}]]</syntaxhighlight> |
||
=={{header|MATLAB}}== |
=={{header|MATLAB}}== |
||
< |
<syntaxhighlight lang=MATLAB>a = 1; |
||
b = 1; |
b = 1; |
||
turns = 2; |
turns = 2; |
||
theta = 0:0.1:2*turns*pi; |
theta = 0:0.1:2*turns*pi; |
||
polarplot(theta, a + b*theta);</ |
polarplot(theta, a + b*theta);</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{libheader|gintro}} |
{{libheader|gintro}} |
||
< |
<syntaxhighlight lang=Nim>import math |
||
import gintro/[glib, gobject, gtk, gio, cairo] |
import gintro/[glib, gobject, gtk, gio, cairo] |
||
Line 1,603: | Line 1,603: | ||
let app = newApplication(Application, "Rosetta.spiral") |
let app = newApplication(Application, "Rosetta.spiral") |
||
discard app.connect("activate", activate) |
discard app.connect("activate", activate) |
||
discard app.run()</ |
discard app.run()</syntaxhighlight> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Line 1,611: | Line 1,611: | ||
[[File:ArchiSpiral2.png|right|thumb|Output ArchiSpiral2.png]] |
[[File:ArchiSpiral2.png|right|thumb|Output ArchiSpiral2.png]] |
||
< |
<syntaxhighlight lang=parigp> |
||
\\ The Archimedean spiral |
\\ The Archimedean spiral |
||
\\ ArchiSpiral() - Where: lps is a number of loops, c is a direction 0/1 |
\\ ArchiSpiral() - Where: lps is a number of loops, c is a direction 0/1 |
||
Line 1,631: | Line 1,631: | ||
ArchiSpiral(640,5,1); \\ArchiSpiral2.png |
ArchiSpiral(640,5,1); \\ArchiSpiral2.png |
||
} |
} |
||
</ |
</syntaxhighlight> |
||
{{Output}} |
{{Output}} |
||
Line 1,644: | Line 1,644: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang=Perl>use Imager; |
||
use constant PI => 3.14159265; |
use constant PI => 3.14159265; |
||
Line 1,657: | Line 1,657: | ||
$img->write(file => 'Archimedean-spiral.png'); |
$img->write(file => 'Archimedean-spiral.png'); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,664: | Line 1,664: | ||
{{libheader|Phix/online}} |
{{libheader|Phix/online}} |
||
You can run this online [http://phix.x10.mx/p2js/Archimedean_spiral.htm here]. |
You can run this online [http://phix.x10.mx/p2js/Archimedean_spiral.htm here]. |
||
<!--< |
<!--<syntaxhighlight lang=Phix>(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\Archimedean_spiral.exw |
-- demo\rosetta\Archimedean_spiral.exw |
||
Line 1,713: | Line 1,713: | ||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
Line 1,720: | Line 1,720: | ||
====with points==== |
====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. |
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>float x, y; |
||
float theta; |
float theta; |
||
float rotation; |
float rotation; |
||
Line 1,739: | Line 1,739: | ||
// check restart |
// check restart |
||
if (x>width/2.0) frameCount=-1; |
if (x>width/2.0) frameCount=-1; |
||
}</ |
}</syntaxhighlight> |
||
====with points, rotated==== |
====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(). |
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>float theta; |
||
float rotation; |
float rotation; |
||
Line 1,760: | Line 1,760: | ||
// check restart |
// check restart |
||
if (theta>width/2.0) frameCount=-1; |
if (theta>width/2.0) frameCount=-1; |
||
}</ |
}</syntaxhighlight> |
||
====with points, vector==== |
====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(). |
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>PVector pv; |
||
float rotation; |
float rotation; |
||
Line 1,782: | Line 1,782: | ||
// check restart |
// check restart |
||
if (pv.mag()>width/2.0) frameCount=-1; |
if (pv.mag()>width/2.0) frameCount=-1; |
||
}</ |
}</syntaxhighlight> |
||
====with line segments==== |
====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. |
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>float px, py, x, y; |
||
float theta; |
float theta; |
||
float rotation; |
float rotation; |
||
Line 1,807: | Line 1,807: | ||
// check restart |
// check restart |
||
if (px>width/2.0) frameCount=-1; |
if (px>width/2.0) frameCount=-1; |
||
}</ |
}</syntaxhighlight> |
||
====with line segments, rotated==== |
====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. |
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>float x, y, px, py; |
||
float theta; |
float theta; |
||
float rotation; |
float rotation; |
||
Line 1,836: | Line 1,836: | ||
py = y; |
py = y; |
||
if (theta>width/2.0) frameCount=-1; // start over |
if (theta>width/2.0) frameCount=-1; // start over |
||
}</ |
}</syntaxhighlight> |
||
==={{header|Processing Python mode}}=== |
==={{header|Processing Python mode}}=== |
||
====with points==== |
====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. |
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 |
rotation = 0.1 |
||
Line 1,858: | Line 1,858: | ||
if x > width / 2.0: |
if x > width / 2.0: |
||
background(255) |
background(255) |
||
theta = 0</ |
theta = 0</syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang=PureBasic>#MAXLOOP = 7*360 |
||
#XCENTER = 640/2 |
#XCENTER = 640/2 |
||
#YCENTER = 480/2 |
#YCENTER = 480/2 |
||
Line 1,882: | Line 1,882: | ||
Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow |
Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow |
||
EndIf |
EndIf |
||
End</ |
End</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Using the '''turtle''' module. |
Using the '''turtle''' module. |
||
< |
<syntaxhighlight lang=python>from turtle import * |
||
from math import * |
from math import * |
||
color("blue") |
color("blue") |
||
Line 1,897: | Line 1,897: | ||
goto(x, y) |
goto(x, y) |
||
up() |
up() |
||
done()</ |
done()</syntaxhighlight> |
||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
< |
<syntaxhighlight lang=Quackery> [ $ "turtleduck.qky" loadfile ] now! |
||
turtle |
turtle |
||
0 n->v |
0 n->v |
||
Line 1,908: | Line 1,908: | ||
1 20 v+ |
1 20 v+ |
||
1 36 turn ] |
1 36 turn ] |
||
2drop</ |
2drop</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,915: | Line 1,915: | ||
=={{header|R}}== |
=={{header|R}}== |
||
< |
<syntaxhighlight lang=r>with(list(s=seq(0, 10 * pi, length.out=500)), |
||
plot((1 + s) * exp(1i * s), type="l"))</ |
plot((1 + s) * exp(1i * s), type="l"))</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
[[File:archemedian-spiral-racket.png]] |
[[File:archemedian-spiral-racket.png]] |
||
< |
<syntaxhighlight lang=racket>#lang racket/base |
||
(require plot |
(require plot |
||
racket/math) |
racket/math) |
||
Line 1,942: | Line 1,942: | ||
;; writes to a file so hopefully, I can post it to RC... |
;; writes to a file so hopefully, I can post it to RC... |
||
(plot-file (list (archemedian-spiral-renderer2d 0.0 24 4)) |
(plot-file (list (archemedian-spiral-renderer2d 0.0 24 4)) |
||
"images/archemidian-spiral-racket.png")</ |
"images/archemidian-spiral-racket.png")</syntaxhighlight> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 1,948: | Line 1,948: | ||
{{works with|Rakudo|2018.10}} |
{{works with|Rakudo|2018.10}} |
||
< |
<syntaxhighlight lang=perl6>use Image::PNG::Portable; |
||
my ($w, $h) = (400, 400); |
my ($w, $h) = (400, 400); |
||
Line 1,958: | Line 1,958: | ||
} |
} |
||
$png.write: 'Archimedean-spiral-perl6.png';</ |
$png.write: 'Archimedean-spiral-perl6.png';</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 1,964: | Line 1,964: | ||
Note: the value of <big><big> ''a'' </big></big> doesn't mean that much as the plot is automatically centered. |
Note: the value of <big><big> ''a'' </big></big> 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*/ |
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.*/ |
if cy=='' | cy=="," then cy= 3 /*Not specified? Then use the default.*/ |
||
Line 2,005: | Line 2,005: | ||
if x=pi * .5 then return 1; if x==pi*1.5 then return -1 |
if x=pi * .5 then return 1; if x==pi*1.5 then return -1 |
||
if abs(x)=pi | x=0 then return 0; q= x*x; z= x |
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</ |
do k=2 by 2 until p=z; p= z; _= -_ *q/(k*k+k); z= z+_; end; return z</syntaxhighlight> |
||
{{out|output|text= when using the following inputs: <tt> 13 , 5 , db </tt>}} |
{{out|output|text= when using the following inputs: <tt> 13 , 5 , db </tt>}} |
||
Line 2,205: | Line 2,205: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang=ring> |
||
/* |
/* |
||
+--------------------------------------------------------------------------------------------------------- |
+--------------------------------------------------------------------------------------------------------- |
||
Line 2,310: | Line 2,310: | ||
return |
return |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Line 2,316: | Line 2,316: | ||
{{libheader|JRubyArt}} |
{{libheader|JRubyArt}} |
||
JRubyArt is an implementation of Processing in ruby, that uses JRuby to provide the interoperability with the java libraries. |
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 |
INCR = 0.1 |
||
attr_reader :x, :theta |
attr_reader :x, :theta |
||
Line 2,337: | Line 2,337: | ||
size(300, 300) |
size(300, 300) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang=rust>#[macro_use(px)] |
||
extern crate bmp; |
extern crate bmp; |
||
Line 2,371: | Line 2,371: | ||
// Save the image |
// Save the image |
||
let _ = img.save("archimedean_spiral.bmp").unwrap_or_else(|e| panic!("Failed to save: {}", e)); |
let _ = img.save("archimedean_spiral.bmp").unwrap_or_else(|e| panic!("Failed to save: {}", e)); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|SAS}}== |
=={{header|SAS}}== |
||
< |
<syntaxhighlight lang=sas>data xy; |
||
h=constant('pi')/40; |
h=constant('pi')/40; |
||
do i=0 to 400; |
do i=0 to 400; |
||
Line 2,387: | Line 2,387: | ||
proc sgplot; |
proc sgplot; |
||
series x=x y=y; |
series x=x y=y; |
||
run;</ |
run;</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
===Java Swing Interoperability=== |
===Java Swing Interoperability=== |
||
< |
<syntaxhighlight lang=Scala> |
||
object ArchimedeanSpiral extends App { |
object ArchimedeanSpiral extends App { |
||
Line 2,458: | Line 2,458: | ||
) |
) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
{{libheader|Scheme/PsTk}} |
{{libheader|Scheme/PsTk}} |
||
< |
<syntaxhighlight lang=scheme> |
||
(import (scheme base) |
(import (scheme base) |
||
(scheme complex) |
(scheme complex) |
||
Line 2,498: | Line 2,498: | ||
(draw-spiral canvas)) |
(draw-spiral canvas)) |
||
(tk-event-loop tk)) |
(tk-event-loop tk)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Scilab}}== |
=={{header|Scilab}}== |
||
Line 2,518: | Line 2,518: | ||
scf(2); |
scf(2); |
||
plot2d(x,y);</ |
plot2d(x,y);</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
< |
<syntaxhighlight lang=seed7>$ include "seed7_05.s7i"; |
||
include "draw.s7i"; |
include "draw.s7i"; |
||
include "keybd.s7i"; |
include "keybd.s7i"; |
||
Line 2,548: | Line 2,548: | ||
DRAW_FLUSH; |
DRAW_FLUSH; |
||
ignore(getc(KEYBOARD)); |
ignore(getc(KEYBOARD)); |
||
end func;</ |
end func;</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang=ruby>require('Imager') |
||
define π = Num.pi |
define π = Num.pi |
||
Line 2,566: | Line 2,566: | ||
} |
} |
||
img.write(file => 'Archimedean_spiral.png')</ |
img.write(file => 'Archimedean_spiral.png')</syntaxhighlight> |
||
Output image: [https://github.com/trizen/rc/blob/master/img/archimedean-spiral-sidef.png Archimedean spiral] |
Output image: [https://github.com/trizen/rc/blob/master/img/archimedean-spiral-sidef.png Archimedean spiral] |
||
=={{header|Stata}}== |
=={{header|Stata}}== |
||
< |
<syntaxhighlight lang=stata>clear all |
||
scalar h=_pi/40 |
scalar h=_pi/40 |
||
set obs 400 |
set obs 400 |
||
Line 2,576: | Line 2,576: | ||
gen x=(1+t)*cos(t) |
gen x=(1+t)*cos(t) |
||
gen y=(1+t)*sin(t) |
gen y=(1+t)*sin(t) |
||
line y x</ |
line y x</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{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`: |
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>package require Tk |
||
# create widgets |
# create widgets |
||
Line 2,645: | Line 2,645: | ||
update ;# lay out widgets before trying to draw |
update ;# lay out widgets before trying to draw |
||
draw |
draw |
||
vwait forever ;# go into event loop until window is closed</ |
vwait forever ;# go into event loop until window is closed</syntaxhighlight> |
||
=={{header|VBA}}== |
=={{header|VBA}}== |
||
< |
<syntaxhighlight lang=vb>Private Sub plot_coordinate_pairs(x As Variant, y As Variant) |
||
Dim chrt As Chart |
Dim chrt As Chart |
||
Set chrt = ActiveSheet.Shapes.AddChart.Chart |
Set chrt = ActiveSheet.Shapes.AddChart.Chart |
||
Line 2,670: | Line 2,670: | ||
Next i |
Next i |
||
plot_coordinate_pairs x, y |
plot_coordinate_pairs x, y |
||
End Sub</ |
End Sub</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Sidef}} |
{{trans|Sidef}} |
||
{{libheader|DOME}} |
{{libheader|DOME}} |
||
< |
<syntaxhighlight lang=ecmascript>import "graphics" for Canvas, Color |
||
import "dome" for Window |
import "dome" for Window |
||
Line 2,702: | Line 2,702: | ||
static draw(dt) {} |
static draw(dt) {} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
Looks a lot like the C++ image. |
Looks a lot like the C++ image. |
||
< |
<syntaxhighlight lang=XPL0>real A, B, R, T, X, Y; |
||
[SetVid($12); \set 640x480 graphics |
[SetVid($12); \set 640x480 graphics |
||
A:= 0.0; B:= 3.0; T:= 0.0; |
A:= 0.0; B:= 3.0; T:= 0.0; |
||
Line 2,715: | Line 2,715: | ||
T:= T + 0.03; \increase angle (Theta) |
T:= T + 0.03; \increase angle (Theta) |
||
until T >= 314.159; \50 revs |
until T >= 314.159; \50 revs |
||
]</ |
]</syntaxhighlight> |
||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
{{trans|Sinclair_ZX81_BASIC}} |
{{trans|Sinclair_ZX81_BASIC}} |
||
< |
<syntaxhighlight lang=Yabasic>5 OPEN WINDOW 320, 200 : WINDOW ORIGIN "CC" |
||
10 LET A=1.5 |
10 LET A=1.5 |
||
20 LET B=0.7 |
20 LET B=0.7 |
||
Line 2,725: | Line 2,725: | ||
40 LET R=A+B*T |
40 LET R=A+B*T |
||
50 LINE TO R*COS(T),R*SIN(T) |
50 LINE TO R*COS(T),R*SIN(T) |
||
60 NEXT T</ |
60 NEXT T</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
[[File:ArchimedeanSpiral.zk.jpg|250px|thumb|right]] |
[[File:ArchimedeanSpiral.zk.jpg|250px|thumb|right]] |
||
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
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; |
w,h:=640,640; centerX,centerY:=w/2,h/2; |
||
bitmap:=PPM(w+1,h+1,0xFF|FF|FF); // White background |
bitmap:=PPM(w+1,h+1,0xFF|FF|FF); // White background |
||
Line 2,741: | Line 2,741: | ||
} |
} |
||
bitmap.writeJPGFile("archimedeanSpiral.jpg"); |
bitmap.writeJPGFile("archimedeanSpiral.jpg"); |
||
}(0,5,7);</ |
}(0,5,7);</syntaxhighlight> |