Polyspiral: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Polyspiral in FreeBASIC)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(10 intermediate revisions by 8 users not shown)
Line 37:
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "H6:REALMATH.ACT"
 
INT ARRAY SinTab=[
Line 116:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Polyspiral.png Screenshot from Atari 8-bit computer]
Line 122:
=={{header|AutoHotkey}}==
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
<langsyntaxhighlight AutoHotkeylang="autohotkey">If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
Line 189:
ExitApp
Return
;----------------------------------------------------------------</langsyntaxhighlight>
 
=={{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 240:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Drawing.Drawing2D;
Line 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 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 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}}==
<langsyntaxhighlight lang="freebasic">#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB
Line 572 ⟶ 654:
Sleep 500
Cls
Loop Until Multikey(SC_ESCAPE)</langsyntaxhighlight>
 
=={{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 588 ⟶ 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 604 ⟶ 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 615 ⟶ 755:
[[File:PS6gp.png|right|thumb|Output PS6gp.png]]
 
<langsyntaxhighlight lang="gnuplot">
## PSpirals.gp 1/10/17 aev
## Plotting many polyspiral pictures.
Line 718 ⟶ 858:
## Continue plotting starting with a range rng=110 to 400+ step 10 to discover new figures.
## END ##
</langsyntaxhighlight>
{{Output}}
<pre>
Line 727 ⟶ 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 742 ⟶ 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 802 ⟶ 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 814 ⟶ 954:
[[File:NiceFigsAnim.gif|right|thumb|Output NiceFigsAnim.gif]]
 
<langsyntaxhighlight lang="gnuplot">
## Animation for polyspirals PS0 - PS6
reset
Line 836 ⟶ 976:
do for [i=8:14]{plot 'PS'.i.'.png' binary filetype=png with rgbimage}
set output
</langsyntaxhighlight>
{{Output}}
<pre>
Line 844 ⟶ 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 851 ⟶ 991:
<img src="PolySpirsAnim.gif">
</body></html>
</langsyntaxhighlight>
<langsyntaxhighlight lang="html">
<!-- NiceFigsAnim.html -->
<html><body>
Line 859 ⟶ 999:
<img src="NiceFigsAnim.gif">
</body></html>
</langsyntaxhighlight>
{{Output}}
<pre>
Line 875 ⟶ 1,015:
$ eog polyspiral2.gif
</pre>
<langsyntaxhighlight lang="go">package main
 
import (
Line 987 ⟶ 1,127:
log.Fatal(err2)
}
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
Line 994 ⟶ 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 1,076 ⟶ 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 1,105 ⟶ 1,245:
320 LET D=740
330 CONTINUE
340 END HANDLER</langsyntaxhighlight>
 
=={{header|J}}==
Line 1,111 ⟶ 1,251:
{{trans|java}}
 
<langsyntaxhighlight Jlang="j">require 'gl2 trig media/imagekit'
coinsert 'jgl2'
Line 1,160 ⟶ 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 1,167 ⟶ 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,228 ⟶ 1,368:
});
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Line 1,239 ⟶ 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,300 ⟶ 1,440:
</body>
</html>
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 1,310 ⟶ 1,450:
===Version #2 - Animated===
{{trans|Java}}
<langsyntaxhighlight lang="javascript"><!DOCTYPE html>
<html lang="en">
<head>
Line 1,391 ⟶ 1,531:
 
</body>
</html></langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Gtk, Graphics, Colors
 
const can = @GtkCanvas()
Line 1,454 ⟶ 1,594:
sleep(0.5)
end
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.*
Line 1,512 ⟶ 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,539 ⟶ 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,550 ⟶ 1,690:
,
{\[Theta], Subdivide[0.1, 1, 100]}
]</langsyntaxhighlight>
{{out}}
Outputs an animating graphic with a spiral with changing angle.
Line 1,558 ⟶ 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,670 ⟶ 1,810:
let app = newApplication(Application, "Rosetta.polyspiral")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
Line 1,680 ⟶ 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,688 ⟶ 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,701 ⟶ 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,736 ⟶ 1,876:
polyspiral(100000,100000,0.03,3,2);\\Polyspiral4.png
}
</langsyntaxhighlight>
 
{{Output}}
Line 1,768 ⟶ 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,805 ⟶ 1,945:
Spiralz(640,2,3.0,3.0,128); \\Spiralz1.png
}
</langsyntaxhighlight>
 
{{Output}}
Line 1,817 ⟶ 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,865 ⟶ 2,005:
$c->createLine( @pts );
$mw->after($wait => \&step);
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 1,875 ⟶ 2,015:
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Polyspiral.exw
Line 1,968 ⟶ 2,108:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Processing}}==
{{trans|C}}
<syntaxhighlight lang="java">
//Aamrun, 2nd July 2022
 
int incr = 0, angle, i, length;
float x,y,x1,y1;
double factor = PI/180;
 
void setup() {
size(1000, 1000);
stroke(255);
 
}
 
void draw() {
background(51);
incr = (incr + 5)%360;
x = width/2;
y = height/2;
length = 5;
angle = incr;
for(i=1;i<=150;i++){
x1 = x + (float)(length*Math.cos(factor*angle));
y1 = y + (float)(length*Math.sin(factor*angle));
line(x,y,x1,y1);
length += 3;
angle = (angle + incr)%360;
x = x1;
y = y1;
}
}
</syntaxhighlight>
 
=={{header|Python}}==
{{libheader|Pygame}}
<langsyntaxhighlight Pythonlang="python">import math
 
import pygame
Line 2,011 ⟶ 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 2,040 ⟶ 2,245:
width height)))
 
(animate (polyspiral 400 400 2 1000))</langsyntaxhighlight>
 
See the output for yourself!
Line 2,051 ⟶ 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 2,094 ⟶ 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 2,101 ⟶ 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,213 ⟶ 2,418:
}
( $r, $g, $b ).map: ((*+$m) * 255).Int
}</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Polyspiral
 
Line 2,272 ⟶ 2,477:
}
label1 { setpicture(p1) show() }
</syntaxhighlight>
</lang>
Output:
 
Line 2,279 ⟶ 2,484:
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
import java.awt.event.ActionEvent
 
Line 2,333 ⟶ 2,538:
)
 
}</langsyntaxhighlight>
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">width,height = #.scrsize()
#.angle(#.degrees)
#.scroff()
Line 2,357 ⟶ 2,562:
<
#.scr()
<</langsyntaxhighlight>
 
=={{header|SVG}}==
Line 2,367 ⟶ 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,385 ⟶ 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,437 ⟶ 2,642:
}
 
var Game = Polyspiral.new(640, 640)</langsyntaxhighlight>
 
=={{header|XPL0}}==
Line 2,443 ⟶ 2,648:
trig functions because they handle argument angles outside 0 to 360
degrees (2 Pi radians).
<syntaxhighlight lang="xpl0">
<lang XPL0>
def Width=640., Height=480.;
def Deg2Rad = 3.141592654/180.;
Line 2,466 ⟶ 2,671:
Clear;
until KeyHit;
]</langsyntaxhighlight>
 
{{out}}
Line 2,477 ⟶ 2,682:
=={{header|Yabasic}}==
{{trans|Python}}
<langsyntaxhighlight Yabasiclang="yabasic">w = 1024 : h = 600
open window w, h
color 255,0,0
Line 2,501 ⟶ 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,508 ⟶ 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,526 ⟶ 2,787:
angleIncrement=(angleIncrement + 0.05);
Atomic.sleep(3);
}</langsyntaxhighlight>
9,486

edits