Archimedean spiral: Difference between revisions

m
Replace deprecated functions
m (Replace deprecated functions)
 
(33 intermediate revisions by 14 users not shown)
Line 236:
=={{header|Amazing Hopper}}==
{{Trans|AmigaBASIC}}
[[File:Captura_de_pantalla_de_2022-10-07_22-57-32.png|200px|thumb|right]]
<syntaxhighlight lang="ada">
<syntaxhighlight lang="c">
#include <jambo.h>
 
Line 282 ⟶ 283:
rxvt -g 500x250 -fn "xft:FantasqueSansMono-Regular:pixelsize=1" -e hopper jm/archi.jambo
</pre>
 
[[File:Captura_de_pantalla_de_2022-10-07_22-57-32.png]]
 
=={{header|APL}}==
Line 499 ⟶ 498:
 
imgsave "spiral-Basic-256.png", "PNG"
</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>
 
Line 562 ⟶ 581:
Sleep
End</syntaxhighlight>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">
_maxPoints = 190
 
void local fn DoIt
window 1, @"Archimedean Spiral", (0,0,500,500)
WindowSetBackgroundColor( 1, fn ColorBlack )
pen 3, fn ColorRed
float x, y, angle
long i, a = 10, b = 10, x1 = 250, y1 = 250
for i = 0 to _maxPoints - 1
angle = 0.1 * i
x = (a + b * angle) * cos(angle) + 250
y = (a + b * angle) * sin(angle) + 250
line x1,y1 to x,y
x1 = x : y1 = y
next
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:ArchimedeanSpiralFB.png]]
 
==={{header|GW-BASIC}}===
Line 957 ⟶ 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 1,035 ⟶ 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>
 
Line 1,153 ⟶ 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}}==
Line 1,599 ⟶ 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}}==
Line 1,671 ⟶ 1,850:
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}}==
Line 2,022 ⟶ 2,243:
<syntaxhighlight lang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
turtle
20 frames
0 n->v
900 times
Line 2,027 ⟶ 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}}==
Line 2,430 ⟶ 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,665 ⟶ 2,900:
theta +:= delta;
end while;
DRAW_FLUSHflushGraphic;
ignore(getc(KEYBOARD));
end func;</syntaxhighlight>
Line 2,769 ⟶ 3,004:
{{trans|Sidef}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
 
Line 2,797 ⟶ 3,032:
static draw(dt) {}
}</syntaxhighlight>
 
{{out}}
[[File:Wren-Archimedean_spiral.png]]
 
=={{header|XPL0}}==
28

edits