Archimedean spiral: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 18:
=={{header|Action!}}==
Action! does not provide trigonometric functions. Therefore a simple implementation for Sin and Cos function has been provided.
<syntaxhighlight lang=Action"action!">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
Line 74:
=={{header|Ada}}==
{{libheader|SDLAda}}
<syntaxhighlight lang=Ada"ada">with Ada.Numerics.Elementary_Functions;
 
with SDL.Video.Windows.Makers;
Line 150:
{{Trans|AWK}}
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 %
integer procedure max ( integer x, y ) ; begin if x > y then x else y end;
Line 240:
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
sp←⎕NEW Causeway.SharpPlot
Line 250:
=={{header|AutoHotkey}}==
Requires [https://github.com/tariqporter/Gdip GDIP]
<syntaxhighlight lang=AutoHotkey"autohotkey">if !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
Line 303:
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f ARCHIMEDEAN_SPIRAL.AWK
# converted from Applesoft BASIC
Line 386:
==={{header|AmigaBASIC}}===
{{trans|Locomotive Basic}}
<syntaxhighlight lang="amigabasic">a=1.5
b=1.5
pi=3.141592
Line 397:
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang=ApplesoftBasic"applesoftbasic">110 LET H = 96
120 LET W = H + H / 2
130 HGR2
Line 419:
 
==={{header|BASIC256}}===
<syntaxhighlight lang=BASIC256"basic256">
# Basic-256 ver 1.1.4
# Archimedean Spiral
Line 459:
==={{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.
<syntaxhighlight lang="basic">1 REM ARCHIMEDEAN SPIRAL
2 REM USING COMMODORE BASIC 7.0
3 REM OF THE COMMODORE 128
Line 476:
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' version 16-10-2016
' compile with: fbc -s gui
 
Line 504:
 
==={{header|GW-BASIC}}===
<syntaxhighlight lang="gwbasic">10 A = 0
20 B = 1
30 SCREEN 1
Line 518:
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang=IS"is-BASICbasic">100 GRAPHICS LORES 2
110 OPTION ANGLE DEGREES
120 PLOT 640,360,ANGLE 90;
Line 527:
==={{header|Locomotive Basic}}===
{{trans|Commodore BASIC}}
<syntaxhighlight lang="locobasic">10 a=1.5:b=2
20 mode 2:rad:move 320,200
30 for t=0 to 40*pi step 0.2
Line 536:
 
==={{header|Run BASIC}}===
<syntaxhighlight lang=Run"run BASICbasic"> 'archimedean spiral.bas
'runs in Run Basic
'Run Basic website http://www.runbasic.com
Line 565:
 
==={{header|QBasic}}===
<syntaxhighlight lang="qbasic">SCREEN 12
WINDOW (-2.67, -2!)-(2.67, 2!)
PI = 4 * ATN(1)
Line 581:
{{trans|Applesoft BASIC}}
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
30 FOR T=0 TO 7*PI STEP 0.05
Line 593:
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.
Line 603:
=={{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.
<syntaxhighlight lang=C"c">
#include<graphics.h>
#include<stdio.h>
Line 640:
=={{header|C sharp|C#}}==
 
<syntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Drawing;
Line 683:
=={{header|C++}}==
[[File:SpiralCpp.png|200px|thumb|right]]
<syntaxhighlight lang="cpp">
#include <windows.h>
#include <string>
Line 798:
=={{header|Clojure}}==
{{Works with| Incanter}}
<syntaxhighlight lang="clojure">
(use '(incanter core stats charts io))
 
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.
 
<syntaxhighlight lang="lisp">(defun draw-coords-as-text (coords size fill-char)
(let* ((min-x (apply #'min (mapcar #'car coords)))
(min-y (apply #'min (mapcar #'cdr coords)))
Line 894:
 
=={{header|FOCAL}}==
<syntaxhighlight lang=FOCAL"focal">1.1 S A=1.5
1.2 S B=2
1.3 S N=250
Line 918:
{{Works with|Frege|3.23.888}}
 
<syntaxhighlight lang="frege">module Archimedean where
 
import Java.IO
Line 1,013:
{{works with|go|1.9}}
Creates a PNG file using only built-in packages.
<syntaxhighlight lang="go">package main
 
import (
Line 1,067:
{{libheader|Juicy.Pixels}}
{{libheader|Rasterific}}
<syntaxhighlight lang="haskell">#!/usr/bin/env stack
-- stack --resolver lts-7.0 --install-ghc runghc --package Rasterific --package JuicyPixels
 
Line 1,099:
=={{header|J}}==
[[File:Archimedian spiral j.png|200px|thumb|right]]
<syntaxhighlight lang="j">require'plot'
'aspect 1' plot (*^)j.0.01*i.1400</syntaxhighlight>
 
Line 1,107:
[[File:archimedian_spiral.png|300px|thumb|right]]
{{works with|Java|8}}
<syntaxhighlight lang="java">import java.awt.*;
import static java.lang.Math.*;
import javax.swing.*;
Line 1,196:
{{Works with|Chrome}}
[[File:ASjs.png|200px|right|thumb|Output ASjs.png]]
<syntaxhighlight lang="html">
<!-- ArchiSpiral.html -->
<html>
Line 1,231:
Assumes the same HTML canvas embedding as above, but is functionally composed.
Defines and logs a set of points, before rendering them to canvas.
<syntaxhighlight lang="html"><html>
<head>
<title>Archimedean spiral</title>
Line 1,240:
<canvas id="spiral" width="640" height="640" style="border: 2px outset;"></canvas>
<script></syntaxhighlight>
<syntaxhighlight lang="javascript">const main = strColor => intCycles => {
const
ai = 0.05,
Line 1,273:
length: 1 + n - m
}, (_, i) => m + i);</syntaxhighlight>
<syntaxhighlight lang="html"></script></body></html></syntaxhighlight>
 
=={{header|jq}}==
Line 1,279:
'''Works with gojq, the Go implementation of jq'''
====SVG version====
<syntaxhighlight lang="jq">def spiral($zero; $turns; $step):
 
def pi: 1 | atan * 4;
Line 1,312:
====ASCII Art Version====
{{trans|awk}}
<syntaxhighlight lang="jq">def spiral($a; $b; $step; $h):
def min($x;$y): if $x <= $y then $x else $y end;
def max($x;$y): if $x <= $y then $y else $x end;
Line 1,349:
{{works with|Julia|0.6}}
 
<syntaxhighlight lang="julia">using UnicodePlots
 
spiral(θ, a=0, b=1) = @. b * θ * cos(θ + a), b * θ * sin(θ + a)
Line 1,379:
=={{header|Kotlin}}==
{{trans|Java}}
<syntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.*
Line 1,459:
{{libheader|LÖVE}}
{{works with|LÖVE|11.3}}
<syntaxhighlight lang=Lua"lua">
a=1
b=2
Line 1,483:
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang=M2000"m2000 Interpreterinterpreter">
module Archimedean_spiral {
smooth on ' enable GDI+
Line 1,513:
 
=={{header|Maple}}==
<syntaxhighlight lang=Maple"maple">
plots[polarplot](1+2*theta, theta = 0 .. 6*Pi)
</syntaxhighlight>
Line 1,519:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
The built-in function PolarPlot easily creates the desired plot
<syntaxhighlight lang=Mathematica"mathematica">With[{a = 5, b = 4}, PolarPlot[a + b t, {t, 0, 10 Pi}]]</syntaxhighlight>
 
=={{header|MATLAB}}==
<syntaxhighlight lang=MATLAB"matlab">a = 1;
b = 1;
turns = 2;
Line 1,530:
=={{header|Nim}}==
{{libheader|gintro}}
<syntaxhighlight lang=Nim"nim">import math
 
import gintro/[glib, gobject, gtk, gio, cairo]
Line 1,611:
[[File:ArchiSpiral2.png|right|thumb|Output ArchiSpiral2.png]]
 
<syntaxhighlight lang="parigp">
\\ The Archimedean spiral
\\ ArchiSpiral() - Where: lps is a number of loops, c is a direction 0/1
Line 1,644:
=={{header|Perl}}==
{{trans|Raku}}
<syntaxhighlight lang=Perl"perl">use Imager;
use constant PI => 3.14159265;
 
Line 1,664:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Archimedean_spiral.htm here].
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Archimedean_spiral.exw
Line 1,720:
====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.
<syntaxhighlight lang=Processing"processing">float x, y;
float theta;
float rotation;
Line 1,743:
====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().
<syntaxhighlight lang=Processing"processing">float theta;
float rotation;
 
Line 1,764:
====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().
<syntaxhighlight lang=Processing"processing">PVector pv;
float rotation;
 
Line 1,786:
====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.
<syntaxhighlight lang=Processing"processing">float px, py, x, y;
float theta;
float rotation;
Line 1,811:
====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.
<syntaxhighlight lang=Processing"processing">float x, y, px, py;
float theta;
float rotation;
Line 1,841:
====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.
<syntaxhighlight lang="python">theta = 0
rotation = 0.1
 
Line 1,861:
 
=={{header|PureBasic}}==
<syntaxhighlight lang=PureBasic"purebasic">#MAXLOOP = 7*360
#XCENTER = 640/2
#YCENTER = 480/2
Line 1,887:
Using the '''turtle''' module.
 
<syntaxhighlight lang="python">from turtle import *
from math import *
color("blue")
Line 1,901:
=={{header|Quackery}}==
 
<syntaxhighlight lang=Quackery"quackery"> [ $ "turtleduck.qky" loadfile ] now!
turtle
0 n->v
Line 1,915:
 
=={{header|R}}==
<syntaxhighlight lang="r">with(list(s=seq(0, 10 * pi, length.out=500)),
plot((1 + s) * exp(1i * s), type="l"))</syntaxhighlight>
 
Line 1,921:
 
[[File:archemedian-spiral-racket.png]]
<syntaxhighlight lang="racket">#lang racket/base
(require plot
racket/math)
Line 1,948:
{{works with|Rakudo|2018.10}}
 
<syntaxhighlight lang=perl6"raku" line>use Image::PNG::Portable;
 
my ($w, $h) = (400, 400);
Line 1,964:
 
Note: &nbsp; the value of &nbsp; <big><big> ''a'' </big></big> &nbsp; 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*/
if cy=='' | cy=="," then cy= 3 /*Not specified? Then use the default.*/
Line 2,205:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
/*
+---------------------------------------------------------------------------------------------------------
Line 2,316:
{{libheader|JRubyArt}}
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
attr_reader :x, :theta
Line 2,340:
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">#[macro_use(px)]
extern crate bmp;
 
Line 2,374:
 
=={{header|SAS}}==
<syntaxhighlight lang="sas">data xy;
h=constant('pi')/40;
do i=0 to 400;
Line 2,391:
=={{header|Scala}}==
===Java Swing Interoperability===
<syntaxhighlight lang=Scala"scala">
 
object ArchimedeanSpiral extends App {
Line 2,463:
{{libheader|Scheme/PsTk}}
 
<syntaxhighlight lang="scheme">
(import (scheme base)
(scheme complex)
Line 2,501:
 
=={{header|Scilab}}==
<syntaxhighlight lang="text">a = 3;
b = 2;
 
Line 2,522:
=={{header|Seed7}}==
 
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "draw.s7i";
include "keybd.s7i";
Line 2,552:
=={{header|Sidef}}==
{{trans|Raku}}
<syntaxhighlight lang="ruby">require('Imager')
define π = Num.pi
 
Line 2,570:
 
=={{header|Stata}}==
<syntaxhighlight lang="stata">clear all
scalar h=_pi/40
set obs 400
Line 2,581:
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"tcl">package require Tk
 
# create widgets
Line 2,648:
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">Private Sub plot_coordinate_pairs(x As Variant, y As Variant)
Dim chrt As Chart
Set chrt = ActiveSheet.Shapes.AddChart.Chart
Line 2,675:
{{trans|Sidef}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "dome" for Window
 
Line 2,706:
=={{header|XPL0}}==
Looks a lot like the C++ image.
<syntaxhighlight lang=XPL0"xpl0">real A, B, R, T, X, Y;
[SetVid($12); \set 640x480 graphics
A:= 0.0; B:= 3.0; T:= 0.0;
Line 2,719:
=={{header|Yabasic}}==
{{trans|Sinclair_ZX81_BASIC}}
<syntaxhighlight lang=Yabasic"yabasic">5 OPEN WINDOW 320, 200 : WINDOW ORIGIN "CC"
10 LET A=1.5
20 LET B=0.7
Line 2,730:
[[File:ArchimedeanSpiral.zk.jpg|250px|thumb|right]]
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;
bitmap:=PPM(w+1,h+1,0xFF|FF|FF); // White background
10,333

edits