我正在爲MIT-Scheme編寫一個小型繪圖工具。 來源:[plotlib]。複合對象不適用
頂層是(make-plot output mode args)
函數,該函數接受輸出設備對象,繪圖模式以及包含模式中指定繪圖類型參數的列表。 我將使用函數(range start stop increment)
來爲每個增量生成從包含開始到獨佔停止的列表。 (range -1 1 .1)
創建清單(-1 -.9 -.8 ... .9)
。
make-plot
適用於它的其他模式,但與'vector-field-plot
模式make-plot
(define window (make-graphics-device 'win32))
(define (vector-field-plot device color xrange yrange func)
(let* ((cords (append-all (map (lambda (i)
(map (lambda (j)
(cond ((eq? j '()) '())
(else (cons i j))))
xrange))
yrange)))
(input (map (lambda (point)
(list (car point) (cdr point)
(car (func (car point) (cdr point)))
(cdr (func (car point) (cdr point)))))
cords)))
(draw-vector-list device color input)))
;This is the part of make-plot that is called for
;(make-plot window 'vector-field-plot '(args))
((eq? mode 'vector-field-plot)
;does not work yet
(let* ((bg-color (car args))
(grid-color (cadr args))
(line-color (caddr args))
(xrange (car (cadddr args)))
(yrange (cadr (cadddr args)))
(func (cddr (cadddr args))))
(clear output bg-color);sets background to white
(coord-grid-cart output grid-color);prints Cartesian coordinate grid
(vector-field-plot output line-color xrange yrange func)))))
;calls vector-field-plot with parameters given to make-plot
;I have left out some function definitions here, they are in the source file
;but you can assume all of those work correctly for this section
一個打印矢量場被稱爲是不行的,它調用函數(vector-field-plot output line-color xrange yrange func)
有了這樣'(-1 -.9 ... 1)
和數字組成的xrange和yrange是名單一個形式爲(lambda (x y) (cons x y))
的函數。如果我使用:
(make-plot window 'vector-field-plot (list "white" "black" "red"
(list (range -1 1 .1) (range -1 1 .1)
(lambda (x y) (cons (* -.1 y) (* -.1 x))))))
它返回The object (#[compound procedure ]) is not applicable.
但是,如果使用:
(vector-field-plot window "red" (range -1 1 .1) (range -1 1 .1)
(lambda (x y) (cons (* -.1 y) (* .1 x))))
@jordan考慮使用'third'(或'fourth')而不是'cadddr'。 – soegaard
即時將要重寫這個使用'list-ref'。我實際上有一些想法可以將它縮小約50%SLOC。 – Anandamide
它將使輸入變得更簡單,因爲您可以使用平坦的參數列表調用make plot,而不是包含另一個列表的列表。或者我將使用可選參數。這是一個快速實現,以查看mit/gnu-scheme實現中圖形操作的功能。 – Anandamide