//Creating images with RGB colours - 1
var output = new SimpleImage(320, 320);
for(var pixel of output.values()){
if(dist(pixel, 100, 100) < 50){
pixel.setRed(255 - 4*dist(pixel, 100, 100));
}
else if(dist(pixel, 200, 200) < 80){
pixel.setGreen(255 - 3*dist(pixel, 200, 200));
}
else if(Math.random() > 0.995){
//Scattering the background with yellow stars.
//if we do the steps above without else if then they will be in the front
pixel.setRed(255);
pixel.setGreen(255);
}
//pixel.setBlue(1.5*pixel.getY()-pixel.getX());
//pixel.setBlue(pixel.getX() - 1.5*pixel.getY());
pixel.setBlue(Math.max( (1.5*pixel.getY() - pixel.getX()) , (pixel.getX() - 1.5*pixel.getY()) ));
}
print(output);
function dist(pixel, x1, y1){
//Finding the distance between pixel and a point(x,y)
/*
Distance Formula: Given the two points (x1, y1) and (x2, y2), the distance between these points is given by the formula: d == Math.sqrt((x2-x1)^2 + (y2-y1)^2);
*/
var x2 = pixel.getX();
var y2 = pixel.getY();
var dx = x2-x1;
var dy = y2-y1;
var distance = Math.sqrt(dx*dx + dy*dy);
return distance;
}