きつくないcolor_id一覧を表示する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
// id : 0 - 16777215 (24bit) // 1 -> [ 0, 0, 1 ] // 16777214 -> [ 255, 255, 254 ] // 16777215 -> [ 255, 255, 255 ] // 16777216 -> [ 0, 0, 0 ] function idToArray(id){ var n = id; var c = Math.floor(n % 256); n /= 256; var b = Math.floor(n % 256); n /= 256; var a = Math.floor(n % 256); n /= 256; return [a, b, c]; } function max(a){ var m = a[0]; for(var v of a){ if(m < v){ m = v; } } return m; } function min(a){ var m = a[0]; for(var v of a){ if(v < m){ m = v; } } return m; } // id : 0 - 16777215 (24bit) function isNgId(id){ var rgb = idToArray(id); // (python) if rgb[0] + rgb[1] + rgb[2] < 60 or rgb[0] + rgb[1] + rgb[2] > 700 or max(rgb) - min(rgb) > 200: if( (rgb[0] + rgb[1] + rgb[2]) < 60 || (rgb[0] + rgb[1] + rgb[2]) > 700 || max(rgb) - min(rgb) > 200 ){ return true; } else { return false; } } function p(a){ console.log(a); } function getRandomInt(min, max){ var d = Math.random(); var randomOffset = Math.floor(d * (max - min + 1)); return min + randomOffset; } function dise(){ let min = 1; let max = 6; return getRandomInt(min, max); } function dispArrayList(a){ for(let k in a){ let v = a[k]; p(k + " => " + v); } } function getRandomColorId(){ let start = 0; let end = 256*256*256 - 1; return getRandomInt(start, end); } function main(){ let a = []; let cnt = 0; while(true){ let n = getRandomColorId(); if(isNgId(n)){ continue; } a[cnt++] = n; if(40 <= cnt){ break; } } dispArrayList(a); } main(); |