-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-Hearts.js
85 lines (70 loc) · 2.96 KB
/
MMM-Hearts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Magic Mirror
* Module: MMM-Snow
*
* By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed.
*
* Comment on terminology: a 'flake' is any moving item being shown on the mirror, while
* the specific themed items are called 'snow' or 'heart'. This applies to variable names
* file names and css class names.
*/
Module.register("MMM-Hearts",{
defaults: {
flakeCount: 100,
theme: "love" // pick from themes map below, i.e. winter, love
},
themes: {
"winter" : {
"flakePrefix" : "snow", // prefix of css name, e.g. snow1
"imagesCount" : 3, // number of images available in this theme, here: snow1, snow2, snow3
"downwards" : true, // direction of flake movements, snow goes downwards
"sizeFactor" : 1}, // adapt size of flakes to your liking, use original flake size
"love" : {
"flakePrefix" : "heart", // prefix of css name, e.g. heart1
"imagesCount" : 2, // number of images in this theme, here: heart1, heart2
"downwards" : true, // direction of flake movements, hearts raise upwards
"sizeFactor" : 2}, // adapt size of flakes to your liking, we like bigger hearts
"water" : {
"flakePrefix" : "bubble", // prefix of css name, e.g. bubble1
"imagesCount" : 1, // number of images in this theme, here: bubble1
"downwards" : false, // direction of flake movements, bubbles raise upwards
"sizeFactor" : 2} // adapt size of flakes to your liking, we like bigger bubbles
},
getStyles: function() {
return [ "MMM-Hearts.css" ]
},
getDom: function() {
var themeSettings = this.themes[this.config.theme];
var wrapper = document.createElement("div")
wrapper.className = "wrapper"
var flake, jiggle, size;
for(var i = 0; i < this.config.flakeCount; i++) {
size = themeSettings.sizeFactor * (Math.random() * 0.75) + 0.25;
flakeImage = document.createElement("div")
var flakeSuffix = Math.round(1 + Math.random() * (themeSettings.imagesCount - 1));
flakeImage.className = themeSettings.flakePrefix + flakeSuffix;
flakeImage.style.transform = "scale(" + size +", " + size + ")";
flakeImage.style.opacity = size;
flake = document.createElement("div");
if(themeSettings.downwards) {
flake.className = "flake-downwards";
}
else {
flake.className = "flake-upwards"
}
jiggle = document.createElement("div");
jiggle.style.animationDelay = (Math.random() * 4) + "s";
jiggle.style.animationDuration = ((Math.random() * 30) + 30) + "s";
jiggle.appendChild(flakeImage);
size = (Math.random() * 0.75) + 0.25;
jiggle.style.transform = "scale(" + size +", " + size + ")";
jiggle.style.opacity = size;
flake.appendChild(jiggle);
flake.style.left = ((Math.random() * 100) - 10) + "%";
flake.style.animationDelay = (Math.random() * 100) + "s";
flake.style.animationDuration = 100 - (Math.random() * 50 * size) + "s";
wrapper.appendChild(flake);
}
return wrapper;
}
});