用于确定球拍中像素颜色的功能?

时间:2017-12-10 19:47:39

标签: colors racket

所以我试图找到或创建一个函数来确定某个点所在像素的颜色,任何关于它可能是什么/如何在Drracket中制作它的想法?我正在尝试制作它,以便找到点穿过的像素的颜色,然后如果颜色变为新的颜色。

3 个答案:

答案 0 :(得分:0)

bitmap-dcget-pixel方法。

答案 1 :(得分:0)

在大爆炸的鼠标中,您可以使用image-> color-list并使用list-ref来获取特定点。

(define img (circle 20 'solid 'red))
(define width (image-width img))
(define height (image-height img))
(define (color-indexes l)
(if (empty? l) empty (cons (take l width)
                           ;r-rest not a function but it drops width items 
                           ;from a list.You will have to make that
                           (color-indexes (r-rest l width)))))
 ;put this where you want the color
 (list-ref (list-ref (image->color-list) (sub1 x)))(sub1 y))

答案 2 :(得分:0)

如果您使用2htdp/image,则必须使用image->color-list。但是,该列表不会为您提供xy坐标的颜色。您需要通过考虑图像的宽度来计算列表中像素的位置。它返回的颜色列表跨越行,从顶部开始,从左上角到右上角,然后是下一行,从左到右,依此类推。

(x,y)列表中的(零索引)位置为x + width*y,或者:

(+ x (* width y))

在上下文中:

;; get-pixel : Image Number Number -> Color
(define (get-pixel img x y)
   (list-ref (image->color-list img)
             (+ x (* (image-width img) y))))
相关问题