summaryrefslogtreecommitdiff
path: root/graphics/asymptote/examples/Sierpinski.asy
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/asymptote/examples/Sierpinski.asy
Initial commit
Diffstat (limited to 'graphics/asymptote/examples/Sierpinski.asy')
-rw-r--r--graphics/asymptote/examples/Sierpinski.asy17
1 files changed, 17 insertions, 0 deletions
diff --git a/graphics/asymptote/examples/Sierpinski.asy b/graphics/asymptote/examples/Sierpinski.asy
new file mode 100644
index 0000000000..c0ff04971d
--- /dev/null
+++ b/graphics/asymptote/examples/Sierpinski.asy
@@ -0,0 +1,17 @@
+size(10cm);
+
+// Draw Sierpinski triangle with top vertex A, side s, and depth q.
+void Sierpinski(pair A, real s, int q, bool top=true)
+{
+ pair B=A-(1,sqrt(2))*s/2;
+ pair C=B+s;
+ if(top) fill(A--B--C--cycle);
+ unfill((A+B)/2--(B+C)/2--(A+C)/2--cycle);
+ if(q > 0) {
+ Sierpinski(A,s/2,q-1,false);
+ Sierpinski((A+B)/2,s/2,q-1,false);
+ Sierpinski((A+C)/2,s/2,q-1,false);
+ }
+}
+
+Sierpinski((0,1),1,9);