Now modify the border program to specify two thicknesses, one for the vertical borders and one for the horizontal borders. You should write the two boolean functions shown below. Be sure to print the image and run your program with different border values for the horizontal and vertical edges. a) function pixelOnVerticalEdge(pixel, image, borderWidth)—This function has three parameters where pixel is a single pixel, image is the complete image, and borderWidth is an integer specifying the thickness of the vertical borders. This function returns true if the pixel’s location is within borderWidth of any of the two vertical borders, and thus on the border. Otherwise it returns false. b) function pixelOnHorizontalEdge(pixel, image, borderWidth)—This function has three parameters where pixel is a single pixel, image is the complete image, and borderWidth is an integer specifying the thickness of the horizontal borders. This function returns true if the pixel’s location is within borderWidth of any of the two horizontal borders, and thus on the border. Otherwise it returns false.
// write your code here
function setBlack(pixel){
pixel.setBlue(0);
pixel.setGreen(0);
pixel.setRed(0);
return pixel;
}
function pixelOnVerticalEdge(pixel, image, borderWidth){
var x = pixel.getX();
var y = pixel.getY();
if (x < borderWidth) return true;
if (x >= image.getWidth() - borderWidth) return true;
return false;
}
function pixelOnHorizontalEdge(pixel, image, borderWidth){
var x = pixel.getX();
var y = pixel.getY();
if (y < borderWidth) return true;
if (y >= image.getHeight() - borderWidth) return true;
return false;
}
var image = new SimpleImage ("lion.jpg");
print (image);
for ( var pixel of image.values()){
if (pixelOnHorizontalEdge(pixel, image, 25) ){
pixel = setBlack(pixel);
}
if (pixelOnVerticalEdge(pixel, image, 40)){
pixel = setBlack(pixel);
}
}
print (image);
Comments
Post a Comment