Purple and Green Image Making

Solve It

In this example we are using math functions to map a pixel's location into its color. We begin by making a new image that is 256 pixels by 256 pixels. This is convenient because it means that the valid x and y values are from 0 to 255 inclusive, which is exactly the same range as our color values. Therefore, we can directly use the x and y values as color values. If we use the x value as the red and blue values and the y value as the green, we get an interesting visual effect that blends purple and green. When the x value is greater than the y value, we will see more purple than green. When the y value is greater than the x value, the green will dominate. When x = y, the green and purple (red and blue) values will be equal. Whenever all three color values are equal we get a shade of gray.

Code It

// purple and green var image = new SimpleImage(256, 256); for (var pixel of image.values()) { var x = pixel.getX(); var y = pixel.getY(); pixel.setRed(x); pixel.setGreen(y); pixel.setBlue(x); } 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.