Discuss Scratch

inchy100
Scratcher
15 posts

Scratch Can't Tell the Difference Between Similar Colours!

Sometimes when I am making a project that uses the “touching colour” block, and I want a sprite to do different things when they touch those colours, the sprite will do the same thing when it is touching either colour, rather than doing different things. For example, just a few minutes ago I was working on a game of pong for my new OS, and I had the edges of the screen painted in a light shade of gray, and the top painted in a slightly darker, but different. I told it to reverse the y velocity when it touched the darker shade of gray (the top), and reverse the x velocity when it touched the lighter shade of gray (the sides). Rather, it reversed the x velocity no matter which colour it was touching. When I changed the top to a much darker shade of gray, then it worked perfectly with no other changes. This is not the first time; I had the same problem with similar shades of green on a different project.
THIS IS STARTING TO GET ANNOYING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Check out my Connect 4 game!
when green flag clicked
forever
program
end
turkey3
Scratcher
1000+ posts

Scratch Can't Tell the Difference Between Similar Colours!

Are you using vector graphics? If so it might be because the anti-aliasing (gradual transparency into the behind layer at the edges of lines and objects)

DadOfMrLog
Scratcher
1000+ posts

Scratch Can't Tell the Difference Between Similar Colours!

The colour matching is not exact - it allows some leeway…

A colour has three components - red, green, blue. Each component can take any value from zero to 255, an eight-bit value. That gives the total number of different colours as 256*256*256 (over 16 million).

However, when checking if touching colour, Scratch reports a match if the first five bits of the red & green components, and the first four bits of the blue component, all match the corresponding bits of the colour you've asked for.

This means, for example, that “if touching white” (which is 255,255,255 for RGB components) will match for anything that has red component from 248 to 255, green component 248 to 255, blue component 240 to 255.

Similarly, “if touching black” (which is 0,0,0) will match for anything that has red component from 0 to 7, green component from 0 to 7, and blue component from 0 to 15.

Take a look at the following RGB colour detector project:
http://scratch.mit.edu/projects/10941245/

In practice that means you have to make sure your colours are sufficiently different if you want to test using “if touching colour”.

Hope that make sense!

(But don't ask me *why* it's been designed like that - I'd guess it's to make it easier for new scratchers so you don't need *exactly* the same colour when drawing different things and putting colours into the colour match blocks…? )

Last edited by DadOfMrLog (Aug. 14, 2013 16:58:16)



Alternate account: TheLogFather –– HowTos and useful custom blocks (see studio). Examples below…


- String manipulation - - - X to power of Y - - - Clone point to clone - Detect New Scratcher - Speed tests studio -

Powered by DjangoBB