feat: Change matrix
- Show characters - Stop using observer
This commit is contained in:
parent
87bea40776
commit
a962046183
1 changed files with 21 additions and 11 deletions
|
|
@ -35,13 +35,19 @@ tags:
|
|||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
const canvas = document.getElementById("canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
const observer = new ResizeObserver(() => {
|
||||
canvas.width = canvas.clientWidth;
|
||||
canvas.height = canvas.clientHeight;
|
||||
console.log("resize");
|
||||
});
|
||||
// const observer = new ResizeObserver(() => {
|
||||
// canvas.width = canvas.clientWidth;
|
||||
// canvas.height = canvas.clientHeight;
|
||||
// console.log("resize");
|
||||
// });
|
||||
|
||||
canvas.width = canvas.clientWidth;
|
||||
canvas.height = canvas.clientHeight;
|
||||
|
||||
// observer.observe(canvas);
|
||||
|
||||
ctx.font = "24px 'Courier New', Courier, monospace";
|
||||
ctx.textBaseline = "top";
|
||||
|
||||
let char = characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
let charMeasure = ctx.measureText(char);
|
||||
|
|
@ -51,8 +57,8 @@ tags:
|
|||
text: char,
|
||||
x: 0,
|
||||
y: 0,
|
||||
w: 13,
|
||||
h: 24
|
||||
w: charH,
|
||||
h: charH
|
||||
}
|
||||
let lane = [];
|
||||
let max = Math.floor(canvas.clientHeight / glyph.h);
|
||||
|
|
@ -69,8 +75,6 @@ tags:
|
|||
console.log("init", newInterval);
|
||||
console.log(glyph);
|
||||
|
||||
observer.observe(canvas);
|
||||
|
||||
newId = setInterval(newTrail, newInterval);
|
||||
|
||||
function newTrail() {
|
||||
|
|
@ -83,12 +87,18 @@ tags:
|
|||
|
||||
ctx.fillStyle = "white";
|
||||
ctx.fillRect(glyph.x, glyph.y, glyph.w, glyph.h);
|
||||
// ctx.fillText(glyph.text, glyph.x, glyph.y + glyph.h);
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillText(glyph.text, Math.floor((charH - charW) / 2), glyph.y);
|
||||
|
||||
if (newIndex > 0) {
|
||||
let prevY = glyph.y - glyph.h;
|
||||
ctx.fillStyle = "rgba(0, 0, 0, " + randomBetween(.6, 1) + ")";
|
||||
let alpha = randomBetween(.2, 1);
|
||||
ctx.clearRect(glyph.x, prevY, glyph.w, glyph.h);
|
||||
ctx.fillStyle = "rgba(0, 0, 0, " + alpha + ")";
|
||||
ctx.fillRect(glyph.x, prevY, glyph.w, glyph.h);
|
||||
ctx.fillStyle = "rgba(255, 255, 255, " + alpha + ")";
|
||||
// TODO: can not use array lane if it is changed by cleanTrail()
|
||||
ctx.fillText(lane[newIndex - 1][1], Math.floor((charH - charW) / 2), prevY);
|
||||
}
|
||||
|
||||
if (newIndex === cleanIndex) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue