Sierpinski square curve: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|J}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8:
{{trans|C++}}
<
V x = (size - length) / 2
V y = Float(length)
Line 35:
outfile.write("'/>\n</svg>\n")
sierpinski_square(‘sierpinski_square.svg’, 635, 5, 5)</
{{out}}
Line 42:
=={{header|C++}}==
Output is a file in SVG format.
<
#include <cmath>
#include <fstream>
Line 121:
s.write(out, 635, 5, 5);
return 0;
}</
{{out}}
Line 128:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<
: square-curve ( L-system -- L-system )
Line 141:
<L-system> square-curve
"Sierpinski square curve" open-window
] with-ui</
Line 178:
{{libheader|go-lindenmayer}}
The following uses the Lindenmayer system with the appropriate parameters from the Wikipedia article and produces a similar image (apart from the colors, yellow on blue) to the Sidef and zkl entries.
<
import (
Line 237:
dc.Stroke()
dc.SavePNG("sierpinski_square_curve.png")
}</
=={{header|J}}==
It looks like there's two different (though similar) concepts implemented here, of what a "Sierpinski square curve" looks like (the wikipedia writeup shows 45 degree angles -- like [[j:File:Sierpinski_curve.png]] but many of the implementations here show only right angles). And, the wikipedia writeup is obtuse about some of the details of the structure. And, we've got some dead links here. So, for now, a quickie ascii art implementation:<
# # # # # # # #
# # # #
Line 255:
# # # # # # # #
# # # #
# # # # # # # # </
=={{header|Java}}==
{{trans|C++}}
<
public class SierpinskiSquareCurve {
Line 349:
private static final String PRODUCTION = "XF-F+F-XF+F+XF-F+F-X";
private static final int ANGLE = 90;
}</
{{out}}
Line 366:
for the simple-turtle.jq module used in this entry. The `include`
statement assumes the file is in the pwd.
<
def rules: {"X": "XF-F+F-XF+F+XF-F+F-X"};
Line 393:
sierpinski_curve(5)
| path("none"; "red"; 1) | svg(1000)
</syntaxhighlight>
=={{header|Julia}}==
<
scurve = LSystem(Dict("X" => "XF-F+F-XF+F+XF-F+F-X"), "F+XF+F+XF")
Line 409:
showpreview = true
)
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang
{{out}}
Outputs a graphical version of a 3rd order Sierpinski curve.
Line 419:
{{trans|C++}}
We produce a SVG file.
<
type
Line 472:
var sc = SierpinskiCurve(file: outfile)
sc.write(635, 5, 5)
outfile.close()</
{{out}}
Line 478:
=={{header|Perl}}==
<
use warnings;
use SVG;
Line 514:
open my $fh, '>', 'sierpinski-square-curve.svg';
print $fh $svg->xmlify(-namespace=>'svg');
close $fh;</
See: [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/sierpinski-square-curve.svg sierpinski-square-curve.svg] (offsite SVG image)
Line 521:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Sierpinski_square_curve.htm here].
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Sierpinski_square_curve.exw
Line 583:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
and an svg-creating version:
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">rule</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"XF-F+F-XF+F+XF-F+F-X"</span>
Line 624:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">svgfmt</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #000000;">X</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">xt</span><span style="color: #0000FF;">+</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #000000;">Y</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">yt</span><span style="color: #0000FF;">+</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">points</span><span style="color: #0000FF;">,</span><span style="color: #000000;">xt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">yt</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
<!--</
=={{header|Python}}==
<
import math
Line 676:
s_angle = 90
draw_lsystem(s_axiom, s_rules, s_angle, 3)</
=={{header|Quackery}}==
<
[ stack ] is switch.arg ( --> [ )
Line 713:
char R case [ 1 4 turn ]
char F case [ 5 1 walk ]
otherwise ( ignore ) ] ]</
{{output}}
Line 723:
{{works with|Rakudo|2020.02}}
<syntaxhighlight lang="raku"
role Lindenmayer {
Line 766:
],
],
);</
See: [https://github.com/thundergnat/rc/blob/master/img/sierpinski-square-curve-perl6.svg Sierpinski-square-curve-perl6.svg] (offsite SVG image)
=={{header|Rust}}==
Program output is a file in SVG format.
<
// svg = "0.8.0"
Line 852:
fn main() {
SierpinskiSquareCurve::save("sierpinski_square_curve.svg", 635, 5.0, 5).unwrap();
}</
{{out}}
Line 859:
=={{header|Sidef}}==
Uses the '''LSystem()''' class from [https://rosettacode.org/wiki/Hilbert_curve#Sidef Hilbert curve].
<
x => 'xF-F+F-xF+F+xF-F+F-x',
)
Line 875:
)
lsys.execute('F+xF+F+xF', 5, "sierpiński_square_curve.png", rules)</
Output image: [https://github.com/trizen/rc/blob/master/img/sierpi%C5%84ski_square_curve-sidef.png Sierpiński square curve]
=={{header|VBScript}}==
Output to html (svg) displayed in the default browser. A turtle graphics class helps to keep the curve definition simple
<syntaxhighlight lang="vb">
option explicit
Line 1,034:
sierp 5,4
set x=nothing
</syntaxhighlight>
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
{{libheader|Wren-lsystem}}
<
import "dome" for Window
import "math" for Math
Line 1,094:
}
var Game = SierpinskiSquareCurve.new(770, 770, Color.blue, Color.yellow)</
=={{header|zkl}}==
Uses Image Magick and
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<
fcn sierpinskiSquareCurve(n){ // Lindenmayer system --> Data of As
Line 1,127:
}
img.writeJPGFile("sierpinskiSquareCurve.zkl.jpg");
}</
{{out}}
Offsite image at [http://www.zenkinetic.com/Images/RosettaCode/sierpinskiSquareCurve.zkl.jpg Sierpinski square curve of order 4]
|