document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //Creating images with RGB colours - 1
  2. var output = new SimpleImage(320, 320);
  3. for(var pixel of output.values()){
  4.     if(dist(pixel, 100, 100) < 50){
  5.         pixel.setRed(255 - 4*dist(pixel, 100, 100));
  6.     }
  7.     else if(dist(pixel, 200, 200) < 80){
  8.         pixel.setGreen(255 - 3*dist(pixel, 200, 200));
  9.     }
  10.     else if(Math.random() > 0.995){
  11.         //Scattering the background with yellow stars.
  12.         //if we do the steps above without else if then they will be in the front
  13.         pixel.setRed(255);
  14.         pixel.setGreen(255);
  15.     }
  16.     //pixel.setBlue(1.5*pixel.getY()-pixel.getX());
  17.     //pixel.setBlue(pixel.getX() - 1.5*pixel.getY());
  18.     pixel.setBlue(Math.max( (1.5*pixel.getY() - pixel.getX()) , (pixel.getX() - 1.5*pixel.getY()) ));
  19. }
  20.  
  21. print(output);
  22.  
  23. function dist(pixel, x1, y1){
  24.     //Finding the distance between pixel and a point(x,y)
  25.     /*
  26. 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);
  27. */
  28.     var x2 = pixel.getX();
  29.     var y2 = pixel.getY();
  30.     var dx = x2-x1;
  31.     var dy = y2-y1;
  32.     var distance = Math.sqrt(dx*dx + dy*dy);
  33.     return distance;
  34. }
');