-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Webassembly #1056
Draft
sakex
wants to merge
28
commits into
main
Choose a base branch
from
webassembly
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[WIP] Webassembly #1056
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
964a0d6
rust-wasm-template
sakex b989324
WASM intro
sakex b0ce243
load-wasm-module
sakex 7d20945
expose-method
sakex fdf8386
expose-rust-type
sakex d4f4ff3
Fix summary indentation
sakex 39ae389
import-method
sakex 7d411b7
web-sys
sakex 4f8bc90
error-handling.md
sakex 8063357
improve CSS
sakex 13af224
import-js-type
sakex f7d791f
async.md
sakex 9b00ca4
remove log from async.md
sakex bee0f95
limitations/borrow-checker.md
sakex a87c286
limitations
sakex abfe08c
update-deps
sakex 46c5a44
Fix import in async.md
9f724d4
Use generic server
sakex afbd29e
closures.md
sakex 449ac4d
camera.md
sakex 360b43e
Bonus exercise for camera
sakex 771e41c
Clearer instructions in camera.md
sakex 6f94c9e
game-of-life.md
sakex 37ebf83
Add dependencies to async.md
sakex 5cb15f1
Fix formatting errors and remove font
sakex d7579d7
WASM -> Wasm
sakex 62200ff
More concise class
sakex 59fa8cc
Fix GOL setup
sakex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"image": "mcr.microsoft.com/devcontainers/rust:0-1-bullseye", | ||
// Configure tool-specific properties. | ||
"customizations": { | ||
// Configure properties specific to VS Code. | ||
"vscode": { | ||
"settings": {}, | ||
"extensions": [ | ||
"streetsidesoftware.code-spell-checker" | ||
] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Camera | ||
|
||
In this exercise we will play with the camera in real time. | ||
|
||
Serve the web server and navigate to [http://localhost:8000/exercises/camera/](http://localhost:8000/exercises/camera/). | ||
|
||
You will edit [lib.rs](../../rust-wasm-template/lib.rs) as usual. | ||
|
||
Here is the basic code you will need: | ||
|
||
```rust | ||
extern crate console_error_panic_hook; | ||
|
||
use js_sys::Uint8ClampedArray; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
fn alert(s: &str); | ||
|
||
#[wasm_bindgen(js_namespace = console)] | ||
pub fn log(s: &str); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn setup() { | ||
console_error_panic_hook::set_once(); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn edit_bitmap(image_data: &Uint8ClampedArray, width: u32, height: u32) { | ||
} | ||
|
||
``` | ||
|
||
We want to edit the function `edit_bitmap`. `image_data` is a reference to the [Uint8ClampedArray](https://rustwasm.github.io/wasm-bindgen/api/js_sys/struct.Uint8ClampedArray.html) being rendered on your screen. `Uint8ClampedArray` is a flat array of unsigned int of `8` bits. | ||
It represents _srgb_ image, which means that each pixel is represented as a vector of 4 elements [red, green, blue, illumination]. | ||
The image can be thought of as a matrix of dimension `(width, height, 4)`, it is row-major. | ||
|
||
We will reuse our different implementations. So do not erase them when going from one exercise to the next. | ||
|
||
First off let's implement some methods that modify the video live: | ||
|
||
1. Paint the top half the image to black. | ||
2. Paint the left half of the image to white. | ||
3. Create an X-ray effect. This is done by mapping colors to their opposite, for instance `0<->255`, `100<->155`. Beware of illumination. | ||
4. _Bonus question:_ Now feel free to implement other transformations such as _greyscale_ or adding _random noise_. | ||
5. Let's now add functionalities to our page. In the _setup_ function create a dropdown (`<select>`) that will change which transformation to apply to the image. | ||
6. _Bonus question:_ Track moving objects. This can be done by figuring out only the pixels that didn't change between multiple frames. For instance, you could compute the standard deviation of the pixel and black out below a threshold. | ||
While this can be achieved without touching Javascript, I recommend editing it. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update
dprint.json
to include the new files undersrc/exercises/webassembly/
andsrc/webassembly/
? That way we can ensure they're formatted in a consistent way!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I don't know how to do this, do you have an example?