是什么让我的图片看起来只有预期的一半宽?

What makes my image look half as wide as intended?

我正在尝试使用初级学生语言中的放置图像将一个垂直放置的矩形和另一个对象放置在空场景中。但是,当我运行这个函数时,当矩形的宽度设置为等于场景的宽度时,矩形只在水平方向占据场景的一半。

我使用 Stepper 检查了我的代码发生了什么,并找到了图像宽度减半的位置,但我不知道为什么。可能与我不太熟悉的缺点有关。

完整代码如下:

(require 2htdp/image)

(define WIDTH 400)
(define HEIGHT 300)
(define HMAX 100)
(define SCENE (empty-scene WIDTH HEIGHT))

(define-struct vcham [x h c])
(define c (make-vcham 0 100 "white"))

(define (render ch)
  (place-images (list (rectangle (* 1 WIDTH (/ (vcham-h ch) HMAX)) 50 "solid" "maroon")
                      (rectangle 1 1 "solid" "blue"))
                (list (make-posn 0 0) (make-posn 20 20))
                SCENE))

(render c)

我已尽可能简化此代码,因此是 1×1 矩形。我也对实现此目的的优雅替代方案感兴趣,但最感兴趣的是找出发生这种情况的原因。

place-images 就像 place-image :

Places image onto scene with its center at the coordinates (x,y) and crops the resulting image so that it has the same size as scene. The coordinates are relative to the top-left of scene.

您可以将 (make-posn 0 0) 更改为 (make-posn 200 25),或者尝试 place-images/align

(define (render ch)
  (place-images/align (list (rectangle (* 1 WIDTH (/ (vcham-h ch) HMAX)) 50 "solid" "maroon")
                      (rectangle 1 1 "solid" "blue"))
                (list (make-posn 0 0) (make-posn 20 20))
                "left" "top" SCENE))