Sierpinski 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.
<
DEFINE N_="20+"
DEFINE E_="30+"
Line 169:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sierpinski_curve.png Screenshot from Atari 8-bit computer]
Line 176:
{{trans|Go}}
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
<
SierpinskiH := 500
level := 5
Line 331:
ExitApp
Return
</syntaxhighlight>
=={{header|C++}}==
Output is a file in SVG format. The curve is generated using the Lindenmayer system method.
<
#include <cmath>
#include <fstream>
Line 415:
s.write(out, 545, 7, 5);
return 0;
}</
{{out}}
Line 422:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<
: curve ( L-system -- L-system )
Line 433:
} >>rules ;
[ <L-system> curve "Sierpinski curve" open-window ] with-ui</
Line 478:
{{trans|Phix}}
A partial translation anyway which produces a static image of a SC of level 5, yellow on blue, which can be viewed with a utility such as EOG.
<
import (
Line 595:
dc.Stroke()
dc.SavePNG("sierpinski_curve.png")
}</
=={{header|Java}}==
{{trans|C++}}
<
public class SierpinskiCurve {
Line 689:
private static final String PRODUCTION = "XF+G+XF--F--XF+G+X";
private static final int ANGLE = 45;
}</
{{out}}
Line 705:
depending on the location of the included file, and the command-line
options used.
<
# Compute the curve using a Lindenmayer system of rules
Line 745:
sierpinski_curve(5)
| svg
</syntaxhighlight>
=={{header|Julia}}==
===Turtle procedural (lineto) version===
Modified from [https://craftofcoding.wordpress.com/2018/05/08/recursive-patterns-the-sierpinski-curve/ Craft of Coding blog, Processing version]
<
function sierpinski_curve(x0, y0, h, level)
Line 802:
finish()
preview()
</syntaxhighlight>
===LSystem version===
<
sierpcurve = LSystem(Dict("X" => "XF+G+XF--F--XF+G+X"), "F--XF--F--XF")
Line 819:
showpreview = true
)
</syntaxhighlight>
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def sierp
{def sierp.r
Line 861:
stroke="#000" fill="transparent" stroke-width="1"}}
}
</syntaxhighlight>
See the result in http://lambdaway.free.fr/lambdawalks/?view=sierpinsky
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang
=={{header|Nim}}==
{{trans|C++}}
We produce a SVG file using same algorithm as the one of C++ version.
<
type
Line 924:
var sc = SierpinskiCurve(file: outfile)
sc.write(545, 7, 5)
outfile.close()</
{{out}}
Line 930:
=={{header|Perl}}==
<
use warnings;
use SVG;
Line 967:
open my $fh, '>', 'sierpinski-curve.svg';
print $fh $svg->xmlify(-namespace=>'svg');
close $fh;</
See: [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/sierpinski-curve.svg sierpinski-curve.svg] (offsite SVG image)
Line 974:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Sierpinski_curve.htm here].
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Sierpinski_curve.exw
Line 1,144:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</
=={{header|Processing}}==
{{trans|Go}}
<syntaxhighlight lang="processing">
// https://rosettacode.org/wiki/Sierpinski_curve#C.2B.2B
Line 1,293:
}
}
</syntaxhighlight>
{{out}}
Offsite image at [https://github.com/rupertrussell/sierpinski_curve/blob/main/Sierpinski_Curve_Level5.png Sierpinski_Curve_Level5.png]
Line 1,300:
=={{header|Python}}==
<
import matplotlib.pyplot as plt
from matplotlib.colors import hsv_to_rgb as hsv
Line 1,330:
#curve('F', {'F': 'G-F-G', 'G': 'F+G+F'}, 60, 7)
#curve('A', {'A': '+BF-AFA-FB+', 'B': '-AF+BFB+FA-'}, 90, 6)
#curve('FX+FX+', {'X': 'X+YF', 'Y': 'FX-Y'}, 90, 12)</
Output in the plot window.
Line 1,336:
=={{header|Quackery}}==
<
[ stack ] is switch.arg ( --> [ )
Line 1,372:
char A case [ ( ignore ) ]
otherwise [ 5 1 walk ] ] ]
-1 8 turn</
{{output}}
Line 1,382:
{{works with|Rakudo|2020.02}}
<syntaxhighlight lang="raku"
role Lindenmayer {
Line 1,420:
],
],
);</
See: [https://github.com/thundergnat/rc/blob/master/img/sierpinski-curve-perl6.svg Sierpinski-curve-perl6.svg] (offsite SVG image)
=={{header|Rust}}==
Program output is a file in SVG format.
<
// svg = "0.8.0"
Line 1,507:
fn main() {
SierpinskiCurve::save("sierpinski_curve.svg", 545, 5).unwrap();
}</
{{out}}
Line 1,514:
=={{header|Sidef}}==
Uses the '''LSystem()''' class from [https://rosettacode.org/wiki/Hilbert_curve#Sidef Hilbert curve].
<
x => 'xF+G+xF--F--xF+G+x',
)
Line 1,530:
)
lsys.execute('F--xF--F--xF', 5, "sierpiński_curve.png", rules)</
Output image: [https://github.com/trizen/rc/blob/master/img/sierpi%C5%84ski_curve-sidef.png Sierpiński curve]
Line 1,536:
{{trans|Go}}
{{libheader|DOME}}
<
import "dome" for Window
Line 1,664:
}
var Game = SierpinskiCurve.new(770, 770, 5, Color.blue, Color.yellow)</
=={{header|Yabasic}}==
<
// Adapted from https://www.ocg.at/sites/ocg.at/files/EuroLogo2001/P74Batagelj.pdf to Yabasic by Galileo, 01/2022
Line 1,694:
startTurtle()
Sierpinski(9, 12) </
=={{header|zkl}}==
Uses Image Magick and
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<
fcn sierpinskiCurve(order){
Line 1,729:
}
img.writeJPGFile("sierpinskiCurve.zkl.jpg");
}</
{{out}}
Offsite image at [http://www.zenkinetic.com/Images/RosettaCode/sierpinskiCurve.zkl.jpg Sierpinski curve order 5]
|