git ssb

0+

cel / ssb-activity



Commit 6349a39796d35a2159558bb5333e2a3762fd9463

Ensure uniqueness of user colors

cel committed on 11/17/2019, 10:36:39 PM
Parent: e6771acdf6578c1d07533da3811ea9d6fc8575a7

Files changed

run.jschanged
run.jsView
@@ -46,18 +46,27 @@
4646 })
4747
4848 var userColors = {}
4949 var userNumbers = {}
50 +var colorsUsed = {}
5051
5152 for (var i = 0; i < ids.length; i++) {
5253 var id = ids[i]
5354 userNumbers[id] = i
5455 var x = i / ids.length
5556 var colorI = Math.floor(x*20)
5657 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
6069 }
6170
6271 function setPixel(data, x, y, color) {
6372 var i = (y * width + x) << 2

Built with git-ssb-web