Polyspiral: Difference between revisions

m
syntax highlighting fixup automation
(Added Processing implementation)
m (syntax highlighting fixup automation)
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|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:
Sleep 500
Cls
Loop Until Multikey(SC_ESCAPE)</langsyntaxhighlight>
 
 
Line 588:
===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:
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:
[[File:PS6gp.png|right|thumb|Output PS6gp.png]]
 
<langsyntaxhighlight lang="gnuplot">
## PSpirals.gp 1/10/17 aev
## Plotting many polyspiral pictures.
Line 718:
## Continue plotting starting with a range rng=110 to 400+ step 10 to discover new figures.
## END ##
</langsyntaxhighlight>
{{Output}}
<pre>
Line 727:
===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:
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:
##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:
[[File:NiceFigsAnim.gif|right|thumb|Output NiceFigsAnim.gif]]
 
<langsyntaxhighlight lang="gnuplot">
## Animation for polyspirals PS0 - PS6
reset
Line 836:
do for [i=8:14]{plot 'PS'.i.'.png' binary filetype=png with rgbimage}
set output
</langsyntaxhighlight>
{{Output}}
<pre>
Line 844:
===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:
<img src="PolySpirsAnim.gif">
</body></html>
</langsyntaxhighlight>
<langsyntaxhighlight lang="html">
<!-- NiceFigsAnim.html -->
<html><body>
Line 859:
<img src="NiceFigsAnim.gif">
</body></html>
</langsyntaxhighlight>
{{Output}}
<pre>
Line 875:
$ eog polyspiral2.gif
</pre>
<langsyntaxhighlight lang="go">package main
 
import (
Line 987:
log.Fatal(err2)
}
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
Line 994:
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:
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:
320 LET D=740
330 CONTINUE
340 END HANDLER</langsyntaxhighlight>
 
=={{header|J}}==
Line 1,111:
{{trans|java}}
 
<langsyntaxhighlight Jlang="j">require 'gl2 trig media/imagekit'
coinsert 'jgl2'
Line 1,160:
)
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:
[[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:
});
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Line 1,239:
* 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:
</body>
</html>
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 1,310:
===Version #2 - Animated===
{{trans|Java}}
<langsyntaxhighlight lang="javascript"><!DOCTYPE html>
<html lang="en">
<head>
Line 1,391:
 
</body>
</html></langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Gtk, Graphics, Colors
 
const can = @GtkCanvas()
Line 1,454:
sleep(0.5)
end
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.*
Line 1,512:
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:
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:
,
{\[Theta], Subdivide[0.1, 1, 100]}
]</langsyntaxhighlight>
{{out}}
Outputs an animating graphic with a spiral with changing angle.
Line 1,558:
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:
let app = newApplication(Application, "Rosetta.polyspiral")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
Line 1,680:
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:
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:
[[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:
polyspiral(100000,100000,0.03,3,2);\\Polyspiral4.png
}
</langsyntaxhighlight>
 
{{Output}}
Line 1,768:
[[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:
Spiralz(640,2,3.0,3.0,128); \\Spiralz1.png
}
</langsyntaxhighlight>
 
{{Output}}
Line 1,817:
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:
$c->createLine( @pts );
$mw->after($wait => \&step);
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 1,875:
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Polyspiral.exw
Line 1,968:
<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}}
<langsyntaxhighlight lang="java">
//Aamrun, 2nd July 2022
 
Line 2,009:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Python}}==
{{libheader|Pygame}}
<langsyntaxhighlight Pythonlang="python">import math
 
import pygame
Line 2,052:
 
pygame.display.flip()
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
Uses the *universe* animation
 
<langsyntaxhighlight lang="racket">#lang racket
 
(require 2htdp/universe pict racket/draw)
Line 2,081:
width height)))
 
(animate (polyspiral 400 400 2 1000))</langsyntaxhighlight>
 
See the output for yourself!
Line 2,092:
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,135:
}
( $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,142:
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,254:
}
( $r, $g, $b ).map: ((*+$m) * 255).Int
}</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Polyspiral
 
Line 2,313:
}
label1 { setpicture(p1) show() }
</syntaxhighlight>
</lang>
Output:
 
Line 2,320:
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
import java.awt.event.ActionEvent
 
Line 2,374:
)
 
}</langsyntaxhighlight>
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">width,height = #.scrsize()
#.angle(#.degrees)
#.scroff()
Line 2,398:
<
#.scr()
<</langsyntaxhighlight>
 
=={{header|SVG}}==
Line 2,408:
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,426:
</g>
</svg>
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|DOME}}
<langsyntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
Line 2,478:
}
 
var Game = Polyspiral.new(640, 640)</langsyntaxhighlight>
 
=={{header|XPL0}}==
Line 2,484:
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,507:
Clear;
until KeyHit;
]</langsyntaxhighlight>
 
{{out}}
Line 2,518:
=={{header|Yabasic}}==
{{trans|Python}}
<langsyntaxhighlight Yabasiclang="yabasic">w = 1024 : h = 600
open window w, h
color 255,0,0
Line 2,542:
next
pause 1
end while</langsyntaxhighlight>
 
=={{header|zkl}}==
Line 2,549:
 
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,567:
angleIncrement=(angleIncrement + 0.05);
Atomic.sleep(3);
}</langsyntaxhighlight>
10,333

edits