Showcase Matrix Rain Program #1003
Replies: 5 comments 1 reply
-
I'm not gonna fix your code, if you want me to work for you, you can pay for paid support. Unless you have an issue with the library. |
Beta Was this translation helpful? Give feedback.
-
Sorry I didn't mean it like that. I believe that a showcase piece for jquery terminal is a good matrix rain code program. I'm not saying it has to be a part of the library but it would nice for the community to have so i posted here on discussions. I have made further progress with it, sadly this isnt complete code this time as I'm using another library with jquery terminal to have programs that can parse arguments and print help files. I got fullscreen working, but for some reason term.cols() and term.rows() is not working in this new version and I have to divide it to keep it from printing too many columns and rows. let cols = 60;
if (this.program.opts().columns)
cols = parseInt(this.program.opts().columns);
let rows = 30;
if (this.program.opts().rows)
rows = parseInt(this.program.opts().rows);
let interval = 1;
if (this.program.opts().interval)
interval = parseInt(this.program.opts().interval);
let minInterval = 5
if(interval < minInterval)
interval = minInterval;
let colour = "#B8E986";
if(this.program.opts().colour)
colour = ensureHexColor(this.program.opts().colour, colour);
if (this.program.opts().fullscreen) {
fullScreen = true;
cols = parseInt( term.cols() /2.4 );
rows = parseInt(term.rows()/1.35- 1); // Subtract 1 to avoid scrolling
}
if (cols < 1 || rows < 1) {
term.error('Invalid dimensions. Columns and rows must be greater than 0.');
return 1;
}
let lineMin = Math.max(1, Math.min(3, Math.floor(rows / 10)));
let lineMax = Math.max(lineMin + 1, Math.min(Math.floor(rows / 2), rows - 1));
const lineLengths = Array.from({length: cols}, () =>
Math.floor(Math.random() * (lineMax - lineMin + 1)) + lineMin
);
const lines = Array.from({length: cols}, () => Math.floor(Math.random() * rows));
function getRandomCharacter() {
const katakanaStart = 0x30A0;
const katakanaEnd = 0x30FF;
return String.fromCharCode(
Math.floor(Math.random() * (katakanaEnd - katakanaStart + 1)) + katakanaStart
);
}
function drawMatrix() {
if (fullScreen) {
cols = parseInt( term.cols() /2.4 );
rows = parseInt(term.rows()/1.35- 1); // Subtract 1 to avoid scrolling
}
const frame = Array.from({length: rows}, () => Array(cols).fill("\u3000"));
for (let x = 0; x < cols; x++) {
for (let i = 0; i < lineLengths[x]; i++) {
const row = (lines[x] + i) % rows;
frame[row][x] = getRandomCharacter();
}
lines[x] = (lines[x] + 1) % rows;
}
term.clear();
frame.forEach(line => {
const trimmedLine = line.slice(0, cols).join(''); // Limit to `cols` characters
const formattedLine = `<span style="color:`+colour+`;">${trimmedLine}</span>`;
term.echo(formattedLine, { raw: true });
});
if (typeof term === 'undefined' || !term) {
clearInterval(matrixInterval);
}
}
let matrixInterval = setInterval(drawMatrix.bind(fullScreen), interval);
term.pause(true);
return 0; Edit: because of the default styling of jquery terminal it looks better with no line spacing; <style>
html, body {
margin: 0;
padding: 0;
height: 100%;
background-color: black;
overflow: hidden;
}
#terminal {
width: 100%;
height: 100%;
font-family: monospace;
font-size: 16px; /* Adjust as needed */
line-height: 1; /* Ensures no extra vertical spacing */
letter-spacing: 0; /* Ensures no extra horizontal spacing */
}
</style>
``` |
Beta Was this translation helpful? Give feedback.
-
I'm really pleased that jquery terminal is performing well with this program, the gif looks slow but it's actually very fast |
Beta Was this translation helpful? Give feedback.
-
Here is a matrix code program, see if you can improve it
Beta Was this translation helpful? Give feedback.
All reactions