Skip to content

Commit

Permalink
cleaned up code
Browse files Browse the repository at this point in the history
merged drop_chars var into drops
added vsCode markers for better navigation through code
  • Loading branch information
IPdotSetAF committed Apr 11, 2024
1 parent c507786 commit 43174ad
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 65 deletions.
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,33 @@ This is a highly customizable animated Matrix wallpaper for Wallpaper Engine (We
- Logo Customization
- Logo
- None
- 23 presets

<p align="left">
<img src="images/ipaf.svg" alt="IP.AF" width=40px/>
<img src="images/kali-1.svg" alt="Kali Linux" width=40px/>
<img src="images/kali-2.svg" alt="Kali Linux" width=40px/>
<img src="images/ubuntu-1.svg" alt="Ubuntu Linux" width=40px/>
<img src="images/ubuntu-2.svg" alt="Ubuntu Linux" width=40px/>
<img src="images/windows-11.svg" alt="Windows 11" width=40px/>
<img src="images/windows-10-8.svg" alt="Windows 10/8" width=40px/>
<img src="images/windows-7.svg" alt="Windows 7" width=40px/>
<img src="images/visual-studio.svg" alt="Visual Studio" width=40px/>
<img src="images/vs-code.svg" alt="VS Code" width=40px/>
<img src="images/unity-1.svg" alt="Unity Engine" width=40px/>
<img src="images/unity-2.svg" alt="Unity Engine" width=40px/>
<img src="images/unreal.svg" alt="Unreal Engine" width=40px/>
<img src="images/python.svg" alt="Python" width=40px/>
<img src="images/blazor.svg" alt="Blazor" width=40px/>
<img src="images/docker.svg" alt="Docker" width=40px/>
<img src="images/flutter.svg" alt="Flutter" width=40px/>
<img src="images/git.svg" alt="Git" width=40px/>
<img src="images/blender.svg" alt="Blender" width=40px/>
<img src="images/angular.svg" alt="Angular" width=40px/>
<img src="images/c-sharp.svg" alt="C#" width=40px/>
<img src="images/c-plus-plus.svg" alt="C++" width=40px/>
<img src="images/qt.svg" alt="QT" width=40px/>
</p>
- 23 presets :

<p align="left">
<img src="images/ipaf.svg" alt="IP.AF" width=40px/>
<img src="images/kali-1.svg" alt="Kali Linux" width=40px/>
<img src="images/kali-2.svg" alt="Kali Linux" width=40px/>
<img src="images/ubuntu-1.svg" alt="Ubuntu Linux" width=40px/>
<img src="images/ubuntu-2.svg" alt="Ubuntu Linux" width=40px/>
<img src="images/windows-11.svg" alt="Windows 11" width=40px/>
<img src="images/windows-10-8.svg" alt="Windows 10/8" width=40px/>
<img src="images/windows-7.svg" alt="Windows 7" width=40px/>
<img src="images/visual-studio.svg" alt="Visual Studio" width=40px/>
<img src="images/vs-code.svg" alt="VS Code" width=40px/>
<img src="images/unity-1.svg" alt="Unity Engine" width=40px/>
<img src="images/unity-2.svg" alt="Unity Engine" width=40px/>
<img src="images/unreal.svg" alt="Unreal Engine" width=40px/>
<img src="images/python.svg" alt="Python" width=40px/>
<img src="images/blazor.svg" alt="Blazor" width=40px/>
<img src="images/docker.svg" alt="Docker" width=40px/>
<img src="images/flutter.svg" alt="Flutter" width=40px/>
<img src="images/git.svg" alt="Git" width=40px/>
<img src="images/blender.svg" alt="Blender" width=40px/>
<img src="images/angular.svg" alt="Angular" width=40px/>
<img src="images/c-sharp.svg" alt="C#" width=40px/>
<img src="images/c-plus-plus.svg" alt="C++" width=40px/>
<img src="images/qt.svg" alt="QT" width=40px/>
</p>

- CUSTOM
- Preserve Logo Color
Expand Down
85 changes: 47 additions & 38 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
window.onload = function () {
//MARK: Update
const version = "v4.3.0";

checkForUpdates = async () => {
Expand All @@ -12,13 +13,7 @@ window.onload = function () {
return await fetch('project.json').then(_ => _.json());
}

function optionsToDict(options) {
return options.reduce((acc, option) => {
acc[option.label] = option.value;
return acc;
}, {});
}

//MARK: Options
var gui;
var options = {
ui_rain_matrixSpeed: 24,
Expand Down Expand Up @@ -85,6 +80,7 @@ window.onload = function () {
else
drawGui();

//MARK: GUI
function drawGui() {
readProjectConfig().then((config) => {
gui = new lil.GUI({ autoPlace: false, width: 300 });
Expand All @@ -97,7 +93,7 @@ window.onload = function () {
options.trailLength = calculateTrailLength(options.ui_rain_trailLength);
updateMask();
});
rainFolder.add(options, "ui_rain_initialAnimation", optionsToDict(config.general.properties.ui_rain_initialanimation.options)).name("Initial Animation").onChange(fallAnimation);
rainFolder.add(options, "ui_rain_initialAnimation", optionsToDict(config.general.properties.ui_rain_initialanimation.options)).name("Initial Animation").onChange(initialAnimation);

const colorFolder = gui.addFolder("Color");
colorFolder.add(options, 'ui_color_colorMode', optionsToDict(config.general.properties.ui_color_colormode.options)).name('Color Mode');
Expand Down Expand Up @@ -155,7 +151,7 @@ window.onload = function () {
const otherFolder = gui.addFolder("Other");
otherFolder.add(options, 'ui_other_codesCommaSeparated').name('Codes (Comma separated)').onChange(() => {
options.codes = makeCodes(options.ui_other_codesCommaSeparated);
fallAnimation();
initialAnimation();
});

gui.add(options, "Save");
Expand All @@ -169,6 +165,7 @@ window.onload = function () {
});
}

//MARK: Wallpaper Engine
window.wallpaperPropertyListener = {
applyUserProperties: function (properties) {
if (properties.ui_rain_matrixspeed)
Expand All @@ -179,7 +176,7 @@ window.onload = function () {
}
if (properties.ui_rain_initialanimation) {
options.ui_rain_initialAnimation = properties.ui_rain_initialanimation.value;
fallAnimation();
initialAnimation();
}

if (properties.ui_color_colormode)
Expand Down Expand Up @@ -265,7 +262,7 @@ window.onload = function () {

if (properties.ui_other_codescommaseparated) {
options.codes = makeCodes(properties.ui_other_codescommaseparated.value);
fallAnimation();
initialAnimation();
}
}
};
Expand All @@ -275,15 +272,10 @@ window.onload = function () {
updateMask();
updateFont();
updateGrid();
fallAnimation();
initialAnimation();
}, false);

setInterval(() => {
updateTime();
if (options.ui_clock_clock != "0")
updateMask();
}, 60000);

//MARK: Variables
var fonts = ["monospace", "consolas", "courier-bold", "neo-matrix"];
var charsets = [
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
Expand All @@ -297,7 +289,7 @@ window.onload = function () {
var logo = null, logos = ["ipaf", "kali-1", "kali-2", "ubuntu-1", "ubuntu-2", "windows-11", "windows-10-8", "windows-7", "visual-studio", "vs-code", "unity-1", "unity-2", "unreal", "python", "blazor", "docker", "flutter", "git", "blender", "angular", "c-sharp", "c-plus-plus", "qt"];
var debug = document.getElementById("debug"), logs = [];
var hour = "", minute = "";
var startTime, now, then, elapsed, letters, columns, rows, drops, drop_chars;
var startTime, now, then, elapsed, letters, columns, rows, drops;
var AudioTimeout = false, LastSoundTime = new Date(), isSilent = false, frequencyArray, frequencyArrayLength = 128, column_frequency;
var column_hue, row_hue;
var font_fraction;
Expand All @@ -323,6 +315,7 @@ window.onload = function () {
colorOverlayDom.width = window.innerWidth;
}

//MARK: Logo
function updateLogo() {
logo = new Image();
logo.onload = updateMask;
Expand All @@ -343,6 +336,13 @@ window.onload = function () {
}
}

//MARK: Time
setInterval(() => {
updateTime();
if (options.ui_clock_clock != "0")
updateMask();
}, 60000);

function updateTime() {
let today = new Date();
hour = today.getHours();
Expand All @@ -365,6 +365,7 @@ window.onload = function () {
minute = "0" + minute;
}

//MARK: Mask
function updateMask() {
mask.globalCompositeOperation = 'source-over';
mask.clearRect(0, 0, neoMatrixDom.width, neoMatrixDom.height);
Expand Down Expand Up @@ -425,6 +426,7 @@ window.onload = function () {
}
}

//MARK: Charset
function updateCharSet() {
if (options.ui_characters_charset == "0")
letters = options.ui_characters_customCharset;
Expand All @@ -434,6 +436,7 @@ window.onload = function () {
letters = letters.split("");
}

//MARK: Font
function updateFont() {
var font_name;

Expand All @@ -447,9 +450,10 @@ window.onload = function () {

updateGrid();
updateMask();
fallAnimation();
initialAnimation();
}

//MARK: Grid
function updateGrid() {
columns = neoMatrixDom.width / options.ui_font_size;
rows = neoMatrixDom.height / options.ui_font_size;
Expand All @@ -458,30 +462,24 @@ window.onload = function () {
column_frequency = frequencyArrayLength / (columns * 2);
}

function fallAnimation() {
//MARK: Initial Animation
function initialAnimation() {
drops = [];
drop_chars = [];

switch (options.ui_rain_initialAnimation) {
case "0": {
for (var i = 0; i < columns; i++) {
drops[i] = [rows + 1, 0, 0];
drop_chars[i] = ["", false];
}
for (var i = 0; i < columns; i++)
drops[i] = [rows + 1, 0, 0, "", 0];
break;
}
case "1": {
for (var i = 0; i < columns; i++) {
drops[i] = [1, 0, 0];
drop_chars[i] = ["", false];
}
for (var i = 0; i < columns; i++)
drops[i] = [1, 0, 0, "", 0];
break;
}
case "2": {
for (var i = 0; i < columns; i++) {
drops[i] = [Math.floor(Math.random() * rows), 0, 0];
drop_chars[i] = ["", false];
}
for (var i = 0; i < columns; i++)
drops[i] = [Math.floor(Math.random() * rows), 0, 0, "", 0];
break;
}
}
Expand All @@ -504,6 +502,7 @@ window.onload = function () {
}
}

//MARK: Draw Matrix
function drawMatrix() {
drawMask();
isSilent = true;
Expand Down Expand Up @@ -533,20 +532,20 @@ window.onload = function () {
neoMatrix.clearRect(i * options.ui_font_size, ((drops[i][0] - 2) * options.ui_font_size) + font_fraction, options.ui_font_size, options.ui_font_size);

var tmp = drops[i][0] - 1;
neoMatrix.fillStyle = calculateColor(i, tmp, drop_chars[i][1]);
neoMatrix.fillText(drop_chars[i][0], i * options.ui_font_size, tmp * options.ui_font_size);
neoMatrix.fillStyle = calculateColor(i, tmp, drops[i][4]);
neoMatrix.fillText(drops[i][3], i * options.ui_font_size, tmp * options.ui_font_size);

neoMatrix.fillStyle = "#FFF";
}
else
neoMatrix.fillStyle = calculateColor(i, drops[i][0], lightness);

neoMatrix.clearRect(i * options.ui_font_size, ((drops[i][0] - 1) * options.ui_font_size) + font_fraction, options.ui_font_size, options.ui_font_size);
drop_chars[i] = [character, lightness];
drops[i][3] = character, drops[i][4] = lightness;
neoMatrix.fillText(character, i * options.ui_font_size, drops[i][0] * options.ui_font_size);

if (drops[i][0] > rows && Math.random() > probability)
drops[i] = [0, 0, 0];
drops[i] = [0, 0, 0, "", 0];

drops[i][0]++;
}
Expand All @@ -561,6 +560,7 @@ window.onload = function () {
}
}

//MARK: Calculate Character
function calculateCharacter(dropItem) {

if (Math.random() > 0.995 && dropItem[1] == 0) {
Expand All @@ -579,6 +579,7 @@ window.onload = function () {
return letters[Math.floor(Math.random() * letters.length)];
}

//MARK: Calculate Color
function calculateColor(i, j, lightness) {
var hue, offset = Math.floor(options.colorAnimationSpeed * then);

Expand Down Expand Up @@ -626,6 +627,7 @@ window.onload = function () {
return codes;
}

//MARK: Helpers
function Log(text) {
debug.classList.remove("hide");
void debug.offsetWidth;
Expand Down Expand Up @@ -680,5 +682,12 @@ window.onload = function () {
return max;
return value;
}

function optionsToDict(options) {
return options.reduce((acc, option) => {
acc[option.label] = option.value;
return acc;
}, {});
}
};

0 comments on commit 43174ad

Please sign in to comment.