Skip to content

Commit

Permalink
Merge pull request #47 from PRO100BYTE/add-matrix-command
Browse files Browse the repository at this point in the history
Add matrix command
  • Loading branch information
mraliscoder authored Jul 31, 2023
2 parents ce79c60 + 7867946 commit 57b7078
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
68 changes: 68 additions & 0 deletions src/commands/General/matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export default class MatrixCommand {
execute(term, params, directory, setDirectory) {
var canvas = document.createElement("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.position = "absolute";
canvas.style.top = "0";
canvas.style.left = "0";
canvas.style.zIndex = "1";
term.element.appendChild(canvas);
term.writeln("Entering in The Matrix...")

var ctx = canvas.getContext("2d");
var symbols = "01";
var fontSize = 14;
var columns = canvas.width / fontSize;
var drops = [];

for (var i = 0; i < columns; i++) {
drops[i] = Math.floor(Math.random() * canvas.height);
}

function draw() {
ctx.fillStyle = "rgba(0, 0, 0, 0.05)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.font = fontSize + "px monospace";
ctx.fillStyle = "#0F0";

for (var i = 0; i < columns; i++) {
var symbol = symbols[Math.floor(Math.random() * symbols.length)];

ctx.fillText(symbol, i * fontSize, drops[i] * fontSize);

if (Math.random() > 0.99) {
drops[i] = 0;
} else {
drops[i]++;
}
}

requestAnimationFrame(draw);
}
draw();

setTimeout(function() {
function fadeOut() {
canvas.style.opacity -= 0.01;
if (canvas.style.opacity > 0) {
setTimeout(fadeOut, 20);
} else {
term.element.removeChild(canvas);
}
}
fadeOut();
}, 5000);
}

description() {
return "Displays an animation of a binary rain from The Matrix";
}

help(term) {
term.writeln("The matrix command displays an animation of a binary rain from The Matrix on a canvas over the console for 5 seconds.");
term.writeln("The canvas fades out smoothly after the animation.");
term.writeln("To stop the animation earlier, you need to close and reopen the terminal.");
}
}

26 changes: 21 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,31 @@ BrowserFS.configure({
window.path = window.require("path");

setTimeout(() => {
window.fs.writeFileSync(`/temp/host`, window.location.host);
window.fs.writeFileSync(`/temp/language`, window.navigator.language);
window.fs.writeFileSync(`/temp/user-agent`, window.navigator.userAgent);
window.fs.writeFileSync(`/temp/user-agent.json`, JSON.stringify(window.navigator.userAgentData, null, 2));
try {
window.fs.writeFileSync(`/temp/host`, window.location.host);
} catch (e) {
}

try {
window.fs.writeFileSync(`/temp/language`, window.navigator.language);
} catch (e) {
}

try {
window.fs.writeFileSync(`/temp/user-agent`, window.navigator.userAgent);
} catch (e) {
}

try {
window.fs.writeFileSync(`/temp/user-agent.json`, JSON.stringify(window.navigator.userAgentData, null, 2));
} catch (e) {
}


try {
const { downlink, effectiveType, rtt, saveData } = navigator.connection;
window.fs.writeFileSync(`/temp/connection`, JSON.stringify({ downlink, effectiveType, rtt, saveData }, null, 2));
} catch (_) {}
} catch (e) {}
}, 100);

const root = ReactDOM.createRoot(document.getElementById('root'));
Expand Down
2 changes: 2 additions & 0 deletions src/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import StatusCommand from "./commands/System/status";
import AboutmeCommand from "./commands/Utility/aboutme";
import DownloadCommand from "./commands/Filesystem/download";
import UploadCommand from "./commands/Filesystem/upload";
import MatrixCommand from "./commands/General/matrix";
import RebootCommand from "./commands/System/reboot";

export const registerAllCommands = () => {
Expand Down Expand Up @@ -60,6 +61,7 @@ export const registerAllCommands = () => {
registeredCommands['confetti'] = new ConfettiCommand();
registeredCommands['httpcat'] = new HttpcatCommand();
registeredCommands['httpdog'] = new HttpdogCommand();
registeredCommands['matrix'] = new MatrixCommand();

// Utility commands
registeredCommands['echo'] = new EchoCommand();
Expand Down

0 comments on commit 57b7078

Please sign in to comment.