Peano curve: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) 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.
<
INT ARRAY
Line 102:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</
{{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}}
<
procedure Peano_Curve is
Line 170:
Draw_Peano;
PDF.Close;
end Peano_Curve;</
=={{header|AutoHotkey}}==
{{trans|C}}
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
<
PeanoX := A_ScreenWidth/2 - 100, PeanoY := A_ScreenHeight/2 - 100
Peano(PeanoX, PeanoY, 3**3, 5, 5, Arr:=[])
Line 247:
ExitApp
Return
</syntaxhighlight>
=={{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">
/*Abhishek Ghosh, 14th September 2018*/
Line 287:
return 0;
}
</syntaxhighlight>
=={{header|C++}}==
<
#include <fstream>
#include <iostream>
Line 375:
pc.write(out, 656, 8, 4);
return 0;
}</
{{out}}
Line 382:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<
: peano ( L-system -- L-system )
Line 393:
} >>rules ;
[ <L-system> peano "Peano curve" open-window ] with-ui</
Line 436:
=={{header|FreeBASIC}}==
{{trans|Yabasic}}
<
Screenres 700,700
Line 459:
Peano(0, 0, anchura, 0, 0)
Sleep</
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]).
<
import "github.com/fogleman/gg"
Line 505:
dc.Stroke()
dc.SavePNG("peano.png")
}</
=={{header|IS-BASIC}}==
<
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</
=={{header|J}}==
This Hilbert variant is taken directly from the j lab "viewmat".
<syntaxhighlight 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>
Or, a smaller [[j:File:Hp1.png|example]] (6 iterations instead of 7) and a different color selection:<
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,</
=={{header|Java}}==
Output is a file in SVG format.
<
public class PeanoCurve {
Line 632:
private int currentAngle;
private static final int ANGLE = 90;
}</
{{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">
# => = 0 degrees
# ^ = 90 degrees
Line 693:
def draw:
path("none"; "red"; "0.1") | svg(100) ;</
====Peano Curve====
<
def rules:
{ L: "LFRFL-F-RFLFR+F+LFRFL",
Line 723:
peano_curve(4)
| draw</
{{out}}
See https://imgur.com/gallery/4QbUN7I
Line 736:
</pre>
<
# 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>
{{out}}
https://imgur.com/a/RGQr17J
Line 778:
=={{header|Julia}}==
The peano function is from the C version.
<
function peano(ctx, x, y, lg, i1, i2)
Line 816:
signal_connect(endit, win, :destroy)
wait(cond)
</syntaxhighlight>
=={{header|Lua}}==
Using the Bitmap class [[Bitmap#Lua|here]], with an ASCII pixel representation, then extending..
<
axiom = "L",
rules = {
Line 870:
bitmap:clear(" ")
bitmap:drawPath(PeanoLSystem:eval(3), 0, 0, 0, 1)
bitmap:render()</
{{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">
Module Peano_curve {
Cls 1, 0
Line 961:
}
Peano_curve
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang
{{out}}
Outputs a graphical representation of a 4th order PeanoCurve.
Line 971:
{{trans|Go}}
{{libheader|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)</
=={{header|Perl}}==
<
use List::Util qw(max min);
Line 1,041:
open $fh, '>', 'peano_curve.svg';
print $fh $svg->xmlify(-namespace=>'svg');
close $fh;</
[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.
<!--<
<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>
<!--</
=={{header|Processing}}==
{{trans|C}}
<
//Abhishek Ghosh, 28th June 2022
Line 1,211:
Peano(0, 0, 1000, 0, 0);
}
</syntaxhighlight>
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<
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).</
{{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.
<
import turtle as tt
import inspect
Line 1,358:
P.plot(stack)
P.show()
</syntaxhighlight>
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}}==
<
[ stack ] is switch.arg ( --> [ )
Line 1,399:
char L case [ -1 4 turn ]
char R case [ 1 4 turn ]
otherwise ( ignore ) ] ]</
{{output}}
Line 1,409:
<
#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"))
}</
=={{header|Racket}}==
Line 1,430:
See also https://pdfs.semanticscholar.org/fee6/187cc2dd1679d4976db9522b06a49f63be46.pdf
<syntaxhighlight lang="racket">
/* Jens Axel Søgaard, 27th December 2018*/
#lang racket
Line 1,463:
(peano 6 90 3)
(draw* c))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.06}}
<syntaxhighlight lang="raku"
role Lindenmayer {
Line 1,496:
:polyline[ :points(@points.join: ','), :fill<black> ],
],
);</
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
<
load_library :grammar
Line 1,591:
size(800, 800)
end
</syntaxhighlight>
=={{header|Rust}}==
<
// svg = "0.8.0"
Line 1,674:
fn main() {
PeanoCurve::save("peano_curve.svg", 656, 4).unwrap();
}</
{{out}}
Line 1,681:
=={{header|Sidef}}==
Uses the LSystem class defined at [https://rosettacode.org/wiki/Hilbert_curve#Sidef Hilbert curve].
<
l => 'lFrFl-F-rFlFr+F+lFrFl',
r => 'rFlFr+F+lFrFl-F-rFlFr',
Line 1,698:
)
lsys.execute('l', 4, "peano_curve.png", rules)</
Output image: [https://github.com/trizen/rc/blob/master/img/peano_curve-sidef.png Peano curve]
=={{header|VBA}}==
{{trans|C}}
<
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</
=={{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">
option explicit
Line 1,857:
peano 7,1
set x=nothing 'show image in browser
</syntaxhighlight>
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<
import "dome" for Window
Line 1,905:
static draw(dt) {}
}</
=={{header|Yabasic}}==
{{trans|VBA}}
<
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</
=={{header|zkl}}==
Using a Lindenmayer system and turtle graphics & turned 90°:
<
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
}</
Using Image Magick and
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<
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");
}</
{{out}}
Image at [http://www.zenkinetic.com/Images/RosettaCode/peanoCurve.zkl.jpg Peano curve]
|