参考Guile的Tutoria来创建一个带脚本支持的绘图程序:
http://www.gnu.org/software/guile/docs/guile-tut/tutorial.html
1.使用MacPorts安装guile和gnuplot
sudo port install guile gnuplot
2. 以管道的方式来操作gnuplot,注意需要在start_gnuplot函数添加如下的设置:
fprintf (output, "set term x11/n");
这是因为我们一会要使用X11来查看结果。
3. 检查一下Makefile
CDEBUG = -g -Wall
CFLAGS = $(CDEBUG) `guile-config compile`
LDFLAGS = `guile-config link`
SRCS = tortoise.c
OBJS = tortoise.o
tortoise: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
rm tortoise *.o
4.新建一个如下的脚本 snowflake.scm
(define (koch-line length depth)
(if (zero? depth)
(tortoise-move length)
(let ((sub-length (/ length 3))
(sub-depth (1- depth)))
(for-each (lambda (angle)
(koch-line sub-length sub-depth)
(tortoise-turn angle))
'(60 -120 60 0)))))
(define (snowflake length depth sign)
(let iterate ((i 1))
(if (<= i 3)
(begin
(koch-line length depth)
(tortoise-turn (* sign -120))
(iterate (1+ i))))))
(tortoise-pendown)
(snowflake 8 3 1)
(tortoise-turn 180)
(snowflake 8 3 -1)
5. 执行X11,并执行./tortoise -s snowflake.scm