How can I simply set the color (HSV or RGB) of a pixel in a costume?

I take back a recent post
https://forum.snap.berkeley.edu/t/changing-the-color-of-a-svg-sprite-using-the-looks-blocks/9315/8 where you said, @bh :

For each pixel in the costume, the effects say how much to add to that pixel's H, S, or V.

But why can we simply set the color (HSV or RGB) of a pixel in a costume ? Anf if it is, how can I do that ? Thank you !

Hi, Nathalie. When you get the pixels of a costume you can simply replace one pixel (whose value is an rgba list) with another one (rgba), you can even directly replace those individual numbers in the pixels list. But that list is a copy of what's inside the costume, therefore changing it does not directly affect the costume (costumes in Snap! are currently immutable). In order for any changes to take effect you can use the new costume reporter and pass the pixels list. Does that make sense to you, is that what you need?

Hi Jens,
it doesn't work for me :

oh, you need to pass in the whole pixels list, it's a list of pixels, a table.

It doesn't work too...

let me give you an example. This script determines the average color of (all opaque pixels in) a costume and "changes" the pixels to that color:

Is that any clearer?

Oh, now I see the problem: The alpha value is also on a scale of 0-255 in Snap! Your script should totally work if you increase it to 255 :slight_smile:

Oh ! Yes, it works ! Thank you.
Could you give your
untitled script pic(3) block please ?

It would be great...

I did this block...
untitled script pic(4)

Great, I'm so glad we found that out!
Here's the is _ transparent? predicate, it's really trivial:

is_transparent_pixel

Thanks Jens !

I have a problem. This script gives me a very very long time to finish. To create the average block I use the sum block.
untitled script pic(6)

My block is probably not correct...

well, it might not be the most efficient algorithm, I was doing this mostly for the example's sake. But the beauty of the "average" block is that it operates the same on numbers, lists, matrices, tensors ... thanks to hyperblocks:

Ok ! Thank you.
I'll definitely try to work with HSV color effects in the Looks category. It seems to be more efficient...

If you want hyper fast pixel-wise image manipulation, hyperblocks is really the way for you! Consider this little expression that substitutes all opaque pixels with the color pink:

It's so fast you can even animate it to make your own interactive graphic effect:

Thanks a lot @jens for this advise !
Look, I improved an old project to see the complementary color of a given color :
Jan-11-2022 11-52-34

https://snap.berkeley.edu/project?user=nathalierun&project=RGB.ColorFunction

Ooh, that's a really nice project, Nathalie!

Jens, in 2019, you edited a similar project of mine and it worked, but now it doesn't work anymore. Can you look into it, please?

Here's the link
https://snap.berkeley.edu/snap/snap.html#present:Username=kinestheticlearning&ProjectName=Media_Map_Transparency_edited_by_jens

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.