Permalink
Browse files

Implement fade in wasm

  • Loading branch information...
tomassedovic committed Dec 20, 2017
1 parent 08b2ee5 commit 4eff11c4f1a6a644603401f6c2fd6dc31543eafe
Showing with 20 additions and 2 deletions.
  1. +7 −1 dose-response.js
  2. +13 −1 src/main.rs
@@ -138,7 +138,13 @@ fetch('target/wasm32-unknown-unknown/release/dose-response.wasm')
let g = memory[i + 4];
let b = memory[i + 5];

if(glyph === null) {
// NOTE: (255, 255) position means fade
if(x == 255 && y == 255) {
// NOTE: alpha is stored in the glyph position
let alpha = memory[i + 2] / 255; // convert the "alpha" to <0, 1>
ctx.fillStyle = `rgba(${r}, ${g}, ${b}, ${alpha})`;
ctx.fillRect(0, 0, width * squareSize, height * squareSize);
} else if(glyph === null) {
ctx.fillStyle = `rgb(${r},${g},${b})`;
ctx.fillRect(x * squareSize, y * squareSize, squareSize, squareSize);
} else {
@@ -464,7 +464,19 @@ pub fn update(state_ptr: *mut State) {
js_drawcalls.push(color.b);
}

_ => {} // TODO
&engine::Draw::Fade(fade, color) => {
assert!(fade >= 0.0);
assert!(fade <= 1.0);
// NOTE: (255, 255) position means fade
js_drawcalls.push(255);
js_drawcalls.push(255);
// NOTE: fade value/alpha is stored in the glyph
js_drawcalls.push(((1.0 - fade) * 255.0) as u8);
js_drawcalls.push(color.r);
js_drawcalls.push(color.g);
js_drawcalls.push(color.b);
}

}
}

0 comments on commit 4eff11c

Please sign in to comment.