From 37250e2344a8630b8389ac4e60d12fa115a9dfaf Mon Sep 17 00:00:00 2001 From: Moon <108756201+LifeAdventurer@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:29:34 +0800 Subject: [PATCH] Add files via upload --- luck_generator/matrix.js | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 luck_generator/matrix.js diff --git a/luck_generator/matrix.js b/luck_generator/matrix.js new file mode 100644 index 0000000..ec0b4c6 --- /dev/null +++ b/luck_generator/matrix.js @@ -0,0 +1,46 @@ +const canvas = document.getElementById("Matrix") +const context = canvas.getContext("2d") + +canvas.height = window.innerHeight +canvas.width = window.innerWidth + +const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./*-+#$%^@!~?><:;[]{}\」=_αβΓγΔδεζηΘθικΛλμΞξΠπρΣσςτυΦφχΨψΩω×≦≧≠∞≒≡~∩∠∪∟⊿∫∮∵∴$¥〒¢£℃€℉╩◢ⅩⅨⅧⅦⅥⅤⅣⅢⅡⅠあいうえおがぎぐげござじずぜぞだぢつでづどにぬのばひぴぶへぺぼみゃょァゐゎè"; + +const fontSize = 16; +const columns = canvas.width / fontSize; + +const charArr = []; +for(let i = 0; i < columns; ++i) { + charArr[i] = 1; +} + +let frame = 0; +let str; + +function Update() { + context.fillStyle = "rgba(0, 0, 0, 0.05)"; + context.fillRect(0, 0, canvas.width, canvas.height); + if(frame == 0){ + let a = parseInt(Math.random() * 255); + str = `rgba(${a}, ${Math.abs(a - 127)}, ${Math.abs(a - 255)}, 0.9)`; + } + context.fillStyle = str; + context.font = fontSize + "px monospace"; + + for(let i = 0; i < columns; ++i){ + const text = chars[Math.floor(Math.random() * chars.length)]; + context.fillText(text, i * fontSize, charArr[i] * fontSize); + if(charArr[i] * fontSize > canvas.height && Math.random() > 0.90){ + charArr[i] = 0; + } + charArr[i]++; + } + frame++; + if(frame <= 40 * (Math.floor(Math.random() * 10) + 3)) requestAnimationFrame(Update); // 40 frames a cycle + else{ + frame = 0; + Appear(); + } +} + +Update(); \ No newline at end of file