Discuss Scratch
- Discussion Forums
- » Suggestions
- » Detect Color by Number
- KPWOLF
-
3 posts
Detect Color by Number
Hello everyone.
I think it would be very useful to have a separate sensor block to detect color by an inputted number instead of just selecting a color with the eye dropper. I'm not saying the eye dropper should be removed, i just want another block to detect color by number. Here is an example of how it could be helpful: A while ago I thought it would be cool to make a program that would condense a stage into pen code so that it could be printed out again in pen. What I found was that this would be way too difficult for me because I did not want to brute force 9000+ color combinations. I gave up on the project. In situations similar to this one and even others, it could be very helpful to have RGB or some other number combination to detect colors instead of having to use the eyedropper every time.
- KPWOLF
I think it would be very useful to have a separate sensor block to detect color by an inputted number instead of just selecting a color with the eye dropper. I'm not saying the eye dropper should be removed, i just want another block to detect color by number. Here is an example of how it could be helpful: A while ago I thought it would be cool to make a program that would condense a stage into pen code so that it could be printed out again in pen. What I found was that this would be way too difficult for me because I did not want to brute force 9000+ color combinations. I gave up on the project. In situations similar to this one and even others, it could be very helpful to have RGB or some other number combination to detect colors instead of having to use the eyedropper every time.
- KPWOLF
- TheLogFather
-
1000+ posts
Detect Color by Number
You can drop an expression into the colour-square, and it treats it as a 24 bit RGB value:
Note that Scratch only matches the first five bits of red & green components, and first four bits of blue.
That means 0xFFFFFF (i.e. white) will match 0xF8F8F0 (off-white), for example.
(Consequently, there are only up to 32*32*16 checks needed to find a match for a given pixel, rather than the full 256*256*256.)
Similar thing for the “set pen color” block, BTW (the one with the colour square, not the one with slot for typing a number – and it's clearly not ‘matching’ a colour here, so all bits make a difference):
..except, it can also take a 32 bit ARGB value – i.e. with alpha in the highest order byte:
Note that Scratch only matches the first five bits of red & green components, and first four bits of blue.
That means 0xFFFFFF (i.e. white) will match 0xF8F8F0 (off-white), for example.
(Consequently, there are only up to 32*32*16 checks needed to find a match for a given pixel, rather than the full 256*256*256.)
Similar thing for the “set pen color” block, BTW (the one with the colour square, not the one with slot for typing a number – and it's clearly not ‘matching’ a colour here, so all bits make a difference):
..except, it can also take a 32 bit ARGB value – i.e. with alpha in the highest order byte:
Last edited by TheLogFather (April 19, 2017 16:49:15)
- NitroCipher
-
500+ posts
Detect Color by Number
Semi offtopic but if you have the time, would you be able to place this information on the scratch wiki? You can drop an expression into the colour-square, and it treats it as a 24 bit RGB value:
Note that Scratch only matches the first five bits of red & green components, and first four bits of blue.
That means 0xFFFFFF (i.e. white) will match 0xF8F8F0 (off-white), for example.
(Consequently, there are only up to 32*32*16 checks needed to find a match for a given pixel, rather than the full 256*256*256.)
Similar thing for the “set pen color” block, BTW (the one with the colour square, not the one with slot for typing a number – and it's clearly not ‘matching’ a colour here, so all bits make a difference):
..except, it can also take a 32 bit ARGB value – i.e. with alpha in the highest order byte:
- jromagnoli
-
1000+ posts
Detect Color by Number
You can use this: Hello everyone.
I think it would be very useful to have a separate sensor block to detect color by an inputted number instead of just selecting a color with the eye dropper. I'm not saying the eye dropper should be removed, i just want another block to detect color by number. Here is an example of how it could be helpful: A while ago I thought it would be cool to make a program that would condense a stage into pen code so that it could be printed out again in pen. What I found was that this would be way too difficult for me because I did not want to brute force 9000+ color combinations. I gave up on the project. In situations similar to this one and even others, it could be very helpful to have RGB or some other number combination to detect colors instead of having to use the eyedropper every time.
- KPWOLF
- L115a3uk
-
5 posts
Detect Color by Number
Could you create a piece of code that detects a certain range of colors? that way you would only need to search 256 or whatever rather than tens of thousands?
- qaz1550
-
100+ posts
Detect Color by Number
would this work for touching if a colour is touching the same colour in a custom block? You can drop an expression into the colour-square, and it treats it as a 24 bit RGB value:
Note that Scratch only matches the first five bits of red & green components, and first four bits of blue.
That means 0xFFFFFF (i.e. white) will match 0xF8F8F0 (off-white), for example.
(Consequently, there are only up to 32*32*16 checks needed to find a match for a given pixel, rather than the full 256*256*256.)
Similar thing for the “set pen color” block, BTW (the one with the colour square, not the one with slot for typing a number – and it's clearly not ‘matching’ a colour here, so all bits make a difference):
earlier on in the code:
later in the code:
- Discussion Forums
- » Suggestions
-
» Detect Color by Number