function setBlack(pixel) {
pixel.setRed(0);
pixel.setGreen(0);
pixel.setBlue(0);
return pixel;
}
function pixelOnEdgeDifferentThicknesses (pixel, image, vWidth, hWidth) {
var x = pixel.getX();
var y = pixel.getY();
if (x < vWidth) return true;
if (y < hWidth) return true;
if (x >= image.getWidth() - vWidth) return true;
if (y >= image.getHeight() - hWidth) return true;
return false;
}
var image = new SimpleImage("usain.jpg");
for (var pixel of image.values()) {
if (pixelOnEdgeDifferentThicknesses (pixel, image, 10, 40)) {
pixel = setBlack(pixel);
}
}
print(image);
pixel.setRed(0);
pixel.setGreen(0);
pixel.setBlue(0);
return pixel;
}
function pixelOnEdgeDifferentThicknesses (pixel, image, vWidth, hWidth) {
var x = pixel.getX();
var y = pixel.getY();
if (x < vWidth) return true;
if (y < hWidth) return true;
if (x >= image.getWidth() - vWidth) return true;
if (y >= image.getHeight() - hWidth) return true;
return false;
}
var image = new SimpleImage("usain.jpg");
for (var pixel of image.values()) {
if (pixelOnEdgeDifferentThicknesses (pixel, image, 10, 40)) {
pixel = setBlack(pixel);
}
}
print(image);
No comments:
Post a Comment