I don't think such a procedure can be written. at least not for the general 
case.

First, the color of `(filled-rectangle 30 30)` is not black, but whatever 
color was installed in the drawing context when the filled rectangle was 
rendered.  You can change it to red using:

(colorize (filled-rectangle 20 20) "red")

Even if you could inspect the colorize pict, it would still not be 
sufficient for a general `get-color` function.  Users can write their own 
pict constructors using dc:


(define colors (list "red" "green" "blue" "yellow"))

(define (my-red-colorize other-pict)
  (dc (lambda (dc dx dy)

        (define color (list-ref colors (random (length colors))))
        
        (define old-pen (send dc get-pen))
        (send dc set-pen (new pen% [width 1] [color color]))
        
        (draw-pict other-pict dc dx dy)
        
        (send dc set-pen old-pen))
      (pict-width other-pict)
      (pict-height other-pict)))

And a call like `(my-red-colorize (filled-rectangle 20 20))` will only 
result in a red rectangle about 25% of the time.

Even if you want to ignore cases like the above, what should `get-color` 
return for the picture below?

(hc-append (colorize (filled-rectangle 20 20) "red") (colorize 
(filled-rectangle 
20 20) "blue"))


Alex.


On Saturday, April 18, 2020 at 8:00:12 PM UTC+8, Raoul Schorer wrote:
>
> Hi,
>
> Using the 'pict' library, I could not find predicates regarding color in 
> the doc.
> Is there something like
>
> (get-color (filled-rectangle 30 30)) --> "black"
>
> somewhere?
> If not, how can I make a reliable color predicate?
>
> Thanks,
> Raoul
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/d3fa9021-63af-4129-bfb6-a82e219cfcf0%40googlegroups.com.

Reply via email to