Tuesday, 28 June 2016

Suppose we have a black image named image and we want to change just part of the image to green as indicated in this image: Consider the following code with a missing condition to do this:


Suppose we have a black image named image and we want to change just part of the image to green as indicated in this image:

Consider the following code with a missing condition to do this:



image = new SimpleImage(200,200);
for (var p of image.values()){
    p.setRed(0);
    p.setGreen(0);
    p.setBlue(0);
w = image.getWidth();
h = image.getHeight();
for (var pixel of image.values()) {
     x = pixel.getX();
     y = pixel.getY();
     if ( x > w/3 && y < 2*h/3 && y > h/3 ) {
          pixel.setGreen(255);
          pixel.setRed(0);
          pixel.setBlue(0);
     }
}
print(image);


No comments:

Post a Comment