The Colors in Our Stars Write a program that takes in a string or text file whose first line has the form

width height


and each subsequent line has the form

x y intensity red green blue


where:


width and height may be any positive integers.
x and y may be any integers.
intensity may be any non-negative integer.
red, green, and blue may be any integers from 0 to 255 inclusive.


Your program must output a truecolor image in any common lossless image file format whose dimensions are width by height. Each x y intensity red green blue line represents a colorful star or orb that must be drawn on the image. There may be any number of stars to draw, including 0. You may assume the string or file has a trailing newline.

The algorithm for drawing the image is as follows, though you may implement it in any way you like as long as the result is identical:


  For every pixel (X,Y) in the image (where X is 0 at the leftmost
  edge and width-1 at the rightmost edge, and Y is 0 at the top edge
  and height-1 at the bottom edge), the color channel C ϵ {red,
  green, blue} (a value pinned between 0 to 255) is given by the equation:
  
  
  
  Where the dist function is either Euclidean distance:
  
  
  
  Or Manhattan distance:
  
  
  
  Choose whichever distance function you prefer, based on golfability or aesthetics.
  
  Each of the lines in the input besides the first is an element of the Stars set. So, for example, Sx represents the x value on one of the input lines, and SC represents either red, green, or blue, depending on which color channel is currently being calculated.


Examples

Example A

If the input is

400 150
-10 30 100 255 128 0


the output should be



if you're using Euclidean distance, and



if you're using Manhattan distance.

Example B

If the input is

200 200
100 100 10 255 255 255
20 20 40 255 0 0
180 20 40 255 255 0
180 180 40 0 255 0
20 180 40 0 0 255


the respective outputs for Euclidean and Manhattan distance should be

 and .

Example C

If the input is

400 400
123 231 10 206 119 85
358 316 27 170 47 99
95 317 3 202 42 78
251 269 17 142 150 153
43 120 3 145 75 61
109 376 6 230 231 52
331 78 21 31 81 126
150 330 21 8 142 23
69 155 11 142 251 199
218 335 7 183 248 241
204 237 13 112 253 34
342 89 18 140 11 123


the output should be



if you're using Euclidean distance, and



if you're using Manhattan distance.

Example D

If the input is

400 400
123 231 5 206 119 85
358 316 5 170 47 99
95 317 5 202 42 78
251 269 5 142 150 153
43 120 5 145 75 61
109 376 5 230 231 52
331 78 5 31 81 126
150 330 5 8 142 23
69 155 5 142 251 199
218 335 5 183 248 241
204 237 5 112 253 34
342 89 5 140 11 123


the output should be



if you're using Euclidean distance, and



if you're using Manhattan distance.

Example E

If the input is

100 1


then the output should be a 100 pixel wide by 1 pixel tall image that is completely black.

Notes


Take the input string or the name of a text file that contains it from stdin or the command line, or you may write a function that takes in a string.
"Outputting" the image means either:


Saving it to a file with the name of your choice.
Printing the raw image file data to stdout.
Displaying the image, such as with PIL's image.show().

I won't be checking that your images are pixel perfect (Stack Exchange lossily compresses images anyway) but I will be very suspicious if I can visually tell any difference.
You may use graphics/image libraries.


Winning

The shortest submission in bytes wins. In case of ties, the earliest submission wins.

Fun Bonus: Give the input for a truly spectacular output image.
JavaScript 394 344

function X(a){for(l=a.match(/\d+/g),h=document,v=h.body.appendChild(h.createElement(&quot;canvas&quot;)),v.width=W=l[0],v.height=H=l[1],w=v.getContext(&quot;2d&quot;),e=w.createImageData(W,H),d=e.data,N=W*H;N--;)for(i=2,c=N*4,d[c+3]=255;i&lt;l.length;)for(x=N%W-l[i++],y=~~(N/W)-l[i++],k=l[i++],q=0;q&lt;3;)d[c+q++]+=k*l[i++]/-~Math.sqrt(x*x+y*y);w.putImageData(e,0,0);}

Edit: shortened the code a lot by applying wolfhammer's awesome suggestions.
Test
Note: Wait a few seconds for the snippet below to render (takes ~4 seconds on my machine).


function X(a){for(l=a.match(/\d+/g),h=document,v=h.body.appendChild(h.createElement("canvas")),v.width=W=l[0],v.height=H=l[1],w=v.getContext("2d"),e=w.createImageData(W,H),d=e.data,N=W*H;N--;)for(i=2,c=N*4,d[c+3]=255;i&lt;l.length;)for(x=N%W-l[i++],y=~~(N/W)-l[i++],k=l[i++],q=0;q&lt;3;)d[c+q++]+=k*l[i++]/-~Math.sqrt(x*x+y*y);w.putImageData(e,0,0);}

var start = Date.now();

X("400 150\n" +
  "-10 30 100 255 128 0");

X("200 200\n" +
  "100 100 10 255 255 255\n" +
  "20 20 40 255 0 0\n" +
  "180 20 40 255 255 0\n" +
  "180 180 40 0 255 0\n" +
  "20 180 40 0 0 255");

X("400 400\n" +
  "123 231 10 206 119 85\n" +
  "358 316 27 170 47 99\n" +
  "95 317 3 202 42 78\n" +
  "251 269 17 142 150 153\n" +
  "43 120 3 145 75 61\n" +
  "109 376 6 230 231 52\n" +
  "331 78 21 31 81 126\n" +
  "150 330 21 8 142 23\n" +
  "69 155 11 142 251 199\n" +
  "218 335 7 183 248 241\n" +
  "204 237 13 112 253 34\n" +
  "342 89 18 140 11 123");

X("400 400\n" +
  "123 231 5 206 119 85\n" +
  "358 316 5 170 47 99\n" +
  "95 317 5 202 42 78\n" +
  "251 269 5 142 150 153\n" +
  "43 120 5 145 75 61\n" +
  "109 376 5 230 231 52\n" +
  "331 78 5 31 81 126\n" +
  "150 330 5 8 142 23\n" +
  "69 155 5 142 251 199\n" +
  "218 335 5 183 248 241\n" +
  "204 237 5 112 253 34\n" +
  "342 89 5 140 11 123");

var end = Date.now();

console.log('Done in ' + (end - start)/1000 + 's.');
canvas {
  display: block;
  padding: 10px;
}



You can also run it in JSFiddle.
Bonus: Blue Eclipse


function X(a){for(l=a.match(/\d+/g),h=document,v=h.body.appendChild(h.createElement("canvas")),v.width=W=l[0],v.height=H=l[1],w=v.getContext("2d"),e=w.createImageData(W,H),d=e.data,N=W*H;N--;)for(i=2,c=N*4,d[c+3]=255;i&lt;l.length;)for(x=N%W-l[i++],y=~~(N/W)-l[i++],k=l[i++],q=0;q&lt;3;)d[c+q++]+=k*l[i++]/-~Math.sqrt(x*x+y*y);w.putImageData(e,0,0);}

var j = 0;
var renderFrame = function () {
  if(window.h &amp;&amp; window.v){h.body.removeChild(v);} // clear prev frame
  X("225 150\n" +
    (70 + j) + " " + (120 - j) + " 170 135 56 0\n" + 
    j * 5 + " " + j * 3 + " 64 0 50 205");       
  if(++j &lt; 50) { setTimeout(renderFrame, 1); } else { console.log('done!'); }
};
setTimeout(renderFrame, 10);



You can also run it in JSFiddle.
Description
This is a straightforward JavaScript + HTML5 canvas implementation: a function that takes a string argument (without trailing spaces/newlines) and displays the output in the DOM. It uses Euclidean distance.
Here is the readable code:
X = function (str) {
  var lines = str.split(&quot;\n&quot;);  
  var canvas = document.createElement('canvas');
  var z = lines[0].split(u=' ');
  var width = z[0], height = z[1];
  
  canvas.width = width;
  canvas.height = height;
  document.body.appendChild(canvas);
 
  var ctx = canvas.getContext(&quot;2d&quot;);
  var imageData = ctx.createImageData(width, height);
  
  for(var y = 0; y &lt; height; y++){
    for(var x=0; x &lt; width; x++){
      var coord = (y * width + x) * 4;
      
      for(i=1; i &lt; lines.length;i++){
        var t = lines[i].split(u);

        var 
          dx = x - t[0], 
          dy = y - t[1];

        var distance = Math.sqrt(dx * dx + dy * dy);

        for(var channel = 0; channel &lt; 3; channel++) {
          var channelIndex = coord + channel;
          imageData.data[channelIndex] += t[2] * t[3 + channel] / (distance + 1);
        }
      }
      
      var alphaIndex = coord + 3;
      imageData.data[alphaIndex] = 255;
    }
  }

  ctx.putImageData(imageData, 0, 0);
};