きつい色をNGにするアルゴリズム。pythonのコードをjsに書き換えた
1 2 3 4 5 6 7 8 9 10 11 12 |
numlist = [] for i in range(16777216): hexed = hex(i)[2:8].zfill(6) rgb = [int(hexed[0:2], 16), int(hexed[2:4], 16), int(hexed[4:6], 16)] if rgb[0] + rgb[1] + rgb[2] < 60 or rgb[0] + rgb[1] + rgb[2] > 700 or max(rgb) - min(rgb) > 200: numlist.append(i) output_target = open('output', 'w') output_target.write(str(numlist)) output_target.close() |
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 |
// 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; } } |