Discuss Scratch

octopus1234
Scratcher
60 posts

Pen RGB

I'm sorry if you've heard this before, but I think adding a Pen RGB block would be nice. Using a complicated math problem to find the pen color is kind of random. It would make it much easier (and cleaner) to have an RGB block, and it wouldn't take away the programming. It would make it easier to do more complicated things without using seemingly random math. Again, I'm sorry if you've seen this before.
ACE009
Scratcher
100+ posts

Pen RGB

The math isn’t random, since colors are stored as 1 byte for red, green, and blue, totaling in 3 bytes per pixel. Since a byte is 8 bits and each bit has 2 possible values, you can calculate 2^8 to find that each byte can store one of 256 different values. The pen blocks will take a number input of the color code, so you can input RGB with the below: (I might have flipped the red and blue inputs.)
setpencolortoblue+green*256+red*256*256
octopus1234
Scratcher
60 posts

Pen RGB

So, is it basically hex codes in regular decimal?
ACE009
Scratcher
100+ posts

Pen RGB

Yes. If you want, you can also prefix the raw hex number with 0x (either with a variable or the join block) and Scratch will do the conversion to decimal for you.
setpencolortojoin0x00ff33 is the same assetpencolorto0*65536+255*255+51 is the same assetpencolorto

Last edited by ACE009 (May 24, 2018 21:20:39)

Zekrom01
Scratcher
1000+ posts

Pen RGB

Support, the workaround is quite tedious and RGB is a crucial part of programming in the real world.
-ShadowOfTheFuture-
Scratcher
1000+ posts

Pen RGB

It's already possible to set pen color using RGB. (It's a somewhat hidden feature though)

Last edited by -ShadowOfTheFuture- (May 24, 2018 20:04:47)

duckboycool
Scratcher
1000+ posts

Pen RGB

If you want a suggestion to not have to use the workaround, this would be a duplicate.
Paddle2See
Scratch Team
1000+ posts

Pen RGB

duckboycool wrote:

If you want a suggestion to not have to use the workaround, this would be a duplicate.
Thanks for the link! It does look like this is a duplicate topic so I'll close it to keep the conversation all in one place.

Please use the existing topic in the link above.

Powered by DjangoBB