Discuss Scratch
- szogye
-
Scratcher
83 posts
Color Detector
So I was wondering if it was possible to make a sprite that detects the RGB color values of the color it is touching. I really hope this is possible because I am trying to make face recognition in Scratch. Thank you!
- cs4715962
-
Scratcher
100+ posts
Color Detector
Would this work?:
Sorry I'm not the best at code
when green flag clicked
<color [#583a3e] is touching [#f91bf4] ?>
Sorry I'm not the best at code

- szogye
-
Scratcher
83 posts
Color Detector
Would this work?:Thank you for trying, but I needed something that detects the RGB of the color it is touching. Thanks for trying though!when green flag clicked<color [#583a3e] is touching [#f91bf4] ?>
Sorry I'm not the best at code
- szogye
-
Scratcher
83 posts
Color Detector
https://scratch.mit.edu/search/projects?q=rgb+detectorHmm… Thanks for the help but these RGB color detectors aren't 100% accurate. I'm trying to make face recognition so it needs to be 100% percent accurate. Thank you for the link though!.
- oppooo
-
Scratcher
63 posts
Color Detector
I need basically the same thing… try looping through combinations of HEX codes maybe?
- Oumuamua
-
Scratcher
1000+ posts
Color Detector
I need basically the same thing… try looping through combinations of HEX codes maybe?
What colors has a face?
- szogye
-
Scratcher
83 posts
Color Detector
I need basically the same thing… try looping through combinations of HEX codes maybe?I was actually thinking the same thing, but I don't know how to create/find a list of hex codes. I've looked it up before but I couldn't find anything.
- Oumuamua
-
Scratcher
1000+ posts
Color Detector
Try this https://scratch.mit.edu/projects/106633672/ by @ScratchMan544
- szogye
-
Scratcher
83 posts
Color Detector
Try this https://scratch.mit.edu/projects/106633672/ by @ScratchMan544Thank you! I'll use this once I find a way to detect the RGB color values of the color a sprite is touching.
- Vadik1
-
Scratcher
500+ posts
Color Detector
First of all, you don't need it to be in hexadecimal. If you convert those hex codes to decimal and give that to scratch instead, it is going to work as well. So there is no point in dealing in hex at all if all calculations can be done in decimal.I need basically the same thing… try looping through combinations of HEX codes maybe?I was actually thinking the same thing, but I don't know how to create/find a list of hex codes. I've looked it up before but I couldn't find anything.
Secondly, scratch supports 16 million colors. (8 bits for red, 8 bits for green, 8 bits for blue). Looping through that many colors would be too slow, but fortunately there is a way to not do it.
Blocks:
<touching color [#70020c] ?>can only distinguish 256 colors. All unsupported colors get rounded(actually floored) to the nearest suppored one. The way rounding works is that it only takes 3 most significant bits from red, 3 most significant bits from green and 2 most significant bits from blue.
<color [#31f99c] is touching [#1e6c24] ?>
2³ × 2³ × 2² = 256
To loop through them you can use this script:
set [red v] to [0]
repeat (8)
set [green v] to [0]
repeat (8)
set [blue v] to [0]
repeat (4)
set [color v] to ((((red) * (65536)) + ((green) * (256))) + (blue))
if <touching color (color) ?> then
end
change [blue v] by (64)
end
change [green v] by (32)
end
change [red v] by (32)
end
- oppooo
-
Scratcher
63 posts
Color Detector
Well, basically you have 8 variables and you try each combination, you need to try all combos from 0-9 and A-F as inputs for the variables.I need basically the same thing… try looping through combinations of HEX codes maybe?I was actually thinking the same thing, but I don't know how to create/find a list of hex codes. I've looked it up before but I couldn't find anything.
when flag clicked
add to list and make sure it has run without screen refresh
sense color and make sure this has run without screen refresh enabled
define sense color and make sure this has run without screen refresh enabled
forever
repeat (8)
set [V8 v] to (item((item # of (V8) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V7 v] to (item((item # of (V7) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V6 v] to (item((item # of (V6) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V5 v] to (item((item # of (V5) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V4 v] to (item((item # of (V4) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V3 v] to (item((item # of (V3) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V2 v] to (item((item # of (V2) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V1 v] to (item((item # of (V1) in [possible values v])+(1)) of [possible values v])
if <touching color (join(V1)(join(V2)(join(join(V3)(V4))(join(V5)(join(V6)(join(V7)(V8)))))))> then
convert (join(V1)(join(V2)(join(join(V3)(V4))(join(V5)(join(V6)(join(V7)(V8))))))) to RGBA
end
end
end
end
end
end
end
end
end
end
define add to list and make sure it has run without screen refresh
set [counter v] to (0)
delete all of [possible values v]
repeat (16)
change [counter v] by (1)
add (letter (counter) of [1234567890ABCDEF]) to [possible values v]
end
Try something like this. I haven't tried it so you might have to change some stuff, and you have to get the HEX converter.
- szogye
-
Scratcher
83 posts
Color Detector
First of all, you don't need it to be in hexadecimal. If you convert those hex codes to decimal and give that to scratch instead, it is going to work as well. So there is no point in dealing in hex at all if all calculations can be done in decimal.I need basically the same thing… try looping through combinations of HEX codes maybe?I was actually thinking the same thing, but I don't know how to create/find a list of hex codes. I've looked it up before but I couldn't find anything.
Secondly, scratch supports 16 million colors. (8 bits for red, 8 bits for green, 8 bits for blue). Looping through that many colors would be too slow, but fortunately there is a way to not do it.
Blocks:<touching color [#70020c] ?>can only distinguish 256 colors. All unsupported colors get rounded(actually floored) to the nearest suppored one. The way rounding works is that it only takes 3 most significant bits from red, 3 most significant bits from green and 2 most significant bits from blue.
<color [#31f99c] is touching [#1e6c24] ?>
2³ × 2³ × 2² = 256
To loop through them you can use this script:set [red v] to [0]
repeat (8)
set [green v] to [0]
repeat (8)
set [blue v] to [0]
repeat (4)
set [color v] to ((((red) * (65536)) + ((green) * (256))) + (blue))
if <touching color (color) ?> then
end
change [blue v] by (64)
end
change [green v] by (32)
end
change [red v] by (32)
end
Thank you so much! I'm trying them right now…Well, basically you have 8 variables and you try each combination, you need to try all combos from 0-9 and A-F as inputs for the variables.I need basically the same thing… try looping through combinations of HEX codes maybe?I was actually thinking the same thing, but I don't know how to create/find a list of hex codes. I've looked it up before but I couldn't find anything.when flag clicked
add to list and make sure it has run without screen refresh
sense color and make sure this has run without screen refresh enabled
define sense color and make sure this has run without screen refresh enabled
forever
repeat (8)
set [V8 v] to (item((item # of (V8) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V7 v] to (item((item # of (V7) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V6 v] to (item((item # of (V6) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V5 v] to (item((item # of (V5) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V4 v] to (item((item # of (V4) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V3 v] to (item((item # of (V3) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V2 v] to (item((item # of (V2) in [possible values v])+(1)) of [possible values v])
repeat (8)
set [V1 v] to (item((item # of (V1) in [possible values v])+(1)) of [possible values v])
if <touching color (join(V1)(join(V2)(join(join(V3)(V4))(join(V5)(join(V6)(join(V7)(V8)))))))> then
convert (join(V1)(join(V2)(join(join(V3)(V4))(join(V5)(join(V6)(join(V7)(V8))))))) to RGBA
end
end
end
end
end
end
end
end
end
end
define add to list and make sure it has run without screen refresh
set [counter v] to (0)
delete all of [possible values v]
repeat (16)
change [counter v] by (1)
add (letter (counter) of [1234567890ABCDEF]) to [possible values v]
end
Try something like this. I haven't tried it so you might have to change some stuff, and you have to get the HEX converter.
- oppooo
-
Scratcher
63 posts
Color Detector
Oh I didn't know that, I will try it. But are you sure it supports transparency too?First of all, you don't need it to be in hexadecimal. If you convert those hex codes to decimal and give that to scratch instead, it is going to work as well. So there is no point in dealing in hex at all if all calculations can be done in decimal.I need basically the same thing… try looping through combinations of HEX codes maybe?I was actually thinking the same thing, but I don't know how to create/find a list of hex codes. I've looked it up before but I couldn't find anything.
Secondly, scratch supports 16 million colors. (8 bits for red, 8 bits for green, 8 bits for blue). Looping through that many colors would be too slow, but fortunately there is a way to not do it.
Blocks:<touching color [#70020c] ?>can only distinguish 256 colors. All unsupported colors get rounded(actually floored) to the nearest suppored one. The way rounding works is that it only takes 3 most significant bits from red, 3 most significant bits from green and 2 most significant bits from blue.
<color [#31f99c] is touching [#1e6c24] ?>
2³ × 2³ × 2² = 256
To loop through them you can use this script:set [red v] to [0]
repeat (8)
set [green v] to [0]
repeat (8)
set [blue v] to [0]
repeat (4)
set [color v] to ((((red) * (65536)) + ((green) * (256))) + (blue))
if <touching color (color) ?> then
end
change [blue v] by (64)
end
change [green v] by (32)
end
change [red v] by (32)
end
- Vadik1
-
Scratcher
500+ posts
Color Detector
After looking through the source code once again I've realised I was wrong.
Those blocks can distinguish 32768 colors.
Rounding takes 5 most significant bits from red, 5 most significant bits from green and 4 most significant bits from blue.
The correct script is:
This in Forkphorus source code
Those blocks can distinguish 32768 colors.
Rounding takes 5 most significant bits from red, 5 most significant bits from green and 4 most significant bits from blue.
The correct script is:
set [red v] to [0]This in Scratch source code
repeat (32)
set [green v] to [0]
repeat (32)
set [blue v] to [0]
repeat (16)
set [color v] to ((((red) * (65536)) + ((green) * (256))) + (blue))
if <touching color (color) ?> then
end
change [blue v] by (16)
end
change [green v] by (8)
end
change [red v] by (8)
end
This in Forkphorus source code
Last edited by Vadik1 (Feb. 26, 2021 05:34:59)
- oppooo
-
Scratcher
63 posts
Color Detector
After looking through the source code once again I've realised I was wrong.
Those blocks can distinguish 32768 colors.
Rounding takes 5 most significant bits from red, 5 most significant bits from green and 4 most significant bits from blue.
The correct script is:set [red v] to [0]This in Scratch source code
repeat (32)
set [green v] to [0]
repeat (32)
set [blue v] to [0]
repeat (16)
set [color v] to ((((red) * (65536)) + ((green) * (256))) + (blue))
if <touching color (color) ?> then
end
change [blue v] by (16)
end
change [green v] by (8)
end
change [red v] by (8)
end
This in Forkphorus source code
Ok, but it doesn't have transparency. How do I put that in?
- Oumuamua
-
Scratcher
1000+ posts
Color Detector
Who are you? Are you the Original Poster?
-snip-
Ok, but it doesn't have transparency. How do I put that in?
- oppooo
-
Scratcher
63 posts
Color Detector
Who are you? Are you the Original Poster?-snip-
Ok, but it doesn't have transparency. How do I put that in?
No, but I am looking for the exact same thing.
Last edited by oppooo (Feb. 26, 2021 19:41:26)





