Discuss Scratch

TannerCraft98
Scratcher
10 posts

How do I detect colors?

I want to move around an image and detect the color and add it to a list, here is what I did:
when green flag clicked
set [color v] to [0
go to x: (bottom left of the screen) y: (0)
forever
if <touching color [color] ?> then
move (1) steps
set [ colorv] to [0]
add [color] to [list v]
end
change [color v] by (1)
end

But it doesn't work.

If I change the variable in the detect object to the color of the image, it works,

but when I have it cycling through every

color until it reaches that one, it will just make color go up infinitely and not put anything in the list.

Please help, and explain it to me in simple terms.

Last edited by TannerCraft98 (Feb. 11, 2024 05:25:51)

SPS32
Scratcher
66 posts

How do I detect colors?

To detect colors in Scratch, you can use the “touching color” block or the “color sensing” block. Here's how you can do it:

1. Using the “touching color” block:
- This block checks if a sprite is touching a specific color.
- You can use it in conditional statements to trigger actions when the sprite touches a certain color.
- To use it, go to the Sensing category, drag the “touching color” block into your script, and choose the color you want to detect.

2. Using the “color sensing” block:
- This block reports the color sensed by the sprite at a specific position.
- You can use it to detect colors at different positions on the stage.
- To use it, go to the Sensing category, drag the “color sensing” block into your script, and specify the position where you want to detect the color.

Choose the method that best suits your project's needs.
TannerCraft98
Scratcher
10 posts

How do I detect colors?

SPS32 Thanks! But I want it to be able to cycle through every color until it reaches that one, is there any way to do that with a variable and not needing to have a pre-set color? The first option needs me to know what color it would detect. And the second sounds like it would work, but I can't find it. The only ones in the sensing I could find are “touching color” and “color touching color” but no “color sensing”. I see other projects doing it, but even when I replicate their code into mine, it still doesn't work (I tried to make my own code, didn't work, so I found a project that sensed color, but it also didn't work in my project).
malicondii
Scratcher
100+ posts

How do I detect colors?

here, this should help.
TannerCraft98
Scratcher
10 posts

How do I detect colors?

TY malicondii! That helps a lot!
TannerCraft98
Scratcher
10 posts

How do I detect colors?

If you don't mind, could you explain to me why it uses those specific numbers?
malicondii
Scratcher
100+ posts

How do I detect colors?

TannerCraft98 wrote:

If you don't mind, could you explain to me why it uses those specific numbers?
because of the way touching color works, you don't have to go through all 16.7 million different color combinations, scratch isn't that sensitive. so, for the first loop i can skip 16, second i can skip 8 and third i can skip again 8 (because its more sensitive for reds and greens which are the 8's rather than blues, which are the 16's).
TannerCraft98
Scratcher
10 posts

How do I detect colors?

Oh! Thanks! But why 1792 and 7 x 65538? (I'm not good with math lol) Tysm for explaining!
malicondii
Scratcher
100+ posts

How do I detect colors?

TannerCraft98 wrote:

Oh! Thanks! But why 1792 and 7 x 65538? (I'm not good with math lol) Tysm for explaining!
so, because there is 256 * 256 * 256 different color values, and since I'm only looking through 16 out of the 256 values, (256/16 for skipping every 15 values) that is 256 values i've already searched through so we subtract that from the first multiplication. For the green values, we are skipping color by 256 for each search, and since we're skipping 8 greens, we would skip 256 * 8, or 2048 values, and since we already checked 256 values (for blue) we subtract that and we get 1792. Each red value is 256*256, or 65536, and we're skipping every 8 it would be 8 * 65536. But since we already checked that many values once for all of the greens, we only change red by 65536 * 7 (minus one for the greens)
hope this explains it well enough, i'm not the best at explaining things.

tl;dr multiplication values comes from the amount we're skipping by.

Last edited by malicondii (Feb. 11, 2024 21:51:39)

TannerCraft98
Scratcher
10 posts

How do I detect colors?

Okay, that's all my questions! Thank you SO much for explaining everything and teaching me how this works and how to do it.
I really appreciate it, thanks.
Btw I saw some of your other projects, they are really impressive! Keep up the great work!
malicondii
Scratcher
100+ posts

How do I detect colors?

TannerCraft98 wrote:

Okay, that's all my questions! Thank you SO much for explaining everything and teaching me how this works and how to do it.
I really appreciate it, thanks.
Btw I saw some of your other projects, they are really impressive! Keep up the great work!
Thank you! I appreciate the support!
Lecturer90
New Scratcher
1 post

How do I detect colors?

Can anyone help me with how to detect a block with a gradient colour in it?
SzymoQwerty
Scratcher
29 posts

How do I detect colors?

Lecturer90 wrote:

Can anyone help me with how to detect a block with a gradient colour in it?
You can use RGBA since scratch was made with JavaScript (JS)

ametrine_
Scratcher
1000+ posts

How do I detect colors?

Lecturer90 wrote:

Can anyone help me with how to detect a block with a gradient colour in it?
please make a new topic for your problem instead of posting on old ones
SpyCoderX
Scratcher
1000+ posts

How do I detect colors?

Lecturer90 wrote:

Can anyone help me with how to detect a block with a gradient colour in it?
Please make your own topic instead of replying to old ones.

Replying to old or abandoned topics is called Necroposting and is considered spam.

Thanks!

Powered by DjangoBB