Sierpinski arrowhead curve: Difference between revisions

m
(Ada version)
 
(31 intermediate revisions by 12 users not shown)
Line 8:
{{trans|Nim}}
 
<langsyntaxhighlight lang="11l">V sqrt3_2 = sqrt(3) / 2
 
F sierpinski_arrowhead_next(points)
Line 34:
V size = 600
V iterations = 8
V outfile = File(‘sierpinski_arrowhead.svg’, ‘w’WRITE)
 
outfile.write(‘<svg xmlns='http://www.w3.org/2000/svg' width='’size‘' height='’size"'>\n")
Line 49:
outfile.write(I L.index == 0 {‘M’} E ‘L’)
outfile.write(point.x‘,’point.y"\n")
outfile.write("'/>\n</svg>\n")</langsyntaxhighlight>
 
{{out}}
Line 56:
=={{header|Ada}}==
{{libheader|APDF}}Even order curves are drawn pointing downwards.
<langsyntaxhighlight Adalang="ada">with Ada.Command_Line;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
Line 119:
Rule => Nonzero_Winding_Number);
Doc.Close;
end Arrowhead_Curve;</langsyntaxhighlight>
 
=={{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 # Sierpinski Arrowhead 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 sierpinski arrowhead 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 := 0;
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 = ( "XF"
, ( "X" -> "YF+XF+Y"
, "Y" -> "XF-YF-X"
)
);
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 +:= 60 MODAB 360
ELIF c = "-" THEN
angle -:= 60 MODAB 360
FI
);
put( svg file, ( "'/>", newline, "</svg>", newline ) );
close( svg file )
FI # sierpinski square # ;
 
sierpinski arrowhead curve( "sierpinski_arrowhead.svg", 1200, 12, 6, 200, 700 )
 
END
</syntaxhighlight>
 
=={{header|ALGOL W}}==
Produces an Ascii Art Sierpinski Arrowhead Curve using the algorithm from the Wikipedia page.<br>
Note that the Wikipedia algotrithm draws even order curves with the base at the top.
<langsyntaxhighlight lang="algolw">begin % draw sierpinski arrowhead curves using ascii art %
integer CANVAS_WIDTH;
CANVAS_WIDTH := 200;
Line 240 ⟶ 306:
end for_order
end
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 283 ⟶ 349:
{{trans|Go}}
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
<langsyntaxhighlight AutoHotkeylang="autohotkey">order := 7
theta := 0
 
Line 387 ⟶ 453:
Gdip_Shutdown(pToken)
ExitApp
Return</langsyntaxhighlight>
 
=={{header|C}}==
This code is based on the Phix and Go solutions, but produces a file in SVG format.
<langsyntaxhighlight lang="c">// See https://en.wikipedia.org/wiki/Sierpi%C5%84ski_curve#Arrowhead_curve
#include <math.h>
#include <stdio.h>
Line 456 ⟶ 522:
fclose(out);
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
{{out}}
[[Media:Sierpinski_arrowhead_c.svg]]
See: [https://slack-files.com/T0CNUL56D-F016A6S357Z-dde1d67b8c sierpinski_arrowhead.svg] (offsite SVG image)
 
=={{header|C++}}==
The output of this program is an SVG file.
<langsyntaxhighlight lang="cpp">#include <fstream>
#include <iostream>
#include <vector>
Line 528 ⟶ 594:
write_sierpinski_arrowhead(out, 600, 8);
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
{{out}}
[[Media:Sierpinski_arrowhead_cpp.svg]]
See: [https://slack-files.com/T0CNUL56D-F016A6S357Z-dde1d67b8c sierpinski_arrowhead.svg] (offsite SVG image)
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
[[File:DelphiSierpinskiArrowhead.png|frame|none]]
<syntaxhighlight lang="Delphi">
 
type T2DVector=packed record
X,Y: double;
end;
 
var Pos: T2DVector;
var CurAngle: double;
 
 
procedure Turn(Angle: double);
{Turn current angle by specified degrees}
begin
CurAngle:=CurAngle+Angle;
end;
 
 
procedure DrawLine(Canvas: TCanvas; Len: double);
{Draw current line, rotated by the current angle}
var P2: T2DVector;
begin
Canvas.Pen.Mode:=pmCopy;
Canvas.Pen.Style:=psSolid;
P2.X:= Pos.X + Len*Cos(DegToRad(CurAngle));
P2.Y:= Pos.Y - Len*Sin(DegToRad(CurAngle));
Canvas.MoveTo(Round(Pos.X),Round(Pos.Y));
Canvas.LineTo(Round(P2.X),Round(P2.Y));
Pos:=P2;
end;
 
procedure Curve(Canvas: TCanvas; Order: integer; Length: double; Angle: integer);
{Recursively draw curve of specified order and based specified Angle}
begin
if 0 = Order then DrawLine(Canvas,Length)
else
begin
Curve(Canvas,Order - 1, Length / 2, -Angle);
Turn(angle);
curve(Canvas,Order - 1, Length / 2, Angle);
Turn(angle);
Curve(Canvas,Order - 1, Length / 2, -Angle);
end;
end;
 
 
procedure SierpinskiArrowheadCurve(Image: TImage; Order: integer; Length: double);
{Draw arrowhead curve of specified order.}
{Length controls the width of one side of the arrowhead }
begin
Pos.X:=10; Pos.Y:=10;
if (Order and 1)=0 then Curve(Image.Canvas, Order, Length, +60)
else
begin
{Order is odd}
Turn(+60);
Curve(Image.Canvas, Order, Length, -60);
end;
end;
 
 
procedure ShowSierpinskiArrowhead(Image: TImage);
var Size: double;
begin
if Image.Width>Image.Height then Size:=Image.Height/0.9
else Size:=Image.Width;
{Super impose three different orders, colors and line-widths}
Image.Canvas.Pen.Color:=clBlack;
Image.Canvas.Pen.Width:=3;
SierpinskiArrowheadCurve(Image,4, Size);
Image.Canvas.Pen.Color:=clBlue;
Image.Canvas.Pen.Width:=2;
SierpinskiArrowheadCurve(Image,6, Size);
Image.Canvas.Pen.Color:=clRed;
Image.Canvas.Pen.Width:=1;
SierpinskiArrowheadCurve(Image,8, Size);
end;
 
</syntaxhighlight>
{{out}}
<pre>
Elapsed Time: 50.555 ms.
 
</pre>
 
=={{header|EasyLang}}==
 
[https://easylang.dev/show/#cod=hZBNDgIhDIX3PcVL3PgTEE3GiQsOQxCVBMEMOs7c3qKMi9nYBen7Wl6bDtBoaOR3p8jECycHRcFH9/KnxxVKNrQA3btkYZ9dj4QAAwlJAPyZtYYqOceAjYZNGcVojVDxWHD2cYbLEP4yFulCdhUnCF5m6sFWY1/Fb/5SmFVlxZLdzbzF/KlPFpIk3VL/XeRTbXFUEHyENw== Run it]
 
<syntaxhighlight lang="easylang">
x = 5
y = 10
ang = 60
linewidth 0.5
#
proc curv o l a . .
if o = 0
x += cos ang * l
y += sin ang * l
line x y
else
o -= 1
l /= 2
curv o l (-a)
ang += a
curv o l a
ang += a
curv o l (-a)
.
.
move x y
curv 7 90 -60
</syntaxhighlight>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<langsyntaxhighlight lang="factor">USING: accessors L-system ui ;
 
: arrowhead ( L-system -- L-system )
Line 546 ⟶ 730:
} >>rules ;
 
[ <L-system> arrowhead "Arrowhead" open-window ] with-ui</langsyntaxhighlight>
 
 
Line 578 ⟶ 762:
| x || iterate L-system
|}
 
 
=={{header|Forth}}==
Line 585 ⟶ 768:
 
===ASCII===
<langsyntaxhighlight lang="forth">( ASCII output with use of ANSI terminal control )
 
: draw-line ( direction -- )
Line 619 ⟶ 802:
;
 
5 arrowhead</langsyntaxhighlight>
 
{{out}}
Line 660 ⟶ 843:
 
===SVG file===
<langsyntaxhighlight lang="forth">( SVG ouput )
 
: draw-line ( direction -- ) \ line-length=10 ; sin(60)=0.87 ; cos(60)=0.5
Line 709 ⟶ 892:
;
 
5 arrowhead</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
{{trans|XPL0}}
<syntaxhighlight lang="vb">#define pi 4 * Atn(1)
#define yellow Rgb(255,255,0)
 
Dim Shared As Integer posX, posY
Dim Shared As Single direc
 
Sub Curva(orden As Byte, largo As Single, angulo As Integer)
If orden = 0 Then
posX += Fix(largo * Cos(direc))
posY -= Fix(largo * Sin(direc))
Line - (posX, posY), yellow
Else
Curva(orden-1, largo/2, -angulo)
direc += angulo
Curva(orden-1, largo/2, +angulo)
direc += angulo
Curva(orden-1, largo/2, -angulo)
End If
End Sub
 
Screenres 640, 480, 32
 
Dim As Integer x, y
Dim As Byte orden = 5
Dim As Integer tam = 2^orden
Dim As Single largo = 300
Dim As Single sixty = pi/3
 
direc = 0
posX = 640/4
posY = 3*480/4
Pset (posX, posY)
 
If (orden And 1) = 0 Then
Curva(orden, largo, +sixty)
Else
direc += sixty
Curva(orden, largo, -sixty)
End If
 
Windowtitle "Hit any key to end program"
Sleep</syntaxhighlight>
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/L-system}}
 
'''Solution'''
 
It can be done using an [[wp:L-system|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 Sierpiński arrowhead is:
 
[[File:Fōrmulæ - L-system - Sierpiński triangle (rounded) 01.png]]
 
[[File:Fōrmulæ - L-system - Sierpiński triangle (rounded) 02.png]]
 
=={{header|Go}}==
Line 717 ⟶ 957:
{{trans|Phix}}
A partial translation anyway which produces a static image of a SAC of order 6, magenta on black, which can be viewed with a utility such as EOG.
<langsyntaxhighlight lang="go">package main
 
import (
Line 782 ⟶ 1,022:
dc.Stroke()
dc.SavePNG("sierpinski_arrowhead_curve.png")
}</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
<syntaxhighlight lang="is-basic">100 PROGRAM "Sierpin2.bas"
110 LET LEVEL=5
120 OPTION ANGLE DEGREES
130 SET VIDEO MODE 1:SET VIDEO COLOUR 0:SET VIDEO X 40:SET VIDEO Y 27
140 OPEN #101:"video:"
150 SET PALETTE BLACK,YELLOW
160 DISPLAY #101:AT 1 FROM 1 TO 27
170 PLOT 1180,20,ANGLE 180;
180 CALL SIERP(560,LEVEL)
190 DEF CURVE(D,A,LEV)
200 IF LEV=0 THEN
210 PLOT FORWARD D;
220 ELSE
230 CALL CURVE(D/2,-A,LEV-1)
240 PLOT RIGHT A;
250 CALL CURVE(D/2,A,LEV-1)
260 PLOT RIGHT A;
270 CALL CURVE(D/2,-A,LEV-1)
280 END IF
290 END DEF
300 DEF SIERP(D,LEV)
310 CALL CURVE(D,60,LEV)
320 PLOT LEFT 60;
330 CALL CURVE(D,-60,LEV)
340 PLOT LEFT 60;
350 CALL CURVE(D,60,LEV)
360 END DEF</syntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
 
import java.awt.Point;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
public final class SierpinskiArrowhead {
 
public static void main(String[] aArgs) throws IOException {
List<Point> points = initialStraightLine();
for ( int i = 1; i < 8; i++ ) {
points = nextIteration(points);
}
String text = sierpinskiArrowheadText(points, IMAGE_SIZE);
Files.write(Paths.get("sierpinkskiArrowhead.svg"), text.getBytes());
}
private static List<Point> initialStraightLine() {
final int margin = 50;
final int boxSize = IMAGE_SIZE - 2 * margin;
final int x = margin;
final int y = Math.round(( IMAGE_SIZE + SQRT3_2 * boxSize ) / 2.0F);
List<Point> points = Arrays.asList( new Point(x, y), new Point(x + boxSize, y) );
return points;
}
private static List<Point> nextIteration(List<Point> aPoints) {
List<Point> result = new ArrayList<Point>();
for ( int i = 0; i < aPoints.size() - 1; i++ ) {
final int x0 = aPoints.get(i).x;
final int y0 = aPoints.get(i).y;
final int x1 = aPoints.get(i + 1).x;
final int y1 = aPoints.get(i + 1).y;
final int dx = x1 - x0;
result.add( new Point(x0, y0) );
if ( y0 == y1 ) {
final float d = Math.abs(dx) * SQRT3_2 / 2;
result.add( new Point(x0 + dx / 4, Math.round(y0 - d)) );
result.add( new Point(x1 - dx / 4, Math.round(y0 - d)) );
} else if ( y1 < y0 ) {
result.add( new Point(x1, y0));
result.add( new Point(x1 + dx / 2, ( y0 + y1 ) / 2) );
} else {
result.add( new Point(x0 - dx / 2, ( y0 + y1 ) / 2) );
result.add( new Point(x0, y1) );
}
}
result.add(aPoints.get(aPoints.size() - 1));
return result;
}
private static String sierpinskiArrowheadText(List<Point> aPoints, int aSize) {
StringBuilder text = new StringBuilder();
text.append("<svg xmlns='http://www.w3.org/2000/svg'");
text.append(" width='" + aSize + "' height='" + aSize + "'>\n");
text.append("<rect width='100%' height='100%' fill='white'/>\n");
text.append("<path stroke-width='1' stroke='black' fill='white' d='");
for ( int i = 0; i < aPoints.size(); i++ ) {
text.append(( i == 0 ? "M" : "L" ) + aPoints.get(i).x + ", " + aPoints.get(i).y + " ");
}
text.append("'/>\n</svg>\n");
return text.toString();
}
private static final float SQRT3_2 = (float) Math.sqrt(3.0F) / 2.0F;
private static final int IMAGE_SIZE = 700;
 
}
</syntaxhighlight>
{{out}}
[[Media:SierpinskiArrowheadJava.svg]]
 
=={{header|jq}}==
Line 795 ⟶ 1,147:
depending on the location of the included file, and the command-line
options used.
<langsyntaxhighlight lang="jq">include "turtle" {search: "."};
 
# Compute the curve using a Lindenmayer system of rules
Line 835 ⟶ 1,187:
sierpinski_curve(8)
| svg
</syntaxhighlight>
</lang>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Lindenmayer # https://github.com/cormullion/Lindenmayer.jl
scurve = LSystem(Dict("F" => "G+F+Gt", "G"=>"F-G-F"), "G")
Line 851 ⟶ 1,203:
showpreview = true
)
</syntaxhighlight>
</lang>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
<lang Scheme>
{def sierp
{def sierp.r
Line 874 ⟶ 1,226:
 
the output can be seen in http://lambdaway.free.fr/lambdawalks/?view=sierpinsky
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[DoStep]
DoStep[Line[{x_, y_}]] := Module[{diff, perp, pts},
diff = y - x;
Line 886 ⟶ 1,238:
lns = {Line[{{0.0, 0.0}, {1.0, 0.0}}]};
lns = Nest[Catenate[DoStep /@ #] &, lns, 5];
Graphics[lns]</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|C++}}
Output is an SVG file.
<langsyntaxhighlight Nimlang="nim">import math
 
const Sqrt3_2 = sqrt(3.0) / 2.0
Line 938 ⟶ 1,290:
let outfile = open("sierpinski_arrowhead.svg", fmWrite)
outfile.writeSierpinskiArrowhead(600, 8)
outfile.close()</langsyntaxhighlight>
 
{{out}}
Line 944 ⟶ 1,296:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use SVG;
Line 983 ⟶ 1,335:
open my $fh, '>', 'sierpinski-arrowhead-curve.svg';
print $fh $svg->xmlify(-namespace=>'svg');
close $fh;</langsyntaxhighlight>
See: [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/sierpinski-arrowhead-curve.svg sierpinski-arrowhead-curve.svg] (offsite SVG image)
 
Line 989 ⟶ 1,341:
{{libheader|Phix/pGUI}}
You can run this online [http://phix.x10.mx/p2js/Sierpinski_arrowhead_curve.htm here], and experiment with [shift] +/- as noted below.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Sierpinski_arrowhead_curve.exw
Line 1,113 ⟶ 1,465:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Processing}}==
<langsyntaxhighlight lang="java">final PVector t = new PVector(20, 30, 60);
 
void setup() {
Line 1,135 ⟶ 1,487:
s.y += sin(radians(s.z)) * l);
return s;
}</langsyntaxhighlight>'''The sketch can be run online''' :<BR> [https://www.openprocessing.org/sketch/954181 here.]
 
==={{header|Processing Python mode}}===
<langsyntaxhighlight lang="python">
 
t = { 'x': 20, 'y': 30, 'a': 60 }
Line 1,162 ⟶ 1,514:
 
return s
</syntaxhighlight>
</lang>
 
'''The sketch can be run online''' :<BR> [https://Trinket.io/processing/de6eddb155 here.]
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">
import matplotlib.pyplot as plt
import math
Line 1,219 ⟶ 1,571:
 
draw_lsystem(s_axiom, s_rules, s_angle, 7)
</syntaxhighlight>
</lang>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
{{Trans|C}}
<langsyntaxhighlight lang="prolog">main:-
write_sierpinski_arrowhead('sierpinski_arrowhead.svg', 600, 8).
 
Line 1,265 ⟶ 1,617:
curve(Stream, Order1, Length2, Cursor3, Cursor4, Angle),
turn(Cursor4, Angle, Cursor5),
curve(Stream, Order1, Length2, Cursor5, Cursor1, Angle1).</langsyntaxhighlight>
 
{{out}}
[[Media:Sierpinski_arrowhead_prolog.svg]]
See: [https://slack-files.com/T0CNUL56D-F01DPA9DNFP-53faf39637 sierpinski_arrowhead.svg] (offsite SVG image)
 
=={{header|Quackery}}==
Line 1,274 ⟶ 1,626:
Using an L-system.
 
<langsyntaxhighlight Quackerylang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
[ stack ] is switch.arg ( --> [ )
Line 1,302 ⟶ 1,654:
turtle
10 frames
witheach
[ switch
[ char L case [ -1 6 turn ]
char R case [ 1 6 turn ]
otherwise [ 4 1 walk ] ] ]</lang>
1 frames</syntaxhighlight>
 
{{output}}
 
[[File:Quackery Sierpinski arrowhead.png]]
https://imgur.com/Qaz37ds
 
=={{header|Raku}}==
Line 1,316 ⟶ 1,670:
{{works with|Rakudo|2020.02}}
 
<syntaxhighlight lang="raku" perl6line>use SVG;
 
role Lindenmayer {
Line 1,353 ⟶ 1,707:
:polyline[ :points(@points.join: ','), :fill<black>, :style<stroke:#FF4EA9> ],
],
);</langsyntaxhighlight>
See: [https://github.com/thundergnat/rc/blob/master/img/sierpinski-arrowhead-curve-perl6.svg Sierpinski-arrowhead-curve-perl6.svg] (offsite SVG image)
 
=={{header|REXX}}==
{{trans|Algol W}}
<langsyntaxhighlight lang="rexx">/*REXX pgm computes and displays a Sierpinski Arrowhead Curve using the characters: \_/ */
parse arg order . /*obtain optional argument from the CL.*/
if order=='' | order=="," then order= 5 /*Not specified? Then use the default.*/
Line 1,393 ⟶ 1,747:
end /*select*/ /*curve character is based on direction*/
Lx= min(Lx,x); Hx= max(Hx,x); Ly= min(Ly,y); Hy= max(Hy,y) /*min&max of x,y*/
return /*#: heading in degrees of the curve. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input value of: &nbsp; &nbsp; <tt> 5 </tt>}}
<b><pre>
Line 1,436 ⟶ 1,790:
{{libheader|JRubyArt}}
For grammar see Hilbert Curve
<langsyntaxhighlight lang="ruby">
load_libraries :grammar
attr_reader :points
Line 1,520 ⟶ 1,874:
end
 
</syntaxhighlight>
</lang>
 
=={{header|Rust}}==
Output is a file in SVG format. Another variation on the same theme as the C, Go and Phix solutions.
<langsyntaxhighlight lang="rust">// [dependencies]
// svg = "0.8.0"
 
Line 1,600 ⟶ 1,954:
fn main() {
write_sierpinski_arrowhead("sierpinski_arrowhead.svg", 600, 8).unwrap();
}</langsyntaxhighlight>
 
{{out}}
[[Media:Sierpinski_arrowhead_rust.svg]]
See: [https://slack-files.com/T0CNUL56D-F0173HHBYL9-af5ef387c5 sierpinski_arrowhead.svg] (offsite SVG image)
 
=={{header|Sidef}}==
Uses the '''LSystem()''' class from [https://rosettacode.org/wiki/Hilbert_curve#Sidef Hilbert curve].
<langsyntaxhighlight lang="ruby">var rules = Hash(
x => 'yF+xF+y',
y => 'xF-yF-x',
Line 1,625 ⟶ 1,979:
)
 
lsys.execute('xF', 7, "sierpiński_arrowhead.png", rules)</langsyntaxhighlight>
Output image: [https://github.com/trizen/rc/blob/master/img/sierpi%C5%84ski_arrowhead-sidef.png Sierpiński arrowhead]
 
Line 1,631 ⟶ 1,985:
{{trans|Go}}
{{libheader|DOME}}
<langsyntaxhighlight ecmascriptlang="wren">import "graphics" for Canvas, Color, Point
import "dome" for Window
 
Line 1,689 ⟶ 2,043:
}
}
}</langsyntaxhighlight>
 
{{out}}
[[File:Wren-Sierpinski_arrowhead_curve.png|400px]]
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">int PosX, PosY;
real Dir;
 
Line 1,720 ⟶ 2,077:
Curve(Order, Length, -Sixty);
];
]</langsyntaxhighlight>
 
{{out}}
Line 1,730 ⟶ 2,087:
Uses Image Magick and
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<langsyntaxhighlight lang="zkl">order:=7;
sierpinskiArrowheadCurve(order) : turtle(_,order);
 
Line 1,760 ⟶ 2,117:
}
img.writeJPGFile("sierpinskiArrowheadCurve.zkl.jpg");
}</langsyntaxhighlight>
{{out}}
Offsite image at [http://www.zenkinetic.com/Images/RosettaCode/sierpinskiArrowheadCurve.zkl.jpg Sierpinski arrowhead curve order 7]
3,043

edits