this was my first attempt at solving the issue, it's not technically the correct answer, but I had to do it this way to create a starting point:
var picture = new SimpleImage("hilton.jpg");
for (var pixel of picture.values()) {
if ((pixel.getX () >= 0 )) if ((pixel.getX () <= 47 )){
pixel.setRed(255);
}
if ((pixel.getX () >= 47 )) if ((pixel.getX () <= 95 )){
pixel.setGreen(255);
}
if ((pixel.getX () >= 95 )) if ((pixel.getX () <= 140 )){
pixel.setBlue(255);
}
}
print(picture)
What I did was manually enter the x-values that would create different 1/3 stripes for the picture, but this wouldn't work, if, say, I was trying to use this code on a different picture with a different width, so the next step is to create a code that automatically creates the 1/3 values, and that's the next step.
var picture = new SimpleImage("hilton.jpg");
for (var pixel of picture.values()) {
if ((pixel.getX () >= (0 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (1 * picture.getWidth() * (1/3)) )){
pixel.setRed(255);
}
if ((pixel.getX () >= (1 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (2 * picture.getWidth() * (1/3)) )){
pixel.setGreen(255);
}
if ((pixel.getX () >= (2 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (3 * picture.getWidth() * (1/3) ))){
pixel.setBlue(255);
}
}
print(picture)
once it can base the x-coordinates on the actual width, it can be used on any other picture.
var picture = new SimpleImage("eastereggs.jpg");
for (var pixel of picture.values()) {
if ((pixel.getX () >= (0 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (1 * picture.getWidth() * (1/3)) )){
pixel.setRed(255);
}
if ((pixel.getX () >= (1 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (2 * picture.getWidth() * (1/3)) )){
pixel.setGreen(255);
}
if ((pixel.getX () >= (2 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (3 * picture.getWidth() * (1/3) ))){
pixel.setBlue(255);
}
}
print(picture)
* * *
var picture = new SimpleImage("eastereggs.jpg");
for (var pixel of picture.values()) {
if ((pixel.getX () >= (0 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (1 * picture.getWidth() * (1/3)) )){
pixel.setRed(255);
}
if ((pixel.getX () >= (1 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (2 * picture.getWidth() * (1/3)) )){
pixel.setGreen(255);
}
if ((pixel.getX () >= (2 * picture.getWidth() * (1/3)) )) if ((pixel.getX () <= (3 * picture.getWidth() * (1/3)) )){
pixel.setBlue(255);
}
}
print(picture)
* * *
I tried to simplify the code, but this didn't work.
var picture = new SimpleImage("hilton.jpg");
for (var pixel of picture.values()) {
if ((((1 * picture.getWidth() * (1/3))) <= (pixel.getX ()) >= ((0 * picture.getWidth() * (1/3))) )){
pixel.setRed(255);
}
if ((((2 * picture.getWidth() * (1/3))) <= (pixel.getX ()) >= ((1 * picture.getWidth() * (1/3))) )){
pixel.setGreen(255);
}
if ((((3 * picture.getWidth() * (1/3))) <= (pixel.getX ()) >= ((2 * picture.getWidth() * (1/3))) )){
pixel.setBlue(255);
}
}
print(picture)
No comments:
Post a Comment