Solve It
This example is similar to the last border problem we completed. Again we are coloring the 10 pixels along each edge of an image black to make a frame around the image. This time we will start with an image rather than making a new one, and we will use a function called "setBlack" to do some of the work. Making functions makes our code easier to read, write, and debug.
Code It
// border frame using a function
function setBlack(px){
px.setRed(0);
px.setGreen(0);
px.setBlue(0);
return px;
}
var image = new SimpleImage("lion.jpg");
for (var pixel of image.values()) {
var x = pixel.getX();
var y = pixel.getY();
if (x < 10){
pixel = setBlack(pixel);
}
if (y < 10){
pixel = setBlack(pixel);
}
if (x >= image.getWidth()-10){
pixel = setBlack(pixel);
}
if (y >= image.getHeight()-10){
pixel = setBlack(pixel);
}
}
print(image);
See It
Available Images

lion.jpg
[250x188]
Drop your images onto the area above to make it available within your code editor on this page. Note: your images will not be uploaded anywhere, they will stay on your computer.
