Skip to content

Instantly share code, notes, and snippets.

@patientplatypus
Created October 17, 2019 20:49
Show Gist options
  • Save patientplatypus/ebd08545e8b3ea490138ae3221d74971 to your computer and use it in GitHub Desktop.
Save patientplatypus/ebd08545e8b3ea490138ae3221d74971 to your computer and use it in GitHub Desktop.
//this is borked
//specifically this.state.wasm.handle_mouse_down_stroke is getting back a Uint8ClampedArray which I can console.log
//unfortunately adding this data to canvas using
let newWASMclamped = Uint8ClampedArray.from(newWASM);
var imgData = new ImageData(newWASMclamped, this.canvasRefWASM.current.width, this.canvasRefWASM.current.height)
this.ctxWASM.putImageData(imgData, 0, 0);
//isnt working.
//on the other hand the this.state.wasm.handle_mouse_down_spray function *is* working.
//why?
mouseDown = () => {
console.log("5235235235235226663456 value of this.state.strokeType: ", this.state.strokeType, " and value of strokeSize: ", this.state.strokeSize);
const update = () => {
if(this.dragArray.length>0){
let lastVal = this.dragArray.pop();
if(this.state.sprayImg!=''){
var newWASM = this.state.wasm.handle_mouse_down_spray(
this.state.sprayImg.width,
this.state.sprayImg.height,
this.canvasRefWASM.current.width,
this.canvasRefWASM.current.height,
lastVal.x,
lastVal.y,
this.state.sprayImg.data);
}
if(this.state.strokeType!='' && this.state.strokeSize>0){
console.log("5235235235235226663456 INSIDE IF");
let colorVec = [this.state.RGBA.r, this.state.RGBA.g, this.state.RGBA.b, this.state.RGBA.a];
var newWASM = this.state.wasm.handle_mouse_down_stroke(
this.state.strokeType,
this.state.strokeSize,
colorVec,
this.canvasRefWASM.current.width,
this.canvasRefWASM.current.height,
lastVal.x,
lastVal.y
);
}
console.log("2035023750235970573092570 VALUE OF NEWWASM: ", newWASM)
let newWASMclamped = Uint8ClampedArray.from(newWASM);
var imgData = new ImageData(newWASMclamped, this.canvasRefWASM.current.width, this.canvasRefWASM.current.height)
this.ctxWASM.putImageData(imgData, 0, 0);
requestAnimationFrame(update);
}
}
update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment