Skip to content

Instantly share code, notes, and snippets.

@45deg 45deg/pro100.js
Created Sep 27, 2015

Embed
What would you like to do?
(function(){
var img = new Image();
var c = document.createElement('canvas');document.body.appendChild(c);
var ctx = c.getContext("2d");
img.src = document.images[0].src;
img.onload = function(){ c.width = img.width; c.height=img.height;
ctx.drawImage(img, 0, 0);
var data = ctx.getImageData(0, 0, img.width, img.height).data;
var arr = []; var pos = [];console.log(img.width,img.height); var are = [];
for(var i = 0; i < img.width * img.height; i++){
var col = 'c' + [data[4*i+0],data[4*i+1],data[4*i+2],data[4*i+3]].join('');
arr[col] = arr[col] ? arr[col]+1 : 1; pos[col] = [i % img.width, i / img.width | 0];
}
for(a in arr){ if(a != 'c255255255255') are.push([arr[a], pos[a]]); }
var poss = (are.sort()[0][1]); // ここのsortが変なのでWrongが出たら are.sort()[0] を are.sort()[1] にした
var q = '?x=' + poss[0] + '&y=' + poss[1]; location.href=img.src.replace(/\/img/, '').replace(/.png/, q);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.