The problem with this code is when I'm executing the if condition. The condition only works if i am using if (pixel.getx() <=100) but does not work for a var x = pixel.getX() & if (x <= 100). Can someone tell me why?
var image = new SimpleImage (200,200);
print (image);
for (var pixel of image.values())
var x = pixel.getX();
var y = pixel.getY()
if (x <= 100 && y <= 100)
{
pixel.setRed(255);
pixel.setBlue(0);
pixel.setGreen(0);
}
else if (x > 100)
{
pixel.setBlue(255);
pixel.setGreen(0);
pixel.setRed(0);
}
print (image);
SimpleImage?getxandgetXare two different methods. Is that the issue? Or just a typo in the question?for (var pixel of image.values())loop isn't using{braces}and therefore operates only on the next statement after it,var x = pixel.getX();The rest of your code, including theifstatement, is not part of the loop.var x = pixel.getX() & if (x <= 100)is not valid syntax, so that's an issue