summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/asymptote/examples/dragon.asy
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-07 18:26:53 +0000
committerKarl Berry <karl@freefriends.org>2013-04-07 18:26:53 +0000
commitb04c2e1a42573e9735547702356c7b9a769a6855 (patch)
treec0753443f39500a062d7698fe6b94359c813f871 /Master/texmf-dist/doc/asymptote/examples/dragon.asy
parentfb0bf13304a356f197bfc1add17f98c07e96f17b (diff)
texmf -> texmf-dist: doc
git-svn-id: svn://tug.org/texlive/trunk@29714 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/asymptote/examples/dragon.asy')
-rw-r--r--Master/texmf-dist/doc/asymptote/examples/dragon.asy66
1 files changed, 66 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/asymptote/examples/dragon.asy b/Master/texmf-dist/doc/asymptote/examples/dragon.asy
new file mode 100644
index 00000000000..08fcb61f5c0
--- /dev/null
+++ b/Master/texmf-dist/doc/asymptote/examples/dragon.asy
@@ -0,0 +1,66 @@
+pair crease(pair z1, pair z2, bool left)
+{
+ pair dz = z2 - z1;
+
+ if (left)
+ return z1 + dz * (0.5, 0.5);
+ else
+ return z1 + dz * (0.5, -0.5);
+}
+
+pair[] fold(pair[] oldz)
+{
+ int n = oldz.length;
+ pair[] newz = new pair[2n-1];
+
+ for (int i = 0; i < n-1; ++i)
+ {
+ newz[2i] = oldz[i];
+ newz[2i+1] = crease(oldz[i], oldz[i+1], i%2==0);
+ }
+
+ newz[2(n-1)] = oldz[n-1];
+
+ return newz;
+}
+
+pair[] dragon(int n, pair[] base={})
+{
+ if (base.length == 0)
+ if (n%2 == 0)
+ base = new pair[] {(0,0), (1,1) };
+ else
+ base = new pair[] {(0,0), (1,0) };
+
+ pair[] z = base;
+
+ for (int i = 1; i < n; ++i)
+ z = fold(z);
+
+ return z;
+}
+
+void drawtris(pair[] z, pen p = currentpen)
+{
+ int n = z.length;
+
+ for (int i = 0; i < n-2; i+=2)
+ fill(z[i]--z[i+1]--z[i+2]--cycle, p);
+}
+
+void drawtris(pair[] z, pen p1, pen p2)
+{
+ int n = z.length;
+
+ for (int i = 0; i < n-2; i+=2)
+ fill(z[i]--z[i+1]--z[i+2]--cycle, 2i < n-1 ? p1 : p2);
+}
+
+size(500,0);
+
+int n = 10;
+
+drawtris(dragon(n, new pair[] {(0,0), (1,0)}), black);
+drawtris(dragon(n, new pair[] {(0,0), (0,-1)}), blue);
+drawtris(dragon(n, new pair[] {(0,0), (-1,0)}), red);
+drawtris(dragon(n, new pair[] {(0,0), (0,1)}), green);