Peano curve: Difference between revisions

6,633 bytes added ,  18 days ago
m
→‎{{header|Quackery}}: Added link to description of method
m (syntax highlighting fixup automation)
m (→‎{{header|Quackery}}: Added link to description of method)
 
(19 intermediate revisions by 9 users not shown)
Line 171:
PDF.Close;
end Peano_Curve;</syntaxhighlight>
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-l-system}}
Generates an SVG file containing the curve using the L-System. Very similar to the Algol 68 Sierpinski square curve sample. Note the Algol 68 L-System library source code is on a separate page on Rosetta Code - follow the above link and then to the Talk page.<syntaxhighlight lang="algol68">
BEGIN # Peano Curve in SVG #
# uses the RC Algol 68 L-System library for the L-System evaluation & #
# interpretation #
 
PR read "lsystem.incl.a68" PR # include L-System utilities #
 
PROC peano curve = ( STRING fname, INT size, length, order, init x, init y )VOID:
IF FILE svg file;
BOOL open error := IF open( svg file, fname, stand out channel ) = 0
THEN
# opened OK - file already exists and #
# will be overwritten #
FALSE
ELSE
# failed to open the file #
# - try creating a new file #
establish( svg file, fname, stand out channel ) /= 0
FI;
open error
THEN # failed to open the file #
print( ( "Unable to open ", fname, newline ) );
stop
ELSE # file opened OK #
 
REAL x := init x;
REAL y := init y;
INT angle := 90;
put( svg file, ( "<svg xmlns='http://www.w3.org/2000/svg' width='"
, whole( size, 0 ), "' height='", whole( size, 0 ), "'>"
, newline, "<rect width='100%' height='100%' fill='white'/>"
, newline, "<path stroke-width='1' stroke='black' fill='none' d='"
, newline, "M", whole( x, 0 ), ",", whole( y, 0 ), newline
)
);
 
LSYSTEM ssc = ( "L"
, ( "L" -> "LFRFL-F-RFLFR+F+LFRFL"
, "R" -> "RFLFR+F+LFRFL-F-RFLFR"
)
);
STRING curve = ssc EVAL order;
curve INTERPRET ( ( CHAR c )VOID:
IF c = "F" THEN
x +:= length * cos( angle * pi / 180 );
y +:= length * sin( angle * pi / 180 );
put( svg file, ( " L", whole( x, 0 ), ",", whole( y, 0 ), newline ) )
ELIF c = "+" THEN
angle +:= 90 MODAB 360
ELIF c = "-" THEN
angle -:= 90 MODAB 360
FI
);
put( svg file, ( "'/>", newline, "</svg>", newline ) );
close( svg file )
FI # sierpinski square # ;
 
peano curve( "peano.svg", 1200, 12, 3, 50, 50 )
 
END
</syntaxhighlight>
 
=={{header|AutoHotkey}}==
Line 378 ⟶ 443:
 
{{out}}
[[Media:Peano_curve_cpp.svg]]
See: [https://slack-files.com/T0CNUL56D-F01GKJNB79U-4cdfc7bd42 peano_curve.svg] (offsite SVG image)
 
=={{header|EasyLang}}==
[https://easylang.online/show/#cod=jZK9boMwFIV3P8WRhbogrKQ/QwavnphYIwYXnMaqY5BNArx95YAJoR06INnnfNzje3Vb11QwfvRqaGHUTRkwyEE3lwTuapRPjiUYAXBqHAy6ZqKCAkDaBByUztfAVAm0he9cdZbOz7Vmf0Y0OPbwnWrxOlW0S9iDBKBPUdclOKrkyQVCGF8QpNiXW+LTKfmN/ZPMyF/H0MvLKiRavpdtHIm0d5cRRto4udrJPvoDRkj7BTb9bbRVva67M3bsLQiX5qYCRP4xLH2a2qOCPh45IOWoGo9au4c6BtVr+6yG9BgGQJmlYraqWGuHjIdX/+bSDZeuORYnMffOQXNKlqXhOAYBNBeFyDORFSIXRSrS+52CFuFba5GhKElcyfftMpLtyD9w2OGwI+QH Run it]
 
<syntaxhighlight>
proc lsysexp level . axiom$ rules$[] .
for l to level
an$ = ""
for c$ in strchars axiom$
for i = 1 step 2 to len rules$[]
if rules$[i] = c$
c$ = rules$[i + 1]
break 1
.
.
an$ &= c$
.
swap axiom$ an$
.
.
proc lsysdraw axiom$ x y ang . .
linewidth 0.3
move x y
for c$ in strchars axiom$
if c$ = "F"
x += cos dir
y += sin dir
line x y
elif c$ = "-"
dir -= ang
elif c$ = "+"
dir += ang
.
.
.
axiom$ = "L"
rules$[] = [ "L" "LFRFL-F-RFLFR+F+LFRFL" "R" "RFLFR+F+LFRFL-F-RFLFR" ]
lsysexp 4 axiom$ rules$[]
lsysdraw axiom$ 5 90 90
</syntaxhighlight>
 
=={{header|Factor}}==
Line 395 ⟶ 500:
[ <L-system> peano "Peano curve" open-window ] with-ui</syntaxhighlight>
 
[[File:Peano.png|thumb]]
 
When using the L-system visualizer, the following controls apply:
Line 428 ⟶ 534:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Peano_curve}}
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'''
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.
 
=== Peano-Meander variant, by recursion ===
In '''[https://formulae.org/?example=Peano_curve this]''' page you can see the program(s) related to this task and their results.
 
[[File:Fōrmulæ - Peano curve 01.png]]
 
[[File:Fōrmulæ - Peano curve 02.png]]
 
[[File:Fōrmulæ - Peano curve 03.png]]
 
'''Test cases'''
 
=== Peano-Meander variant, by L-system ===
 
There are generic functions written in Fōrmulæ to compute an L-system in the page [[L-system#Fōrmulæ | L-system]].
 
The program that creates a Peano-Meander curve is:
 
[[File:Fōrmulæ - L-system - Peano-Meander curve 01.png]]
 
[[File:Fōrmulæ - L-system - Peano-Meander curve 02.png]]
 
=== Switch-back variant, by L-system ===
 
The program that creates a Switch-back Peano curve is:
 
[[File:Fōrmulæ - L-system - Peano Curve 01.png]]
 
[[File:Fōrmulæ - L-system - Peano Curve 02.png]]
 
=={{header|FreeBASIC}}==
Line 461 ⟶ 593:
Sleep</syntaxhighlight>
 
=={{header|FutureBasic}}==
Couldn't help adding a little bling.
<syntaxhighlight lang="futurebasic">
_window = 1
_curveSize = 7
_curveOrder = 3 * 3 * 3 * 3 // 3^4
 
void local fn BuildWindow
CGRect r = fn CGRectMake( 0, 0, 565, 570 )
window _window, @"Peano Curve In FutureBasic", r, NSWindowStyleMaskTitled
WindowSetBackgroundColor( _window, fn ColorBlack )
end fn
 
local fn Peano( x as long, y as long, lg as long, i1 as long, i2 as long )
ColorRef color = fn ColorRed
if ( lg == 1 ) then line to x * _curveSize, y * _curveSize : exit fn
lg /= 3
select ( rnd(8) )
case 1 : color = fn ColorBrown
case 2 : color = fn ColorRed
case 3 : color = fn ColorOrange
case 4 : color = fn ColorYellow
case 5 : color = fn ColorGreen
case 6 : color = fn ColorBlue
case 7 : color = fn ColorPurple
case 8 : color = fn ColorWhite
end select
pen 2, color
fn Peano( x + 2*i1* lg, y + 2*i1* lg, lg, i1, i2 )
fn Peano( x + (i1-i2+1)*lg, y + (i1+i2)* lg, lg, i1, 1-i2 )
fn Peano( x + lg, y + lg, lg, i1, 1-i2 )
fn Peano( x + (i1+i2)* lg, y + (i1-i2+1)*lg, lg, 1-i1, 1-i2 )
fn Peano( x + 2*i2* lg, y + 2*(1-i2)* lg, lg, i1, i2 )
fn Peano( x + (1+i2-i1)*lg, y + (2-i1-i2)*lg, lg, i1, i2 )
fn Peano( x + 2*(1-i1)* lg, y + 2*(1-i1)* lg, lg, i1, i2 )
fn Peano( x + (2-i1-i2)*lg, y + (1+i2-i1)*lg, lg, 1-i1, i2 )
fn Peano( x + 2*(1-i2)* lg, y + 2*i2* lg, lg, 1-i1, i2 )
end fn
 
randomize
fn BuildWindow
fn Peano( 0, 0, _curveOrder, 0, 0 )
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Rosetta_Code_Peano_Curve_rev.png]]
 
=={{header|Go}}==
Line 635 ⟶ 817:
 
{{out}}
[[Media:Peano_curve_java.svg]]
See: [https://slack-files.com/T0CNUL56D-F017FM1JKM2-dc8a4b1575 peano_curve.svg] (offsite SVG image)
 
=={{header|jq}}==
Line 1,273 ⟶ 1,455:
 
{{out}}
[[Media:Peano_curve_prolog.svg]]
See: [https://slack-files.com/T0CNUL56D-F0179PCAUSF-addac3a9f7 peano_curve.svg] (offsite SVG image)
 
=={{header|Python}}==
Line 1,363 ⟶ 1,545:
 
=={{header|Quackery}}==
 
(Method is described at [[L-system#Quackery]].)
 
<syntaxhighlight lang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
Line 1,403 ⟶ 1,587:
{{output}}
 
[[File:Quackery Peano curve.png]]
https://imgur.com/PCi2cSZ
 
=={{header|R}}==
Line 1,677 ⟶ 1,861:
 
{{out}}
[[Media:Peano_curve_rust.svg]]
See: [https://slack-files.com/T0CNUL56D-F01749MF7TM-70dda622c5 peano_curve.svg] (offsite SVG image)
 
=={{header|Sidef}}==
Line 1,862 ⟶ 2,046:
{{trans|Go}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color, Point
import "dome" for Window
 
Line 1,906 ⟶ 2,090:
static draw(dt) {}
}</syntaxhighlight>
 
=={{header|XPL0}}==
{{trans|C}}
<syntaxhighlight lang "XPL0">proc Peano(X, Y, Lg, I1, I2);
int X, Y, Lg, I1, I2;
[if Lg = 1 then
[Line(3*X, 3*Y, 11 \cyan\);
return;
];
Lg:= Lg/3;
Peano(X + 2*I1* Lg, Y + 2*I1* Lg, Lg, I1, I2);
Peano(X + (I1-I2+1)*Lg, Y + (I1+I2)* Lg, Lg, I1, 1-I2);
Peano(X + Lg, Y + Lg, Lg, I1, 1-I2);
Peano(X + (I1+I2)* Lg, Y + (I1-I2+1)*Lg, Lg, 1-I1, 1-I2);
Peano(X + 2*I2* Lg, Y + 2*(1-I2)* Lg, Lg, I1, I2);
Peano(X + (1+I2-I1)*Lg, Y + (2-I1-I2)*Lg, Lg, I1, I2);
Peano(X + 2*(1-I1)* Lg, Y + 2*(1-I1)* Lg, Lg, I1, I2);
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);
];
 
[SetVid($13);
Peano(0, 0, 3*3*3*3, 0, 0); \start Peano recursion
]</syntaxhighlight>
{{out}}
[[File:PianoXPL0.gif]]
 
=={{header|Yabasic}}==
1,462

edits