summaryrefslogtreecommitdiff
path: root/ipl/gprocs/lindterp.icn
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2013-01-27 23:51:56 +0000
committerIgor Pashev <pashev.igor@gmail.com>2013-01-27 23:51:56 +0000
commit6ab0c0f5bf14ed9c15370407b9ee7e0b4b089ae1 (patch)
tree926065cf45450116098db664e3c61dced9e1f21a /ipl/gprocs/lindterp.icn
downloadicon-6ab0c0f5bf14ed9c15370407b9ee7e0b4b089ae1.tar.gz
Initial upstream version 9.4.3upstream/9.4.3
Diffstat (limited to 'ipl/gprocs/lindterp.icn')
-rw-r--r--ipl/gprocs/lindterp.icn73
1 files changed, 73 insertions, 0 deletions
diff --git a/ipl/gprocs/lindterp.icn b/ipl/gprocs/lindterp.icn
new file mode 100644
index 0000000..2f01f1a
--- /dev/null
+++ b/ipl/gprocs/lindterp.icn
@@ -0,0 +1,73 @@
+############################################################################
+#
+# File: lindterp.icn
+#
+# Subject: Procedure to interpret and draw L-System strings
+#
+# Author: Ralph E. Griswold
+#
+# Date: May 2, 2001
+#
+############################################################################
+#
+# This file is in the public domain.
+#
+############################################################################
+#
+# This procedure interpreters strings of characters produced by
+# L-Systems and draws them using turtle graphics.
+#
+############################################################################
+#
+# Links: lindrec, lindgen, turtle
+#
+############################################################################
+
+link lindrec
+link lindgen
+link turtle
+
+global size
+
+# length is the length of line segments and delta is the amount of
+# direction change.
+
+procedure lindterp(x, y, lsys, gener, length, color, fnc)
+ local rewrite, delta, axiom, symbols, c
+
+ /size := 500
+ /x := size / 2
+ /y := size / 2
+ rewrite := lsys.rewrite
+ axiom := lsys.axiom
+ delta := lsys.delta
+ /gener := lsys.gener
+ /length := lsys.length
+
+# The table symbols contains definitions for other symbols as
+# string of other characters. It remains to be seen how this
+# will be represented. Note also there is a potential for
+# circularity and unbounded recursion.
+
+ symbols := table() # table of defined symbols
+
+ TReset()
+ TGoto(x, y)
+
+ every c := lindgen(!axiom, rewrite, gener) do
+ case c of {
+ "F": TDraw(length) # draw forward
+ "f": TSkip(length) # skip forward
+ "+": TRight(delta) # turn right
+ "-": TLeft(delta) # turn left
+ "[": TSave() # save state
+ "]": TRestore() # restore state
+ # interpret defined symbol
+ default: lindterp(\symbols[c], length, delta)
+ } # ignore other characters
+
+ WFlush()
+
+ return
+
+end