Hey, im working on trying to use a get() function within an IF statement to detect a pixels colour,
The code that looks like this..
if( get(x)(y+0.1) != color(0) ){ //check for pixel below particle y to not equal the color black
speed = 0; //If the pixel isn't black speed = 0
This IF statement isn't working.
Does anyone knows how to use the get() function correctly? or instead, recommend a better function to use to check a pixels colour that would help alot.
I've been trying to work out a basic particle color detection program for a few hours and cant seem to find the answer with my little experience in processing.
The program is meant to simulate snow falling down, when it hits a line
which is white the snowflakes are meant to stop falling and build up ontop of eachother.
The
background is set to black so when the particles reach a pixel that is not black, theoretically they should stop falling
If anyone with a fresh pair of eyes can see the cure to my basic problem, i would be very grateful.
I believe the problem is within: void(move), which i have highlighted in
bold
Thanks in advance.
MAIN BODY
PImage E;
int numSnow = 100;
Snow[] Snowblizzard = new Snow[numSnow];
void setup(){
E = loadImage("LetterEFinal.jpg");
size(400,400);
for (int i=0; i<Snowblizzard.length; i++) {
Snowblizzard [i] = new Snow (random(width), random (height) ); //creates ball at random coordinates within parameter
}
}
void draw(){
image(E,0,0);
background(E);
// fill (255);
smooth();
for (int i = 0; i < Snowblizzard.length; i++) {
Snowblizzard [i].run();
}
}
CLASS BALL
class Snow {
//global variables
float x=0; //x coordinate of particle
float y=0; //y coordinate of particle
float S=1; //speed of snow falling
Snow(float _x, float _y) {
x = _x; //must use other variable besides x so _x, y and _y
y = _y;
}
void run () //void run plays void display and void move
{
display ();
move ();
}
void move () { //movement of the particle
if (y+11 == color(0)) { //if the pixel below the particle is white, then speed is set to 0
S = 0;
}
else {
y += S; //particles continue to fall down at speed S
if ( y > height ) { //If particle reaches bottom of screen, reset to the top