You could use pict/convert to make a wrapper that remembers the color: ``` #lang racket (require pict pict/convert) (struct pict+color (pict color) #:property prop:pict-convertible (lambda (x) (pict+color-pict x)))
(define (my-colorize p c) (pict+color (colorize p c) c)) (define (get-color p) (and (pict+color? p) (pict+color-color p))) ``` This would be a little unreliable, as only the direct result of `my-colorize` would have a retrievable color, but it might work for your purposes. --spencer On Sat, Apr 18, 2020 at 9:34 PM Robby Findler <[email protected]> wrote: > I basically agree with Alex, as the internal structures of pict don't > really keep information in that way, but a "best effort" might be to > draw it into a bitmap and then use the bitmap to find the average > color or the most common color (perhaps with some error bounds on what > colors count as "the same") or something like that. > > Robby > > On Sat, Apr 18, 2020 at 6:49 PM Alex Harsanyi <[email protected]> > wrote: > > > > > > 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 > . > > -- > 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/CAL3TdONPB16S1srT1%3Dz0ZPM52%3DZh624hrq5zOc7C4oerXqgaCA%40mail.gmail.com > . > -- 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/CAF4wvDzH-AK40WjJrnhFKDAiJaV5fQrCV0othqQj-R%3Di7S1PxQ%40mail.gmail.com.

