Re: All given colors to picture, so that neighbor color total difference is minimum

Aman Livinginviljandicity <[email protected]> Sat, 21 Nov 2020 10:17:40 -0800 (PST)
Newsgroups alt.comp.lang.javascript
Message-ID <[email protected]>
I have now something like following, but it seems not to be the thing I want:

<html>
<body>
<canvas id="canvas" width="1200" height="1000"></canvas>

<script>

function draw() {
  var ctx = document.getElementById('canvas').getContext('2d');
  var a=new Array();
  var a2=new Array();

  for (var i = 0; i < 256; i=i+2) {
    for (var j = 0; j < 256; j=j+2) {
       for (var k = 0; k < 256; k=k+2) {
          a.push(new Array('rgb(' + i + ', ' + j + ', '+k+')', Math.sqrt((i*i+j*j+k*k)/3)));
          a2.push(new Array(i,j,k));
      }
    }
  }


a.sort(function(aa1, bb1) {
    return aa1[1] - bb1[1];
});

  var c1=0;

  for (var i = 0; i < 1200; i++) {
    for (var j = 0; j < 1000; j++) {
       
       ctx.fillStyle=a[c1][0];
       ctx.fillRect(i,j,1,1);
       c1++;
    }
  } 

}

draw();

</script>
</body>
</html>

Khritjan Robam
Phone number: 372 57865442
E-mail: he12457 hotmail com