-
Notifications
You must be signed in to change notification settings - Fork 256
add wasm-backend using HTML canvas element #741
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
Open
genieCS
wants to merge
19
commits into
gyscos:main
Choose a base branch
from
genieCS:main
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.
Open
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e219ed8
add wasm-backend using HTML canvas element(#1)
genieCS 5db16fc
add wasm-backend
genieCS 491bc17
fix event handling (#3)
genieCS 2ca849d
remove buffering in js
genieCS 327b52b
adjust font size
genieCS fe6b6c5
separate async feature from wasm
genieCS 10964f1
empty default config
genieCS bea24fb
fix canvas size
genieCS bc15a01
fix default and remove getrandom
genieCS fb8f22c
add wasm initializer with canvas
genieCS 6980b4c
fix wasm canvas size
genieCS 55de09c
Add support for the different keys in the WASM backend
genieCS e15fe30
implement clear for WASM backend
genieCS 7a5c925
fix errors
genieCS 379227a
fix width and height
genieCS 040d6a6
fix font size
genieCS 12d7dca
wrap writer logic on wasm backend
genieCS c23b043
make run as async
genieCS 1747b21
fix doc-tests
genieCS 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
const fontWidth = 12; | ||
const fontHeight = fontWidth * 2; | ||
const textColorPairSize = 12; | ||
|
||
export function paint(buffer) { | ||
// console.time('paint'); | ||
genieCS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const data = new Uint8Array(buffer); | ||
const canvas = document.getElementById('cursive-wasm-canvas'); | ||
const context = canvas.getContext('2d'); | ||
context.font = `${fontHeight - 2}px monospace`; | ||
for (let x = 0; x < 1000; x++) { | ||
for (let y = 0; y < 1000; y++) { | ||
const n = 1000 * y + x; | ||
const textColorPair = data.slice(n * textColorPairSize, (n + 1) * textColorPairSize); | ||
const text = String.fromCharCode(textColorPair[0] + (2**8) *textColorPair[1] + (2**16)* textColorPair[2] + (2 ** 24) + textColorPair[3]); | ||
const front = byte_to_hex_string(textColorPair.slice(4, 7)); | ||
const back = byte_to_hex_string(textColorPair.slice(7, 10)); | ||
context.fillStyle = back; | ||
context.fillRect(x * fontWidth, y * fontHeight, fontWidth, fontHeight); | ||
if (text != ' ') { | ||
context.fillStyle = front; | ||
context.fillText(text, x * fontWidth, (y + 0.8) * fontHeight); | ||
} | ||
} | ||
} | ||
// console.timeEnd('paint'); | ||
genieCS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
function byte_to_hex_string(bytes) { | ||
const red = bytes[0].toString(16).padStart(2, '0'); | ||
const green = bytes[1].toString(16).padStart(2, '0'); | ||
const blue = bytes[2].toString(16).padStart(2, '0'); | ||
return `#${red}${green}${blue}`; | ||
} |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.