KITASENJU DESIGN BLOG

memo, html, javascript, unity

color pick

let img;
let dom;
let isInit=false;
let isDown=false;
function setup() {
  let c = createCanvas(100, 100);
  c.drawingContext.imageSmoothingEnabled=false;
  background(200);
  textAlign(CENTER);
  text('drop image', width / 2, height / 2);
  c.drop(gotFile);
  dom = document.getElementById("colors");
}

function mousePressed() {
  isDown=true;
}

function draw() {
  if (img) {
    isInit=true;
    image(img, 0, 0, width, height);
  }
  
  if(isDown){
    isDown=false;
    dom.innerHTML = "";
    let lim=40;
    for(let i=0;i<lim;i++){
    let c = get(random(0,width),random(0,height));
    
    
    let hx = "#" + hex(c[0],2) + hex(c[1],2) + hex(c[2],2);
    dom.innerHTML += '"' + hx + '"';
      if(i!=lim-1) dom.innerHTML+=","
    }    
  }
  
}

function gotFile(file) {
  img = createImg(file.data, '').hide();
}
"FOOTER"