Polyspiral: Difference between revisions

29,000 bytes added ,  4 months ago
m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(16 intermediate revisions by 13 users not shown)
Line 34:
 
<br><br>
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<syntaxhighlight lang="action!">INCLUDE "H6:REALMATH.ACT"
 
INT ARRAY SinTab=[
0 4 9 13 18 22 27 31 36 40 44 49 53 58 62 66 71 75 79 83
88 92 96 100 104 108 112 116 120 124 128 132 136 139 143
147 150 154 158 161 165 168 171 175 178 181 184 187 190
193 196 199 202 204 207 210 212 215 217 219 222 224 226
228 230 232 234 236 237 239 241 242 243 245 246 247 248
249 250 251 252 253 254 254 255 255 255 256 256 256 256]
 
INT FUNC Sin(INT a)
WHILE a<0 DO a==+360 OD
WHILE a>360 DO a==-360 OD
IF a<=90 THEN
RETURN (SinTab(a))
ELSEIF a<=180 THEN
RETURN (SinTab(180-a))
ELSEIF a<=270 THEN
RETURN (-SinTab(a-180))
ELSE
RETURN (-SinTab(360-a))
FI
RETURN (0)
 
INT FUNC Cos(INT a)
RETURN (Sin(a-90))
 
PROC DrawSpiral(INT x0,y0)
INT i,angle,x,y,tmp
REAL rx,ry,len,dlen,r1,r2,r3,r256
 
IntToReal(x0,rx)
IntToReal(y0,ry)
ValR("1.9",len)
ValR("1.14",dlen)
IntToReal(256,r256)
angle=0
Plot(x0,y0)
FOR i=1 TO 150
DO
tmp=Cos(angle)
IntToRealForNeg(tmp,r1)
RealDiv(r1,r256,r2)
RealMult(r2,len,r1)
RealAdd(rx,r1,r2)
RealAssign(r2,rx)
 
tmp=Sin(angle)
IntToRealForNeg(tmp,r1)
RealDiv(r1,r256,r2)
RealMult(r2,len,r1)
RealAdd(ry,r1,r2)
RealAssign(r2,ry)
 
x=RealToInt(rx)
y=RealToInt(ry)
DrawTo(x,y)
 
RealAdd(len,dlen,r1)
RealAssign(r1,len)
angle==+123
IF angle>360 THEN
angle==-360
FI
OD
RETURN
 
PROC Main()
BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
 
Graphics(8+16)
Color=1
COLOR1=$0C
COLOR2=$02
 
DrawSpiral(160,96)
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Polyspiral.png Screenshot from Atari 8-bit computer]
 
=={{header|AutoHotkey}}==
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
<syntaxhighlight lang="autohotkey">If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
gdip1()
incr := 0
π := 3.141592653589793
loop
{
incr := Mod(incr + 0.05, 360)
x1 := Width/2
y1 := Height/2
length := 5
angle := incr
Gdip_FillRoundedRectangle(G, pBrush, 0, 0, Width, Height, 0)
loop 150
{
x2 := x1 + length * Cos(angle * π/180)
y2 := y1 + length * Sin(angle * π/180)
Gdip_DrawLine(G, pPen, x1, y1, x2, y2)
x1 := x2
y1 := y2
length := length + 3
angle := Mod(angle + incr, 360)
}
UpdateLayeredWindow(hwnd1, hdc, -1, -1, Width, Height)
Sleep 25
}
return
;----------------------------------------------------------------
Esc:: Pause, toggle
^Esc::ExitApp
;----------------------------------------------------------------
gdip1(){
global
Width := A_ScreenWidth+1, Height := A_ScreenHeight+1
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pBrush := Gdip_BrushCreateSolid("0xFF000000")
pPen := Gdip_CreatePen("0xFF00FF00", 1)
}
;----------------------------------------------------------------
gdip2(){
global
Gdip_DeletePen(pPen)
Gdip_DeleteBrush(pBrush)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
}
;----------------------------------------------------------------
Exit:
gdip2()
Gdip_Shutdown(pToken)
ExitApp
Return
;----------------------------------------------------------------</syntaxhighlight>
 
=={{header|C}}==
Straightforward implementation of the pseudocode, incr and angle are integers and incr is incremented by 5 instead of 0.05 as the % operation in C is not defined for non-integers. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
<lang C>
#include<graphics.h>
#include<math.h>
Line 84 ⟶ 240:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Drawing.Drawing2D;
Line 150 ⟶ 306:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
This Windows programm has no animation, it will simply save 100 bitmaps onto your harddrive
<langsyntaxhighlight lang="cpp">
#include <windows.h>
#include <sstream>
Line 298 ⟶ 454:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|Ceylon}}==
Be sure to import javafx.graphics and ceylon.numeric in your module.ceylon file.
<langsyntaxhighlight lang="ceylon">import javafx.application {
Application
}
Line 382 ⟶ 538:
primaryStage.show();
}
}</langsyntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
[[File:DelphiSpiralAnimaion.png|frame|none]]
 
 
<syntaxhighlight lang="Delphi">
 
 
procedure PolySpiral(Image: TImage);
var Step,Angle,LineLen,I: integer;
var X,Y,X1,Y1: double;
begin
AbortFlag:=False;
ClearImage(Image,clBlack);
Image.Canvas.Pen.Width:=1;
while true do
begin
Image.Canvas.Pen.Color:=clYellow;
Step:=(Step + 5) mod 360;
X:=Image.Width/2;
Y:=Image.Height/2;
 
LineLen:=5;
angle:=Step;
for I:=1 to 150 do
begin
X1:=X + LineLen*cos(DegToRad(angle));
Y1:=Y + LineLen*sin(DegToRad(angle));
Image.Canvas.MoveTo(Round(X),Round(Y));
Image.Canvas.LIneTo(Round(X1),Round(Y1));
Image.Repaint;
 
LineLen:=LineLen+2;
 
Angle:=(Angle + Step) mod 360;
X:=X1;
Y:=Y1;
end;
if Application.Terminated then exit;
if AbortFlag then break;
Sleep(1200);
Application.ProcessMessages;
WaitForButton;
ClearImage(Image,clBlack);
end;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
 
</pre>
 
=={{header|EasyLang}}==
 
[https://easylang.dev/show/#cod=bU/LCsMgELz7FXtMKwTzKvSQjxFjU8GskIQ2/n13jekDenLGmR1mTPBhhmvbCu/QPt2w3kGVjQgIGt2kVysAwHirZwYOzQw9FOmV5FTdCaYwQHNRrG8VqV2C8QO9xZFye6iYaRy9JcIZzKfwsHwYk3qjOo6tsAao9nsOrumPTBJMWHLEOQdnS2RLZMvi8L+FN3JUrI9YLrkdLFV+a7m1zLW/mhc7kGnCz/5SlOIF Run it]
 
<syntaxhighlight lang="easylang">
color 944
linewidth 0.3
on animate
clear
incr = (incr + 0.05) mod 360
x1 = 50
y1 = 50
length = 1
angle = incr
move x1 y1
for i = 1 to 150
x2 = x1 + cos angle * length
y2 = y1 + sin angle * length
line x2 y2
x1 = x2
y1 = y2
length += 1
angle = (angle + incr) mod 360
.
.
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif
#define pi 4 * Atn(1)
#define Deg2Rad pi/180
 
Dim As Integer w = 900, h = w
Screenres w, h, 8
Windowtitle "Polyspiral"
 
Dim As Integer incr = 0, angulo, longitud, x1, y1, x2, y2, N
Do
incr += 1
x1 = w / 2
y1 = h / 2
Pset (Fix(x1), Fix(y1))
longitud = 5
angulo = incr
For N = 1 To 150
x2 = x1 + longitud * Cos(angulo * Deg2Rad)
y2 = y1 + longitud * Sin(angulo * Deg2Rad)
Line - (Fix(x2), Fix(y2)), N+16
x1 = x2
y1 = y2
longitud += 3
angulo += incr
Next N
Sleep 500
Cls
Loop Until Multikey(SC_ESCAPE)</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn DoIt
NSInteger i, t
double length, incr, x1, y1, x2, y2, twopi, angle, w, h
pen 2.0, fn ColorRed, NSLineCapStyleButt, NULL, 0
incr = 0 : twopi = 2 * pi
w = 600 : h = 600
t = 150
while ( t > 0 )
incr = ( incr + 0.05 mod twopi )
x1 = w / 2
y1 = h / 2
length = 1.0
angle = incr
line to x1, y1
cls
for i = 1 to 300
x2 = x1 + cos( angle ) * length
y2 = y1 + sin( angle ) * length
line to x1, y1 to x2, y2
x1 = x2 : y1 = y2
length = length + 1.0
angle = ( angle + incr mod twopi )
next
t--
wend
end fn
 
window 1, @"Rosetta Code Polyspiral", fn CGRectMake( 0, 0, 600, 600 )
WindowSetBackgroundColor( 1, fn ColorBlack )
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Polyspiral FutureBasic.png]]
 
 
 
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Polyspiral}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
 
[[File:Fōrmulæ - Polyspiral 01.png]]
 
'''Test cases'''
 
[[File:Fōrmulæ - Polyspiral 02.png]]
 
[[File:Fōrmulæ - Polyspiral 03.png]]
 
[[File:Fōrmulæ - Polyspiral 04.png]]
 
[[File:Fōrmulæ - Polyspiral 05.png]]
 
[[File:Fōrmulæ - Polyspiral 06.png]]
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Polyspiral 07.png]]
In '''[https://formulae.org/?example=Polyspiral this]''' page you can see the program(s) related to this task and their results.
 
=={{header|Gnuplot}}==
Line 397 ⟶ 728:
===Plotting a polyspiral file-function for the load command===
'''plotpoly.gp''' file for the load command is the only possible imitation of the fine function in the '''gnuplot'''.
<langsyntaxhighlight lang="gnuplot">
## plotpoly.gp 1/10/17 aev
## Plotting a polyspiral and writing to the png-file.
Line 413 ⟶ 744:
plot [0:c] t*cos(d*t), t*sin(d*t) lt rgb @clr
set output
</langsyntaxhighlight>
 
===Plotting many versions of a polyspiral.===
Line 424 ⟶ 755:
[[File:PS6gp.png|right|thumb|Output PS6gp.png]]
 
<langsyntaxhighlight lang="gnuplot">
## PSpirals.gp 1/10/17 aev
## Plotting many polyspiral pictures.
Line 527 ⟶ 858:
## Continue plotting starting with a range rng=110 to 400+ step 10 to discover new figures.
## END ##
</langsyntaxhighlight>
{{Output}}
<pre>
Line 536 ⟶ 867:
===Plotting a polyspiral file-function for the load command (for animation)===
'''plotpolya.gp''' file for the load command is the only possible imitation of the fine function in the '''gnuplot'''.
<langsyntaxhighlight lang="gnuplot">
## plotpolya.gp 1/19/17 aev
## Plotting a polyspiral and writing to the png-file. Simple plot for animation.
Line 551 ⟶ 882:
plot [0:c] t*cos(d*t), t*sin(d*t) lt rgb @clr
set output
</langsyntaxhighlight>
 
===Plotting many polyspiral and other pictures for animation.===
'''Note:''' No generated pictures here on RC.
<langsyntaxhighlight lang="gnuplot">
## PSpirals4a.gp 1/19/17 aev
## Plotting many polyspiral and other pictures for animation
Line 611 ⟶ 942:
##PS14 Not a polyspiral, but has many short secondary spirals.
rng=700; d=-1; clr = '"navy"'; filename = "PS14"; load "plotpolya.gp";
</langsyntaxhighlight>
{{Output}}
<pre>
Line 623 ⟶ 954:
[[File:NiceFigsAnim.gif|right|thumb|Output NiceFigsAnim.gif]]
 
<langsyntaxhighlight lang="gnuplot">
## Animation for polyspirals PS0 - PS6
reset
Line 645 ⟶ 976:
do for [i=8:14]{plot 'PS'.i.'.png' binary filetype=png with rgbimage}
set output
</langsyntaxhighlight>
{{Output}}
<pre>
Line 653 ⟶ 984:
===Showing 2 animated gif-files.===
Create 2 the following html-files and envoke them in browser.
<langsyntaxhighlight lang="html">
<!-- PolySpirsAnim.html -->
<html><body>
Line 660 ⟶ 991:
<img src="PolySpirsAnim.gif">
</body></html>
</langsyntaxhighlight>
<langsyntaxhighlight lang="html">
<!-- NiceFigsAnim.html -->
<html><body>
Line 668 ⟶ 999:
<img src="NiceFigsAnim.gif">
</body></html>
</langsyntaxhighlight>
{{Output}}
<pre>
Line 684 ⟶ 1,015:
$ eog polyspiral2.gif
</pre>
<langsyntaxhighlight lang="go">package main
 
import (
Line 796 ⟶ 1,127:
log.Fatal(err2)
}
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
Line 803 ⟶ 1,134:
This implementation compiles to javascript that runs in the browser using the [https://github.com/ghcjs/ghcjs ghcjs compiler ] . The [https://github.com/reflex-frp/reflex-dom reflex-dom ] library is used to help with svg rendering and animation.
 
<langsyntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-}
import Reflex
import Reflex.Dom
Line 885 ⟶ 1,216:
elSvgns t m ma = do
(el, val) <- elDynAttrNS' (Just "http://www.w3.org/2000/svg") t m ma
return val</langsyntaxhighlight>
 
Link to live demo: https://dc25.github.io/rosettaCode__Polyspiral_haskell/
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "PolySp.bas"
110 OPTION ANGLE DEGREES
120 LET CH=2
Line 914 ⟶ 1,245:
320 LET D=740
330 CONTINUE
340 END HANDLER</langsyntaxhighlight>
 
=={{header|J}}==
Line 920 ⟶ 1,251:
{{trans|java}}
 
<langsyntaxhighlight Jlang="j">require 'gl2 trig media/imagekit'
coinsert 'jgl2'
Line 969 ⟶ 1,300:
)
poly_run''</langsyntaxhighlight>
 
Note that we're using a lot of [[j:Guides/Window_Driver/Command_Reference|wd]] commands here. You'll need to be running [[j:System/Installation|jqt]] for this to work.
Line 976 ⟶ 1,307:
[[File:Polyspiral_java2.png|300px|thumb|right]]
{{works with|Java|8}}
<langsyntaxhighlight lang="java">import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.*;
Line 1,037 ⟶ 1,368:
});
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Line 1,048 ⟶ 1,379:
* An image uploading is still blocked. But you have a browser!? So, copy/paste/save this page and double click it.
{{Works with|Chrome}} (or any other browser supporting Canvas tag)
<langsyntaxhighlight lang="html">
<!-- Polyspiral.html -->
<html>
Line 1,109 ⟶ 1,440:
</body>
</html>
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 1,119 ⟶ 1,450:
===Version #2 - Animated===
{{trans|Java}}
<langsyntaxhighlight lang="javascript"><!DOCTYPE html>
<html lang="en">
<head>
Line 1,200 ⟶ 1,531:
 
</body>
</html></langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Gtk, Graphics, Colors
 
const can = @GtkCanvas()
Line 1,263 ⟶ 1,594:
sleep(0.5)
end
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.*
Line 1,321 ⟶ 1,652:
f.setVisible(true)
}
}</langsyntaxhighlight>
 
=={{header|Lua}}==
{{libheader|LÖVE}}
LÖVE defaults to animating at sixty frames per second, so the patterns become very complex very quickly.
<langsyntaxhighlight Lualang="lua">function love.load ()
love.window.setTitle("Polyspiral")
incr = 0
Line 1,348 ⟶ 1,679:
angle = (angle + incr) % 360
end
end</langsyntaxhighlight>
[[File:love2dPolyspiral.jpg]]
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">linedata = {};
Dynamic[Graphics[Line[linedata], PlotRange -> 1000]]
Do[
Line 1,359 ⟶ 1,690:
,
{\[Theta], Subdivide[0.1, 1, 100]}
]</langsyntaxhighlight>
{{out}}
Outputs an animating graphic with a spiral with changing angle.
Line 1,367 ⟶ 1,698:
As Julia, we use Gtk/Cairo to draw the polyspirals. So, the drawing part is taken, with some modifications, from Julia solution.
 
<langsyntaxhighlight Nimlang="nim"># Pendulum simulation.
 
import math, random
Line 1,479 ⟶ 1,810:
let app = newApplication(Application, "Rosetta.polyspiral")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
Line 1,489 ⟶ 1,820:
You can find a few others on [http://oeis.org/wiki/User:Anatoly_E._Voevudko/VoeLib.gp#Plotting_helper_functions OEIS Wiki] and here on RC Wiki.
 
<langsyntaxhighlight lang="parigp">
\\ Plot the line from x1,y1 to x2,y2.
plotline(x1,y1,x2,y2,w=0)={plotmove(w, x1,y1);plotrline(w,x2-x1,y2-y1);}
Line 1,497 ⟶ 1,828:
cartes2(r,a,rndf=0)={my(v,x,y); x=r*cos(a); y=r*sin(a);
if(rndf==0, return([x,y]), return(round([x,y])))}
</syntaxhighlight>
</lang>
 
===Version #1. Polyspiral (a spiral made of multiple line segments).===
Line 1,510 ⟶ 1,841:
[[File:Polyspiral4.png|100px|right|thumb|Output Polyspiral4.png]]
 
<langsyntaxhighlight lang="parigp">
\\Polyspiral (a spiral made of multiple line segments)
\\ 4/15/16 aev
Line 1,545 ⟶ 1,876:
polyspiral(100000,100000,0.03,3,2);\\Polyspiral4.png
}
</langsyntaxhighlight>
 
{{Output}}
Line 1,577 ⟶ 1,908:
[[File:Spiralz1.png|100px|right|thumb|Output Spiralz.png]]
 
<langsyntaxhighlight lang="parigp">
\\ plotpspiralz() Multi-spiral figure translated from zkl using my own ploting functions.
\\ 4/15/16 aev
Line 1,614 ⟶ 1,945:
Spiralz(640,2,3.0,3.0,128); \\Spiralz1.png
}
</langsyntaxhighlight>
 
{{Output}}
Line 1,626 ⟶ 1,957:
Click Start button to run, then runs continuously.
It takes just a little over four minutes to complete a full 360 degree cycle.
<langsyntaxhighlight lang="perl">
#!/usr/bin/perl
 
Line 1,674 ⟶ 2,005:
$c->createLine( @pts );
$mw->after($wait => \&step);
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 1,680 ⟶ 2,011:
'M' toggles "mod360", which inverts the angle every 360/2PI or so, since sin/cos
accept arguments in radians not degrees (and mod 2*PI changes nothing), producing
non-true polyspirals, but quite interesting nevertheless.
You can run this online [http://phix.x10.mx/p2js/Polyspiral.htm here].
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
<lang Phix>-- demo\rosetta\Polyspiral.exw
<!--<syntaxhighlight lang="phix">(phixonline)-->
include pGUI.e
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Polyspiral.exw
-- ===========================
--
-- Space toggles the timer, '+' increases speed (up to 100 FPS), '-' decreases speed
-- 'M' toggles "mod360", which inverts the angle every 360/2PI or so, since sin/cos
-- accept arguments in radians not degrees (and mod 2*PI changes nothing), producing
-- non-true polyspirals, but quite interesting nevertheless.
--</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">TITLE</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Polyspiral"</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">timer</span>
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cdcanvas</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">incr</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #004080;">bool</span> <span style="color: #000000;">mod360</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">Polyspiral</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y1</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">angle</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">incr</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">len</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span>
<span style="color: #000000;">incr</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">0.05</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">mod360</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">incr</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">incr</span><span style="color: #0000FF;">,</span><span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">150</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">x2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">x1</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">angle</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">len</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">y2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">y1</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">angle</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">len</span>
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">*</span><span style="color: #000000;">#200</span><span style="color: #0000FF;">+</span><span style="color: #000000;">i</span><span style="color: #0000FF;">*</span><span style="color: #000000;">#40</span><span style="color: #0000FF;">+</span><span style="color: #000000;">i</span><span style="color: #0000FF;">*</span><span style="color: #000000;">#10</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasLine</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y2</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y1</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">x2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y2</span><span style="color: #0000FF;">}</span>
<span style="color: #000000;">len</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">3</span>
<span style="color: #000000;">angle</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">incr</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">mod360</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">angle</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">angle</span><span style="color: #0000FF;">,</span><span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">redraw_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">w</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasActivate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasClear</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">Polyspiral</span><span style="color: #0000FF;">(</span><span style="color: #000000;">w</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ms</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TIME"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"%s (timer=%d [%g FPS], angle %3.2f%s)"</span><span style="color: #0000FF;">,</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">TITLE</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ms</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">/</span><span style="color: #000000;">ms</span><span style="color: #0000FF;">,</span><span style="color: #000000;">incr</span><span style="color: #0000FF;">,</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mod360</span><span style="color: #0000FF;">?</span><span style="color: #008000;">" (mod360)"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">timer_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*timer*/</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupUpdate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_IGNORE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">map_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cdcanvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_IUP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cddbuffer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_DBUFFER</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetBackground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_WHITE</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cddbuffer</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_GRAY</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">key_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #004600;">K_ESC</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CLOSE</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #008000;">' '</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RUN"</span><span style="color: #0000FF;">,</span><span style="color: #008080;">not</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RUN"</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"+-"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RUN"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">-(</span><span style="color: #008000;">','</span><span style="color: #0000FF;">-</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- ('+' ==&gt; +1, '-' ==&gt; -1)</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TIME"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TIME"</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">c</span><span style="color: #0000FF;">*</span><span style="color: #000000;">10</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RUN"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">upper</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)=</span><span style="color: #008000;">'M'</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">mod360</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">not</span> <span style="color: #000000;">mod360</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CONTINUE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupCanvas</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"RASTERSIZE=640x640"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetCallbacks</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"MAP_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"map_cb"</span><span style="color: #0000FF;">),</span>
<span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"redraw_cb"</span><span style="color: #0000FF;">)})</span>
<span style="color: #000000;">timer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupTimer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"timer_cb"</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">20</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`TITLE="%s"`</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">TITLE</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">IupSetCallback</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"KEY_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"key_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"RASTERSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
 
=={{header|Processing}}==
Ihandle dlg, canvas, timer
{{trans|C}}
cdCanvas cddbuffer, cdcanvas
<syntaxhighlight lang="java">
//Aamrun, 2nd July 2022
 
int incr = 0, angle, i, length;
constant TITLE = "Polyspiral"
float x,y,x1,y1;
double factor = PI/180;
 
void setup() {
atom incr = 0
size(1000, 1000);
bool mod360 = false
stroke(255);
 
}
procedure Polyspiral(atom x1, y1)
atom angle = incr
integer len = 5
incr += 0.05
if mod360 then
incr = mod(incr,360)
end if
for i=1 to 150 do
atom x2 = x1 + cos(angle)*len
atom y2 = y1 + sin(angle)*len
cdCanvasSetForeground(cddbuffer, i*#200+i*#40+i*#10)
cdCanvasLine(cddbuffer, x1, y1, x2, y2)
{x1, y1} = {x2, y2}
len += 3
angle += incr
if mod360 then
angle = mod(angle,360)
end if
end for
end procedure
 
void draw() {
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
background(51);
integer {w, h} = IupGetIntInt(canvas, "DRAWSIZE")
incr = (incr + 5)%360;
cdCanvasActivate(cddbuffer)
cdCanvasClear(cddbuffer)
Polyspiral(w/2,x = hwidth/2);
y = height/2;
cdCanvasFlush(cddbuffer)
integer ms = IupGetInt(timer,"TIME")
length = 5;
IupSetStrAttribute(dlg, "TITLE", "%s (timer=%d [%g FPS], angle %3.2f%s)",
angle = incr;
{TITLE,ms,1000/ms,incr,iff(mod360?" (mod360)":"")})
return IUP_DEFAULT
for(i=1;i<=150;i++){
end function
x1 = x + (float)(length*Math.cos(factor*angle));
 
y1 = y + (float)(length*Math.sin(factor*angle));
function timer_cb(Ihandle /*ih*/)
IupUpdate line(canvasx,y,x1,y1);
return IUP_IGNORE
length += 3;
end function
 
angle = (angle + incr)%360;
function map_cb(Ihandle ih)
cdcanvas = cdCreateCanvas(CD_IUP, ih)
x = x1;
cddbuffer = cdCreateCanvas(CD_DBUFFER, cdcanvas)
y = y1;
cdCanvasSetBackground(cddbuffer, CD_WHITE)
}
cdCanvasSetForeground(cddbuffer, CD_GRAY)
}
return IUP_DEFAULT
</syntaxhighlight>
end function
 
function esc_close(Ihandle /*ih*/, atom c)
if c=K_ESC then return IUP_CLOSE end if
if c=' ' then
IupSetInt(timer,"RUN",not IupGetInt(timer,"RUN"))
elsif find(c,"+-") then
-- ('+' increases speed, by decreasing TIME)
IupSetInt(timer,"TIME",max(10,IupGetInt(timer,"TIME")-(','-c)*10))
IupSetInt(timer,"RUN",0)
IupSetInt(timer,"RUN",1)
elsif upper(c)='M' then
mod360 = not mod360
end if
return IUP_CONTINUE
end function
 
procedure main()
IupOpen()
 
canvas = IupCanvas(NULL)
IupSetAttribute(canvas, "RASTERSIZE", "640x640")
IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
 
timer = IupTimer(Icallback("timer_cb"), 20)
 
dlg = IupDialog(canvas)
IupSetAttribute(dlg, "TITLE", TITLE)
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
 
IupShow(dlg)
IupSetAttribute(canvas, "RASTERSIZE", NULL)
IupMainLoop()
IupClose()
end procedure
 
main()</lang>
 
=={{header|Python}}==
{{libheader|Pygame}}
<langsyntaxhighlight Pythonlang="python">import math
 
import pygame
Line 1,817 ⟶ 2,192:
 
pygame.display.flip()
</syntaxhighlight>
</lang>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ $ "turtleduck.qky" loadfile ] now!
 
[ 1000 * time +
[ dup time < until ]
drop ] is ms ( n --> )
 
[ turtle 0 frames
3601 times
[ clear
i^ 3600
1000 times
[ i^ 1+ 1 walk
2dup turn ]
2drop
frame
10 ms ] ] is polyspiral ( --> )</syntaxhighlight>
 
{{out}}
 
https://youtu.be/qZemJJBUekM
 
 
=={{header|Racket}}==
Uses the *universe* animation
 
<langsyntaxhighlight lang="racket">#lang racket
 
(require 2htdp/universe pict racket/draw)
Line 1,846 ⟶ 2,245:
width height)))
 
(animate (polyspiral 400 400 2 1000))</langsyntaxhighlight>
 
See the output for yourself!
Line 1,857 ⟶ 2,256:
Sort of an ersatz animation. Write updates to a svg file, most modern viewers will update as the content changes.
 
<syntaxhighlight lang="raku" perl6line>use SVG;
my $w = 600;
my $h = 600;
Line 1,900 ⟶ 2,299:
}
( $r, $g, $b ).map: ((*+$m) * 255).Int
}</langsyntaxhighlight>
{{out}}
See [https://github.com/thundergnat/rc/blob/master/img/polyspiral-perl6.gif polyspiral-perl6.gif] (offsite animated gif image)
Line 1,907 ⟶ 2,306:
Uses the same basic algorithm but fully animated. Use the up / down arrow keys to speed up / slow down the update speed. Use PgUp / PgDn keys to increment / decrement animation speed by large amounts. Use left / right arrow keys to reverse the "direction" of angle change. Press Space bar to toggle animation / reset to minimum speed. Left Control key to toggle stationary / rotating center. Use + / - keys to add remove line segments.
 
<syntaxhighlight lang="raku" perl6line>use SDL2::Raw;
 
my $width = 900;
Line 2,019 ⟶ 2,418:
}
( $r, $g, $b ).map: ((*+$m) * 255).Int
}</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Polyspiral
 
Line 2,078 ⟶ 2,477:
}
label1 { setpicture(p1) show() }
</syntaxhighlight>
</lang>
Output:
 
Line 2,085 ⟶ 2,484:
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
import java.awt.event.ActionEvent
 
Line 2,139 ⟶ 2,538:
)
 
}</langsyntaxhighlight>
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">width,height = #.scrsize()
#.angle(#.degrees)
#.scroff()
Line 2,163 ⟶ 2,562:
<
#.scr()
<</langsyntaxhighlight>
 
=={{header|SVG}}==
Line 2,173 ⟶ 2,572:
It requires building up layers, animated over a rotation transformation. This is verbose, so the code below has been truncated, and the [https://codepen.io/shephero/full/xxbaWXb demo] uses another language ([https://codepen.io/shephero/full/xxbaWXb Pug]) to generate the source.
 
<langsyntaxhighlight lang="html">
<svg viewBox="0 0 100 100" stroke="#000" stroke-width="0.3">
<g>
Line 2,191 ⟶ 2,590:
</g>
</svg>
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|DOME}}
<langsyntaxhighlight ecmascriptlang="wren">import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
Line 2,243 ⟶ 2,642:
}
 
var Game = Polyspiral.new(640, 640)</langsyntaxhighlight>
 
=={{header|XPL0}}==
There is no need for the MOD operator shown in the pseudo code for XPL0's
trig functions because they handle argument angles outside 0 to 360
degrees (2 Pi radians).
<syntaxhighlight lang="xpl0">
def Width=640., Height=480.;
def Deg2Rad = 3.141592654/180.;
real Incr, Angle, Length, X, Y, X1, Y1;
int N;
[SetVid($101); \VESA 640x480x8 graphics
Incr:= 0.;
repeat Incr:= Incr+1.;
X:= Width/2.; Y:= Height/2.;
Move(fix(X), fix(Y));
Length:= 5.;
Angle:= Incr;
for N:= 1 to 150 do
[X1:= X + Length*Cos(Angle*Deg2Rad);
Y1:= Y + Length*Sin(Angle*Deg2Rad);
Line(fix(X1), fix(Y1), N+16);
X:= X1; Y:= Y1;
Length:= Length+3.;
Angle:= Angle+Incr;
];
DelayUS(83_333);
Clear;
until KeyHit;
]</syntaxhighlight>
 
{{out}}
<pre>
https://www.youtube.com/watch?v=p1M2VVY3abM
The actual program looks better and runs under MS-DOS, Windows (with EXPL) and RPi.
</pre>
 
 
=={{header|Yabasic}}==
{{trans|Python}}
<langsyntaxhighlight Yabasiclang="yabasic">w = 1024 : h = 600
open window w, h
color 255,0,0
Line 2,271 ⟶ 2,706:
next
pause 1
end while</langsyntaxhighlight>
 
=={{header|Zig}}==
{{works with|Zig|0.11.0}} {{works with|raylib|4.6-dev}}
{{libheader|raylib}}
<syntaxhighlight lang="zig">
const std = @import("std");
const rl = @cImport({
@cInclude("raylib.h");
@cInclude("raymath.h");
});
 
const SCREEN_WIDTH = 640;
const SCREEN_HEIGHT = 480;
var incr: f32 = 0;
 
pub fn main() void {
rl.SetConfigFlags(rl.FLAG_WINDOW_RESIZABLE | rl.FLAG_VSYNC_HINT);
rl.SetTargetFPS(60);
 
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Polyspiral");
 
while (!rl.WindowShouldClose())
updateDrawFrame();
 
rl.CloseWindow();
}
 
fn updateDrawFrame() void {
rl.BeginDrawing();
 
rl.ClearBackground(rl.BLACK);
 
incr = @mod(incr + 0.001, 360);
 
drawSpiral(5, std.math.degreesToRadians(f32, incr));
 
rl.EndDrawing();
}
 
fn drawSpiral(_length: f32, _angle: f32) void {
const width = rl.GetScreenWidth();
const height = rl.GetScreenHeight();
var point0 = rl.Vector2{ .x = @as(f32, @floatFromInt(width)) / 2, .y = @as(f32, @floatFromInt(height)) / 2 };
var length = _length;
var angle = _angle;
for (0..150) |_| {
const line_vector = rl.Vector2Rotate(rl.Vector2{ .x = length, .y = 0 }, angle);
const point1 = rl.Vector2Add(point0, line_vector);
rl.DrawLineV(point0, point1, rl.LIME);
point0 = point1;
length += 3;
angle += incr;
angle = @mod(angle, comptime @as(f32, (2.0 * std.math.pi)));
}
}
</syntaxhighlight>
 
=={{header|zkl}}==
Line 2,278 ⟶ 2,769:
 
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<langsyntaxhighlight lang="zkl">w,h:=640,640;
bitmap:=PPM(w,h,0xFF|FF|FF); // White background
angleIncrement:=(3.0).toRad();
Line 2,296 ⟶ 2,787:
angleIncrement=(angleIncrement + 0.05);
Atomic.sleep(3);
}</langsyntaxhighlight>
9,482

edits