Solve It
In this example we will create a black border of 10 pixels on all edges of an image that is 300 by 200 pixels. The middle of the image will be white. To solve this problem, we should create a new image with the specified dimensions. We need to identify whether or not a pixel is within 10 pixels of any edge, and if so, we will color it black. Otherwise, it will be colored white.
Code It
// border frame
var image = new SimpleImage(300,200);
for (var p of image.values()) {
p.setRed(255);
p.setGreen(255);
p.setBlue(255);
if (p.getX() > 289){
p.setGreen(0);
p.setBlue(0);
p.setRed(0);
}
if (p.getX() > 289){
p.setGreen(0);
p.setBlue(0);
p.setRed(0);
}
if (p.getX() < 10){
p.setGreen(0);
p.setBlue(0);
p.setRed(0);
}
if (p.getY() < 10){
p.setGreen(0);
p.setBlue(0);
p.setRed(0);
}
if (p.getY() > 189){
p.setGreen(0);
p.setBlue(0);
p.setRed(0);
}
}
print(image);
See It
Available Images
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.
