How can I check, if there is a specific color in an area?
Like:
If(color in area(10,100,50,600) == color(0,0,255)){
run code
}
How can I check, if there is a specific color in an area?
Like:
If(color in area(10,100,50,600) == color(0,0,255)){
run code
}
Err, get(x,y) gives you one point
get with 4 parameters gives you a rectangle that you could loop over to check all points in it
If I use get with 4 parameters it says: Type mismatch,“processing.core.PImage” does not match with “int”
Yeah, using it with 4 parameters gives you an image (the section of the big image)
PImage section = get(…); // 4 parameters
Look at loadPixels and pixels to see how to for loop over it to check single points
With a for loop its too slow. I want to create a PacMan game where it should get checked fast to stop the character if a blue pixel is x+24 pixels next to it.
When you know it’s x+24 then use get with 2 parameters to get the color of this point
color testColor=get(x+24,y);
Test it against the color blue
can I also check if the color blue is in the area (x+24,y-24,x+24,y+24)?
Yes.
Theoretically
so when you have the direction stored (int dir=0
or 1 or 2… for north, east, south, west) make the check accordingly.
Otherwise you have to write in full length:
if( get(x+24,y) == BLUE ||
get(x-24,y) == BLUE ||
.... ) {
// reached a wall
}
(|| means logical OR, && means logical AND)
This doesn’t make much sense because it would nearly always give you that PacMan reached a wall. So he wouldn’t be able to move anyway.
Instead, when you hit a cursor (or wasd keys) to make PacMan move, check only the direction for that key and allow the move or disallow move.
Chrisir
[EDITED]
so is this the only way to set pixels?
loadPixels()
pixels[x+y*w] = color(255)
updatePixels()
… or use point()
command