Skip to content

Commit f295747

Browse files
committed
feat: fine tuning of flake speeds
1 parent 5005081 commit f295747

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

octoprint_wrapped/static/js/wrapped.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
$(function () {
88
const FLAKES = 50;
9+
const MIN_DURATION = 5;
10+
const MAX_DURATION = 15;
911

1012
const MONTH_DECEMBER = 11;
1113
const MONTH_JANUARY = 0;
@@ -113,6 +115,8 @@ $(function () {
113115
container = document.createElement("div");
114116
container.id = "snow";
115117
container.dataset.count = FLAKES;
118+
container.dataset.durmin = MIN_DURATION;
119+
container.dataset.durmax = MAX_DURATION;
116120
body.insertBefore(container, body.firstChild);
117121

118122
const styleSnow = document.createElement("link");
@@ -128,7 +132,7 @@ $(function () {
128132
scriptSnow.onload = () => {
129133
setTimeout(() => {
130134
createSnow();
131-
showSnow(true);
135+
if (showSnow !== undefined) showSnow(true);
132136
}, 500);
133137
};
134138
head.appendChild(scriptSnow);

octoprint_wrapped/static/pure-snow/pure-snow.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
let snowflakesCount = 200; // Snowflake count, can be overwritten by attrs
2+
let minDuration = 10; // can be overwritten by attrs
3+
let maxDuration = 30; // can be overwritten by attrs
24
let baseCSS = ``;
35

46
// set global attributes
57
if (typeof SNOWFLAKES_COUNT !== "undefined") {
68
snowflakesCount = SNOWFLAKES_COUNT;
79
}
10+
if (typeof SNOWFLAKES_MIN_DURATION !== "undefined") {
11+
minDuration = SNOWFLAKES_MIN_DURATION;
12+
}
13+
if (typeof SNOWFLAKES_MAX_DURATION !== "undefined") {
14+
maxDuration = SNOWFLAKES_MAX_DURATION;
15+
}
816
if (typeof BASE_CSS !== "undefined") {
917
baseCSS = BASE_CSS;
1018
}
@@ -21,6 +29,8 @@ function setHeightVariables() {
2129
function getSnowAttributes() {
2230
const snowWrapper = document.getElementById("snow");
2331
snowflakesCount = Number(snowWrapper?.dataset?.count || snowflakesCount);
32+
minDuration = Number(snowWrapper?.dataset?.durmin || minDuration);
33+
maxDuration = Number(snowWrapper?.dataset?.durmax || maxDuration);
2434
}
2535

2636
// This function allows you to turn on and off the snow
@@ -89,7 +99,10 @@ function generateSnowCSS(snowDensity = 200) {
8999
let randomYoyoTime = getRandomArbitrary(0.3, 0.8);
90100
let randomYoyoY = randomYoyoTime * pageHeightVh; // vh
91101
let randomScale = Math.random();
92-
let fallDuration = randomIntRange(10, (pageHeightVh / 10) * 3); // s
102+
let fallDuration = Math.min(
103+
randomIntRange(minDuration, (pageHeightVh / 10) * 3),
104+
maxDuration
105+
); // s
93106
let fallDelay = randomInt((pageHeightVh / 10) * 3) * -1; // s
94107
let opacity = Math.random();
95108

0 commit comments

Comments
 (0)