Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
angeldeejay committed Aug 28, 2022
0 parents commit c9233e4
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 0 deletions.
144 changes: 144 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

# End of https://www.toptal.com/developers/gitignore/api/node
10 changes: 10 additions & 0 deletions MMM-MatrixRainBackground.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
*
* {{MODULE_NAME}}
*
* {{AUTHOR_NAME}}
* {{LICENSE}} Licensed.
*
* Custom here your css module
*
*/
125 changes: 125 additions & 0 deletions MMM-MatrixRainBackground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/* global Module */

/* Magic Mirror
* Module: MMM-MatrixRainBackground
*
* By Andrés Vanegas <[email protected]>
* MIT Licensed.
*/

Module.register("MMM-MatrixRainBackground", {
defaults: {
updateInterval: 60000,
fontSize: 32,
speed: 75,
},

requiresVersion: "2.1.0", // Required version of MagicMirror
animationInterval: null,
wrapper: null,
canvas: null,
context: null,
drops: [],
characters: [
'田', '由', '甲', '申', '甴',
'电', '甶', '男', '甸', '甹',
'町', '画', '甼', '甽', '甾',
'甿', '畀', '畁', '畂', '畃',
'畄', '畅', '畆', '畇', '畈',
'畉', '畊', '畋', '界', '畍',
'畎', '畏', '畐', '畑'
],

start: function () {
this.updateDom();
},

initDrops: function () {
this.drops = [];
for (
var columns = Math.ceil(this.canvas.width / this.config.fontSize),
rows = Math.ceil(this.canvas.height / this.config.fontSize),
i = 0;
i < columns;
i++
) {
this.drops[i] = Math.floor(Math.random() * rows) * this.config.fontSize;
}
},

clear: function () {
if (this.animationInterval !== null) {
clearInterval(this.animationInterval);
this.animationInterval = null;
}
for (var el of ['canvas', 'wrapper']) {
if (this[el] !== null) {
try { this[el].parentNode.removeChild(this[el]); }
catch (_) { ; }
finally { this[el] = null; }
}
}
this.context = null;
this.initDrops();
},

getDom: function () {
this.clear();

this.wrapper = document.createElement("div");
this.wrapper.width = '100%';
this.wrapper.height = '100%';
this.wrapper.style.position = 'relative';
this.wrapper.style.width = '100%';
this.wrapper.style.maxWidth = '100%';
this.wrapper.style.minWidth = '100%';
this.wrapper.style.height = '100%';
this.wrapper.style.maxHeight = '100%';
this.wrapper.style.minHeight = '100%';

this.canvas = document.createElement('canvas');
this.canvas.style.position = 'relative';
this.wrapper.appendChild(this.canvas);

this.context = this.canvas.getContext("2d");
this.animate();

return this.wrapper;
},

draw: function () {
this.context.fillStyle = "rgba(0, 0, 0, 0.05)";
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.context.fillStyle = "rgba(135, 180, 15, 0.7)";
this.context.font = this.config.fontSize + "px arial";
this.context.style = "text-align:center !important";
for (var i = 0; i < this.drops.length; i++) {
var character = this.characters[Math.floor(Math.random() * this.characters.length)];
this.context.fillText(character, i * this.config.fontSize, this.drops[i] * this.config.fontSize);
this.drops[i]++;
if (this.drops[i] * this.config.fontSize > c.height && Math.random() > 0.995) {
this.drops[i] = 0;
}
}
},

animate: function () {
if (this.wrapper = null || this.wrapper.offsetParent === null) {
setTimeout(() => this.animate, 100);
return;
}
this.canvas.height = this.wrapper.innerHeight;
this.canvas.width = this.wrapper.innerWidth;

this.animationInterval = setInterval(
() => window.requestAnimationFrame(this.draw),
this.config.speed
);
},

getStyles: function () {
return [
"MMM-MatrixRainBackground.css",
];
},
});
11 changes: 11 additions & 0 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Magic Mirror
* Node Helper: MMM-MatrixRainBackground
*
* By Andrés Vanegas <[email protected]>
* MIT Licensed.
*/

var NodeHelper = require("node_helper");

module.exports = NodeHelper.create({
});
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "MMM-MatrixRainBackground",
"version": "1.0.0",
"description": "MagicMirror module to rain code like The Matrix movie",
"main": "MMM-MatrixRainBackground.js",
"author": "Andrés Vanegas",
"license": "MIT"
}
Empty file added rain.js
Empty file.

0 comments on commit c9233e4

Please sign in to comment.