Commit 6349a39796d35a2159558bb5333e2a3762fd9463
Ensure uniqueness of user colors
cel committed on 11/17/2019, 10:36:39 PMParent: e6771acdf6578c1d07533da3811ea9d6fc8575a7
Files changed
run.js | changed |
run.js | |||
---|---|---|---|
@@ -46,18 +46,27 @@ | |||
46 | 46 … | }) | |
47 | 47 … | ||
48 | 48 … | var userColors = {} | |
49 | 49 … | var userNumbers = {} | |
50 … | +var colorsUsed = {} | ||
50 | 51 … | ||
51 | 52 … | for (var i = 0; i < ids.length; i++) { | |
52 | 53 … | var id = ids[i] | |
53 | 54 … | userNumbers[id] = i | |
54 | 55 … | var x = i / ids.length | |
55 | 56 … | var colorI = Math.floor(x*20) | |
56 | 57 … | var inbetweenAmount = x*20 - colorI | |
57 | - var c = common.interpolate(common.colors20[colorI], common.colors20[colorI+1], inbetweenAmount) | ||
58 | - c[3] = 255 | ||
59 | - userColors[id] = c | ||
58 … | + var color = common.interpolate(common.colors20[colorI], common.colors20[colorI+1], inbetweenAmount) | ||
59 … | + color[0] = Math.floor(color[0]) | ||
60 … | + color[1] = Math.floor(color[1]) | ||
61 … | + color[2] = Math.floor(color[2]) | ||
62 … | + color[3] = 255 | ||
63 … | + // Ensure uniqueness | ||
64 … | + while (colorsUsed[color]) { | ||
65 … | + color[3]-- | ||
66 … | + } | ||
67 … | + colorsUsed[color] = true | ||
68 … | + userColors[id] = color | ||
60 | 69 … | } | |
61 | 70 … | ||
62 | 71 … | function setPixel(data, x, y, color) { | |
63 | 72 … | var i = (y * width + x) << 2 |
Built with git-ssb-web