Peano curve: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 7:
=={{header|Action!}}==
Action! language does not support recursion. Therefore an iterative approach with a stack has been proposed.
<langsyntaxhighlight Actionlang="action!">DEFINE MAXSIZE="12"
 
INT ARRAY
Line 102:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Peano_curve.png Screenshot from Atari 8-bit computer]
Line 109:
{{trans|C}}
{{libheader|APDF}}
<langsyntaxhighlight Adalang="ada">with PDF_Out; use PDF_Out;
 
procedure Peano_Curve is
Line 170:
Draw_Peano;
PDF.Close;
end Peano_Curve;</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
{{trans|C}}
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
<langsyntaxhighlight AutoHotkeylang="autohotkey">gdip1()
PeanoX := A_ScreenWidth/2 - 100, PeanoY := A_ScreenHeight/2 - 100
Peano(PeanoX, PeanoY, 3**3, 5, 5, Arr:=[])
Line 247:
ExitApp
Return
</syntaxhighlight>
</lang>
 
=={{header|C}}==
Adaptation of the C program in the [https://www.researchgate.net/profile/Christoph_Schierz2/publication/228982573_A_recursive_algorithm_for_the_generation_of_space-filling_curves/links/0912f505c2f419782c000000/A-recursive-algorithm-for-the-generation-of-space-filling-curves.pdf Breinholt-Schierz paper] , requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
<lang C>
/*Abhishek Ghosh, 14th September 2018*/
 
Line 287:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cmath>
#include <fstream>
#include <iostream>
Line 375:
pc.write(out, 656, 8, 4);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 382:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<langsyntaxhighlight lang="factor">USING: accessors L-system ui ;
 
: peano ( L-system -- L-system )
Line 393:
} >>rules ;
 
[ <L-system> peano "Peano curve" open-window ] with-ui</langsyntaxhighlight>
 
 
Line 436:
=={{header|FreeBASIC}}==
{{trans|Yabasic}}
<langsyntaxhighlight lang="freebasic">Const anchura = 243 'una potencia de 3 para una curva uniformemente espaciada
 
Screenres 700,700
Line 459:
Peano(0, 0, anchura, 0, 0)
 
Sleep</langsyntaxhighlight>
 
 
Line 466:
<br>
The following is based on the recursive algorithm and C code in [https://www.researchgate.net/profile/Christoph_Schierz2/publication/228982573_A_recursive_algorithm_for_the_generation_of_space-filling_curves/links/0912f505c2f419782c000000/A-recursive-algorithm-for-the-generation-of-space-filling-curves.pdf this paper] scaled up to 81 x 81 points. The image produced is a variant known as a Peano-Meander curve (see Figure 1(b) [https://www5.in.tum.de/lehre/vorlesungen/asc/ss17/blatt10/ws10.pdf here]).
<langsyntaxhighlight lang="go">package main
 
import "github.com/fogleman/gg"
Line 505:
dc.Stroke()
dc.SavePNG("peano.png")
}</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "PeanoC.bas"
110 OPTION ANGLE DEGREES
120 SET VIDEO MODE 5:SET VIDEO COLOR 0:SET VIDEO X 40:SET VIDEO Y 27
Line 524:
240 CALL PEANO(D,-A,LEV-1)
250 PLOT LEFT A;
260 END DEF</langsyntaxhighlight>
 
=={{header|J}}==
This Hilbert variant is taken directly from the j lab "viewmat".
<syntaxhighlight lang="j">
<lang j>
load'viewmat'
hp=: 3 : '(|.,]) 1 (0 _2 _2 ,&.> _2 _1 0 + #y) } (,.|:) y'
Line 534:
WR=: 16777215 16711680
viewrgb WR {~ hp ^:7 HP
</syntaxhighlight>
</lang>
 
Or, a smaller [[j:File:Hp1.png|example]] (6 iterations instead of 7) and a different color selection:<langsyntaxhighlight Jlang="j"> require 'viewmat'
hp=: 3 : '(|.,]) 1 (0 _2 _2 ,&.> _2 _1 0 + #y) } (,.|:) y'
MG=: 256 #. 128 0 128,:0 192 0
viewrgb 2 ([ # #"1) MG {~ hp ^:6 [ 0, 0 1 0 ,: 0,</langsyntaxhighlight>
 
=={{header|Java}}==
Output is a file in SVG format.
<langsyntaxhighlight lang="java">import java.io.*;
 
public class PeanoCurve {
Line 632:
private int currentAngle;
private static final int ANGLE = 90;
}</langsyntaxhighlight>
 
{{out}}
Line 651:
The output converted to a .png file can be viewed at https://imgur.com/gallery/4QbUN7I
====Simple Turtle Graphics====
<syntaxhighlight lang="jq">
<lang jq>
# => = 0 degrees
# ^ = 90 degrees
Line 693:
 
def draw:
path("none"; "red"; "0.1") | svg(100) ;</langsyntaxhighlight>
 
====Peano Curve====
<langsyntaxhighlight lang="jq"># Compute the curve using a Lindenmayer system of rules
def rules:
{ L: "LFRFL-F-RFLFR+F+LFRFL",
Line 723:
 
peano_curve(4)
| draw</langsyntaxhighlight>
{{out}}
See https://imgur.com/gallery/4QbUN7I
Line 736:
</pre>
 
<langsyntaxhighlight lang="jq"># Input: an array
# Output: the array augmented with another x,y pair
def peano($x; $y; $lg; $i1; $i2):
Line 772:
svg,
( path("none"; "red") + peanoCurve + endpath)
</syntaxhighlight>
</lang>
{{out}}
https://imgur.com/a/RGQr17J
Line 778:
=={{header|Julia}}==
The peano function is from the C version.
<langsyntaxhighlight lang="julia">using Gtk, Graphics, Colors
 
function peano(ctx, x, y, lg, i1, i2)
Line 816:
signal_connect(endit, win, :destroy)
wait(cond)
</syntaxhighlight>
</lang>
 
=={{header|Lua}}==
Using the Bitmap class [[Bitmap#Lua|here]], with an ASCII pixel representation, then extending..
<langsyntaxhighlight lang="lua">local PeanoLSystem = {
axiom = "L",
rules = {
Line 870:
bitmap:clear(" ")
bitmap:drawPath(PeanoLSystem:eval(3), 0, 0, 0, 1)
bitmap:render()</langsyntaxhighlight>
{{out}}
<pre style="font-size:50%;">@ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+ +---+
Line 928:
Draw to M2000 console (which has graphic capabilities). Sub is a copy from freebasic, changed *Line* statement to *Draw to*
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Peano_curve {
Cls 1, 0
Line 961:
}
Peano_curve
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang Mathematica="mathematica">Graphics[PeanoCurve[4]]</langsyntaxhighlight>
{{out}}
Outputs a graphical representation of a 4th order PeanoCurve.
Line 971:
{{trans|Go}}
{{libheader|imageman}}
<langsyntaxhighlight Nimlang="nim">import imageman
 
const Width = 81
Line 999:
for i in 1..points.high:
image.drawLine(points[i - 1], points[i], color)
image.savePNG("peano.png", compression = 9)</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use SVG;
use List::Util qw(max min);
 
Line 1,041:
open $fh, '>', 'peano_curve.svg';
print $fh $svg->xmlify(-namespace=>'svg');
close $fh;</langsyntaxhighlight>
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/peano_curve.svg Peano curve] (offsite image)
 
Line 1,049:
You can run this online [http://phix.x10.mx/p2js/peano.htm here].
Space key toggles between switchback and meander curves.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\peano_curve.exw
Line 1,181:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Processing}}==
{{trans|C}}
<langsyntaxhighlight lang="java">
//Abhishek Ghosh, 28th June 2022
 
Line 1,211:
Peano(0, 0, 1000, 0, 0);
}
</syntaxhighlight>
</lang>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">main:-
write_peano_curve('peano_curve.svg', 656, 4).
 
Line 1,270:
execute(Stream, X, Y, Length, Angle1, Chars).
execute(Stream, X, Y, Length, Angle, [_|Chars]):-
execute(Stream, X, Y, Length, Angle, Chars).</langsyntaxhighlight>
 
{{out}}
Line 1,280:
This implementation is, as I think, a variant of the Peano curve (just because it's different in the images). And it's supposed to be like a fullscreen app. And because of scale, the "steps" of the curve will be different in horizontal and vertical (it'll be quite nice if your screen is square :D). If <code>peano(4)</code> (in the last line of code) is runned with the input higher than 8, the void between the steps will be filled with steps, and the hole screen will fill (of course, this depends of your screen size). It's also produces a graphic with the current stack pilled, timed by the current function runned.
 
<langsyntaxhighlight lang="python">
import turtle as tt
import inspect
Line 1,358:
P.plot(stack)
P.show()
</syntaxhighlight>
</lang>
 
You can see the output image [https://github.com/jlfcosta/Projeto_2019_v2/blob/master/Exerc%C3%ADcios/Curva%20de%20Peano/opahehe1.png <ins>here</ins>] and the output stack graphic [https://github.com/jlfcosta/Projeto_2019_v2/blob/master/Exerc%C3%ADcios/Curva%20de%20Peano/opahehestacks1.png <ins>here</ins>].
Line 1,364:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
[ stack ] is switch.arg ( --> [ )
Line 1,399:
char L case [ -1 4 turn ]
char R case [ 1 4 turn ]
otherwise ( ignore ) ] ]</langsyntaxhighlight>
 
{{output}}
Line 1,409:
 
 
<langsyntaxhighlight lang="rsplus">
#to install hilbercurve library, biocmanager needs to be installed first
install.packages("BiocManager")
Line 1,422:
peano = HilbertCurve(1, 512, level = 4, reference = TRUE, arrow = FALSE)
hc_points(peano, x1 = i, np = NULL, pch = 16, size = unit(3, "mm"))
}</langsyntaxhighlight>
 
=={{header|Racket}}==
Line 1,430:
 
See also https://pdfs.semanticscholar.org/fee6/187cc2dd1679d4976db9522b06a49f63be46.pdf
<syntaxhighlight lang="racket">
<lang Racket>
/* Jens Axel Søgaard, 27th December 2018*/
#lang racket
Line 1,463:
(peano 6 90 3)
(draw* c))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.06}}
<syntaxhighlight lang="raku" perl6line>use SVG;
 
role Lindenmayer {
Line 1,496:
:polyline[ :points(@points.join: ','), :fill<black> ],
],
);</langsyntaxhighlight>
 
See: [https://github.com/thundergnat/rc/blob/master/img/peano-perl6.svg Peano curve] (SVG image)
Line 1,506:
<br/>
Implemented as a Lindenmayer System, depends on JRuby or JRubyComplete see Hilbert for grammar
<langsyntaxhighlight lang="ruby">
load_library :grammar
 
Line 1,591:
size(800, 800)
end
</syntaxhighlight>
</lang>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">// [dependencies]
// svg = "0.8.0"
 
Line 1,674:
fn main() {
PeanoCurve::save("peano_curve.svg", 656, 4).unwrap();
}</langsyntaxhighlight>
 
{{out}}
Line 1,681:
=={{header|Sidef}}==
Uses the LSystem class defined at [https://rosettacode.org/wiki/Hilbert_curve#Sidef Hilbert curve].
<langsyntaxhighlight lang="ruby">var rules = Hash(
l => 'lFrFl-F-rFlFr+F+lFrFl',
r => 'rFlFr+F+lFrFl-F-rFlFr',
Line 1,698:
)
 
lsys.execute('l', 4, "peano_curve.png", rules)</langsyntaxhighlight>
Output image: [https://github.com/trizen/rc/blob/master/img/peano_curve-sidef.png Peano curve]
 
=={{header|VBA}}==
{{trans|C}}
<langsyntaxhighlight lang="vb">Const WIDTH = 243 'a power of 3 for a evenly spaced curve
Dim n As Long
Dim points() As Single
Line 1,750:
Call Peano(0, 0, WIDTH, 0, 0) 'Start Peano recursion to generate and store points
ActiveSheet.Shapes.AddPolyline points 'Excel assumed
End Sub</langsyntaxhighlight>
 
=={{header|VBScript}}==
VBSCript does'nt have access to Windows graphics so I write SVG commands into an HML file and display it using the default browser. A turtle graphics class makes the recursive definition of the curve easy.
<syntaxhighlight lang="vb">
<lang vb>
 
option explicit
Line 1,857:
peano 7,1
set x=nothing 'show image in browser
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<langsyntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color, Point
import "dome" for Window
 
Line 1,905:
 
static draw(dt) {}
}</langsyntaxhighlight>
 
=={{header|Yabasic}}==
{{trans|VBA}}
<langsyntaxhighlight Yabasiclang="yabasic">WIDTH = 243 //a power of 3 for a evenly spaced curve
 
open window 700, 700
Line 1,930:
Peano(x + ((2 - i1 - i2) * lg), y + ((1 + i2 - i1) * lg), lg, 1 - i1, i2)
Peano(x + (2 * (1 - i2) * lg), y + (2 * i2 * lg), lg, 1 - i1, i2)
End Sub</langsyntaxhighlight>
 
=={{header|zkl}}==
Using a Lindenmayer system and turtle graphics & turned 90°:
<langsyntaxhighlight lang="zkl">lsystem("L", // axiom
Dictionary("L","LFRFL-F-RFLFR+F+LFRFL", "R","RFLFR+F+LFRFL-F-RFLFR"), # rules
"+-F", 4) // constants, order
Line 1,947:
}
buf1.text // n=4 --> 16,401 characters
}</langsyntaxhighlight>
Using Image Magick and
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<langsyntaxhighlight lang="zkl">fcn turtle(koch){
const D=10.0;
dir,angle, x,y := 0.0, (90.0).toRad(), 20.0, 830.0; // turtle; x,y are float
Line 1,966:
}
img.writeJPGFile("peanoCurve.zkl.jpg");
}</langsyntaxhighlight>
{{out}}
Image at [http://www.zenkinetic.com/Images/RosettaCode/peanoCurve.zkl.jpg Peano curve]
10,333

edits