-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nerin3
committed
Jun 13, 2023
1 parent
449f06e
commit 51a58e7
Showing
8 changed files
with
274 additions
and
143 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,49 @@ | ||
// Get the canvas node and the drawing context | ||
const canvas = document.getElementById('canvas'); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
// set the width and height of the canvas | ||
const w = canvas.width = document.body.offsetWidth; | ||
const h = canvas.height = document.body.offsetHeight; | ||
|
||
// draw a black rectangle of width and height same as that of the canvas | ||
ctx.fillStyle = '#0000'; | ||
ctx.fillRect(0, 0, w, h); | ||
|
||
const cols = Math.floor(w / 10) + 1; | ||
const ypos = Array(cols).fill(0); | ||
|
||
function matrix () { | ||
// Draw a semitransparent black rectangle on top of previous drawing | ||
ctx.fillStyle = '#0001'; | ||
ctx.globalCompositeOperation = 'destination-out'; | ||
ctx.fillRect(0, 0, w, h); | ||
ctx.fillStyle = '#0005'; | ||
ctx.globalCompositeOperation = 'xor'; | ||
ctx.fillRect(0, 0, w, h); | ||
|
||
// Set color to green and font to 15pt pixelSGA in the drawing context | ||
ctx.fillStyle = '#8c5dca'; | ||
ctx.font = '10px PixelSGA'; | ||
|
||
// for each column put a random character at the end | ||
ypos.forEach((y, ind) => { | ||
// generate a random character | ||
const text = String.fromCharCode(0x0041 + Math.random() * (0x005A - 0x0041 + 1)); | ||
|
||
// x coordinate of the column, y coordinate is already given | ||
const x = ind * 10; | ||
// render the character at (x, y) | ||
ctx.globalCompositeOperation = 'source-over'; | ||
ctx.fillText(text, x, y); | ||
|
||
|
||
// randomly reset the end of the column if it's at least 100px high | ||
if (y > 300 + Math.random() * 10000) ypos[ind] = 0; | ||
// otherwise just move the y coordinate for the column 20px down, | ||
else ypos[ind] = y + 10; | ||
}); | ||
} | ||
|
||
// render the animation at 20 FPS. | ||
setInterval(matrix, 50); |
Oops, something went wrong.