{"version":3,"sources":["https://lively-kernel.org/lively4/BP2019RH-stable/src/internal/individuals-as-points/map/individualCanvas.js"],"names":["IndividualCanvas","constructor","canvas","individuals","pointSize","transform","scale","constPointSize","context","getContext","setIndividuals","updateScale","updatePointSize","updateTransform","threshold","clear","clearRect","width","height","draw","save","translate","x","y","drawIndividuals","restore","forEach","individual","drawPixel","color","getColor","r","g","b","opacity","drawing","position","beginPath","arc","Math","PI","fillStyle","fill","DefaultColoredCanvas","currentColor","UniqueColoredCanvas","identifyingColor"],"mappings":";;;;;;;;AAAA,YAAMA,gBAAN,CAAuB;;AAErBC,oBAAYC,MAAZ,EAAoBC,WAApB,EAAiCC,SAAjC,EAA4C;AAC1C,eAAKF,MAAL,GAAcA,MAAd;AACA,eAAKG,SAAL,GAAiB,EAAC,KAAK,CAAN,EAAS,KAAK,CAAd,EAAiB,KAAK,CAAtB,EAAjB;AACA,eAAKC,KAAL,GAAa,CAAb;AACA,eAAKH,WAAL,GAAmBA,WAAnB;AACA,eAAKC,SAAL,GAAiBA,SAAjB;AACA,eAAKG,cAAL,GAAsB,KAAKH,SAA3B;AACA,eAAKI,OAAL,GAAeN,OAAOO,UAAP,CAAkB,IAAlB,CAAf;AACD;;AAEDC,uBAAeP,WAAf,EAA4B;AAC1B,eAAKA,WAAL,GAAmBA,WAAnB;AACD;;AAEDQ,oBAAYL,KAAZ,EAAmB;AACjB,eAAKA,KAAL,GAAaA,KAAb;AACA,eAAKM,eAAL;AACD;;AAEDC,wBAAgBR,SAAhB,EAA2B;AACzB,eAAKA,SAAL,GAAiBA,SAAjB;AACD;;AAEDO,0BAAkB;AAChB,cAAIE,YAAY,GAAhB;AACA;AACA,cAAI,KAAKR,KAAL,GAAc,KAAKC,cAAL,GAAsBO,SAAxC,EAAoD;AAClD,iBAAKV,SAAL,GAAiB,KAAKG,cAAL,GAAsB,KAAKD,KAA5C;AACD,WAFD,MAEO,IAAK,KAAKC,cAAL,GAAsBO,SAAvB,IAAqC,KAAKR,KAA9C,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Ab,GAAyB,UAASV,CAAT,GAAY,GAAZ,GAAiBC,CAAjB,GAAoB,GAApB,GAAyBC,CAAzB,GAA4B,GAA5B,GAAiCC,OAAjC,GAA0C,GAAnE;AACA,eAAK1B,OAAL,CAAakC,IAAb;AACD;;AAnEoB;;;;;;;;;;;;;;;AAuEhB,YAAMC,oBAAN,SAAmC3C,gBAAnC,CAAoD;;AAEzD8B,iBAASH,UAAT,EAAqB;AACnB,iBAAOA,WAAWQ,OAAX,CAAmBS,YAA1B;AACD;;AAJwD;;;;;;;;;;;;;;;;;;AAQpD,YAAMC,mBAAN,SAAkC7C,gBAAlC,CAAmD;;AAExD8B,iBAASH,UAAT,EAAqB;AACnB,iBAAOA,WAAWQ,OAAX,CAAmBW,gBAA1B;AACD;;AAJuD","file":"individualCanvas.js","sourcesContent":["class IndividualCanvas {\n  \n  constructor(canvas, individuals, pointSize) {\n    this.canvas = canvas\n    this.transform = {\"k\": 1, \"x\": 0, \"y\": 0}\n    this.scale = 1\n    this.individuals = individuals\n    this.pointSize = pointSize\n    this.constPointSize = this.pointSize\n    this.context = canvas.getContext(\"2d\")\n  }\n  \n  setIndividuals(individuals) {\n    this.individuals = individuals\n  }\n  \n  updateScale(scale) {\n    this.scale = scale\n    this.updatePointSize()\n  }\n  \n  updateTransform(transform) {\n    this.transform = transform\n  }\n  \n  updatePointSize() {\n    let threshold = 200\n    // maybe use transform.invert for smaller scales?\n    if (this.scale < (this.constPointSize + threshold)) {\n      this.pointSize = this.constPointSize / this.scale\n    } else if ((this.constPointSize + threshold) <= this.scale) {\n      this.pointSize = this.constPointSize / (this.constPointSize + threshold)\n    }\n  }\n  \n  clear() {\n    this.context.clearRect(0, 0, this.canvas.width, this.canvas.height)\n  }\n  \n  draw() {\n    this.context.save()\n    this.clear()\n    this.context.translate(this.transform.x, this.transform.y)\n    this.context.scale(this.scale, this.scale)\n    this.drawIndividuals()\n    this.context.restore()\n  }\n  \n  drawIndividuals() {\n    this.individuals.forEach((individual) => {\n      this.drawPixel(individual)\n    })\n  }\n  \n  drawPixel(individual) {\n    let color = this.getColor(individual)\n    let r = color.r\n    let g = color.g\n    let b = color.b\n    let opacity = color.opacity\n    let x = individual.drawing.position.x\n    let y = individual.drawing.position.y\n    \n    this.context.beginPath()\n    this.context.arc(x, y, this.pointSize/2, 0, 2 * Math.PI)\n    this.context.fillStyle = \"rgba(\"+ r +\",\"+ g +\",\"+ b +\",\"+ opacity +\")\"\n    this.context.fill()\n  }\n  \n}\n\nexport class DefaultColoredCanvas extends IndividualCanvas {\n  \n  getColor(individual) {\n    return individual.drawing.currentColor\n  }\n  \n}\n\nexport class UniqueColoredCanvas extends IndividualCanvas {\n\n  getColor(individual) {\n    return individual.drawing.identifyingColor\n  }\n  \n}"]}