Skip to content

Commit

Permalink
Implement fade in wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
tomassedovic committed Dec 20, 2017
1 parent 08b2ee5 commit 4eff11c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion dose-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
}

Expand Down

0 comments on commit 4eff11c

Please sign in to comment.