Changeset - cd4a9eeeb9e6
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 20 months ago 2023-05-29 20:21:14
drewp@bigasterisk.com
special case- white picks the center-top px
1 file changed with 5 insertions and 0 deletions:
0 comments (0 inline, 0 general)
light9/web/floating_color_picker.ts
Show inline comments
 
@@ -73,24 +73,29 @@ class RainbowCanvas {
 
  }
 

	
 
  colorAt(pos: RainbowCoord) {
 
    var data = this.ctx.getImageData(pos.x, pos.y, 1, 1).data;
 
    return color([data[0], data[1], data[2], 255]).hex();
 
  }
 

	
 
  posFor(col: string): RainbowCoord {
 
    if (col == "#000000") {
 
      throw new Error("no match");
 
    }
 

	
 
    log("col", col);
 
    if (col == "#ffffff") {
 
      return new RainbowCoord(400 / 2, 0);
 
    }
 

	
 
    let bright = color(col).value(1).hex();
 
    let r = parseInt(bright.slice(1, 3), 16),
 
      g = parseInt(bright.slice(3, 5), 16),
 
      b = parseInt(bright.slice(5, 7), 16);
 

	
 
    // We may not have a match for this color exactly (e.g. on
 
    // the small image), so we have to search for a near one.
 

	
 
    // 0, 1, -1, 2, -2, ...
 
    let walk = function (x: number): number {
 
      return -x + (x > 0 ? 0 : 1);
 
    };
0 comments (0 inline, 0 general)