Can Processing set a range of values?

edited December 2013 in Android Mode

hi, i'm new in processing Currently i'm doing a camera colour pixel related app. ---(White=255,Black=0) everything works fine but i can't add range of colours to it i can only set a colour, or a range to darkest black( total/3 < 60) which i don't want i want to set a range of (ligthen)black to grey (e.g) 40 to 60 my code is as follow:

  float r = red(cam.pixels[loc]);
  float g = green(cam.pixels[loc]);
  float b = blue(cam.pixels[loc]);
  float total = r+g+b;



  if (total/3 > 238)
  {

    try 
  {......         
  }

  else if (total/3 == 60 ) //problem here
  {......
  }

Answers

  • Answer ✓

    I am sorry, but I find your question unclear... (and is it really related / specific to Android mode?)

    I don't see what the try is doing there. Nor what you try to do exactly.

    Perhaps the answer is to just use && (logical AND).

    float third = total / 3;
    if (third > 238)
    {
      doStuff();
    }
    else if (third > 128) // Between 128 and 238
    {
      doOtherStuff();
    }
    else if (third > 40 && third < 60) // Between 40 and 60. 
    {
      doSomethingElse();
    }
    

    Note that == doesn't work with floating-point numbers! (in general)

  • it's for android mode, the 'try' was actually doing something for the bottom part coding. Anyway thanks! then code works fine! thanks so much ;)

Sign In or Register to comment.