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?
it doesn't work for me :
oh, you need to pass in the whole pixels list, it's a list of pixels, a table.
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
Oh ! Yes, it works ! Thank you.
Could you give your
block please ?
It would be great...
Great, I'm so glad we found that out!
is _ transparent? predicate, it's really trivial:
I have a problem. This script gives me a very very long time to finish. To create the
average block I use the
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 :
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
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.