方案图形
Scheme graphics
我正在使用 mit-scheme 及其图形库。
你用 (define device (make-graphics-device (car (enumerate-graphics-types))))
制作了一个图形设备,它打开了一个 window 用于图形创建。(graphics-operation device 'set-foreground-color "black")
使线条变黑。函数 (graphics-operation device 'fill-polygon #(0 1 0 0 1 0 1 1))
生成一个黑色正方形,参数 #() 中的每两个数字是形状上的一个点。
如果我使用以下内容:
(define (print-cell dev x y)
(define off .01)
(define x+ (+ x off))
(define x- (- x off))
(define y+ (+ y off))
(define y- (- y off))
(graphics-operation dev 'fill-polygon #(x+ y+ x+ y- x- y+ x- y-)))
我收到错误 The object x+ passed to integer->flownum is not the correct type
我不明白这个,因为我可以在函数的 #() 部分使用 flonums 作为参数。
我要print-cell
取一组坐标,然后以点为中心画一个小方块,使(print-cell device .5 .5)
变成(graphics-operation device 'fill-polygon #(.51 .51 .51 .49 .49 .49 .49 .51))
#()
符号显示为 vector constants:您正在阅读文字符号,这解释了为什么传递给 integer->flownum
的对象是 x+
而不是绑定到 x+
。您应该将 #(x+)
视为等同于 '(x+)
,但对于矢量。
vector
函数可以实现您想做的事情:
(vector x+ y+ x+ y- y+ x- y-)
我正在使用 mit-scheme 及其图形库。
你用 (define device (make-graphics-device (car (enumerate-graphics-types))))
制作了一个图形设备,它打开了一个 window 用于图形创建。(graphics-operation device 'set-foreground-color "black")
使线条变黑。函数 (graphics-operation device 'fill-polygon #(0 1 0 0 1 0 1 1))
生成一个黑色正方形,参数 #() 中的每两个数字是形状上的一个点。
如果我使用以下内容:
(define (print-cell dev x y)
(define off .01)
(define x+ (+ x off))
(define x- (- x off))
(define y+ (+ y off))
(define y- (- y off))
(graphics-operation dev 'fill-polygon #(x+ y+ x+ y- x- y+ x- y-)))
我收到错误 The object x+ passed to integer->flownum is not the correct type
我不明白这个,因为我可以在函数的 #() 部分使用 flonums 作为参数。
我要print-cell
取一组坐标,然后以点为中心画一个小方块,使(print-cell device .5 .5)
变成(graphics-operation device 'fill-polygon #(.51 .51 .51 .49 .49 .49 .49 .51))
#()
符号显示为 vector constants:您正在阅读文字符号,这解释了为什么传递给 integer->flownum
的对象是 x+
而不是绑定到 x+
。您应该将 #(x+)
视为等同于 '(x+)
,但对于矢量。
vector
函数可以实现您想做的事情:
(vector x+ y+ x+ y- y+ x- y-)