Peano curve: Difference between revisions

3,934 bytes added ,  1 month ago
→‎{{header|Fōrmulæ}}: added Peano-Meander variant by L-system
(Added Easylang)
(→‎{{header|Fōrmulæ}}: added Peano-Meander variant by L-system)
(4 intermediate revisions by 3 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 381 ⟶ 446:
 
=={{header|EasyLang}}==
[https://easylang.online/show/#cod=jZK9boMwFIV3P8WRhbogrKQ/QwavnphYIwYXnMaqY5BNArx95YAJoR06INnnfNzje3Vb11QwfvRqaGHUTRkwyEE3lwTuapRPjiUYAXBqHAy6ZqKCAkDaBByUztfAVAm0he9cdZbOz7Vmf0Y0OPbwnWrxOlW0S9iDBKBPUdclOKrkyQVCGF8QpNiXW+LTKfmN/ZPMyF/H0MvLKiRavpdtHIm0d5cRRto4udrJPvoDRkj7BTb9bbRVva67M3bsLQiX5qYCRP4xLH2a2qOCPh45IOWoGo9au4c6BtVr+6yG9BgGQJmlYraqWGuHjIdX/+bSDZeuORYnMffOQXNKlqXhOAYBNBeFyDORFSIXRSrS+52CFuFba5GhKElcyfftMpLtyD9w2OGwI+QH Run it]
[https://easylang.online/show/#cod=jZK9boMwFIV3P8WRhbogLNKfIYNXT0ysEYMLprHqGGSThLx95YAJoR06INnnfNzje3V719VQYy9tA6MuyoBBjro7JXBno3xyqMAIgLZzMBi6iQoKAGkTcFA6XwNTJ9AWfnD1UTo/15r9GdHg2MEPqsfrVNEuYQ8SgG6jritw1MmTC4QwviBIsau2xKdT8hu7J5mRv46hl5dVSLT8VfZxJNLeXUYY6cPgGiev0Rtxg7RfYNOfRlt11c1wRM7egnDqLipA5B+D0u3UGhX08cARKUfdeTTaPdRbUL22z2pIj2EAlFkqZquKjXbIeHj1by7dcOmaY3EKc+8ctKBkWRiOQxBAC1GKIhNZKQpRpiK93yloGb61FhmKiszb+L7dQ7Ke9gf2OfY5IT8= Run it]
 
<syntaxhighlight>
proc expandlsysexp level . axiom$ rules$[] .
for l to level
an$ = ""
Line 399 ⟶ 464:
.
.
proc drawlsysdraw axiom$ x y ang . .
linewidth 0.3
move x y
Line 416 ⟶ 481:
axiom$ = "L"
rules$[] = [ "L" "LFRFL-F-RFLFR+F+LFRFL" "R" "RFLFR+F+LFRFL-F-RFLFR" ]
expandlsysexp 4 axiom$ rules$[]
drawlsysdraw axiom$ 5 90 90
</syntaxhighlight>
 
Line 472 ⟶ 537:
 
'''Solution'''
 
=== Peano-Meander variant, by recursion ===
 
[[File:Fōrmulæ - Peano curve 01.png]]
 
'''Test cases'''
 
[[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}}==
2,120

edits