jeudi 1 décembre 2016

if condition in javascript using variables

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);

Aucun commentaire:

Enregistrer un commentaire