forked from lynnthegrinch/year-in-pixels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmas.html
196 lines (166 loc) Β· 6.1 KB
/
xmas.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="styles.css">
<title> Year in pixels </title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Delius+Unicase&display=swap" rel="stylesheet">
<link rel='stylesheet' href='https://cdn-uicons.flaticon.com/2.0.0/uicons-regular-rounded/css/uicons-regular-rounded.css'>
<link rel='stylesheet' href='https://cdn-uicons.flaticon.com/2.0.0/uicons-brands/css/uicons-brands.css'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="your mood tracker in pixels">
<meta charset="utf-8">
<meta name="author" content="Valentina Conte">
</head>
<body class="body">
<div class="pyro">
<div class="before"></div>
<div class="after"></div>
</div>
<div id="outerbox">
<h1 class="title">Year in pixels</h1>
<div id="guide">
<div id="moods"></div>
<div id="selectedMood">Today I'm feeling: <span></span></div>
</div>
<div class="content">
<div id="daysHeader"></div>
<div id="tableContainer">
<div id="monthHeader"></div>
<div id="yearContainer"></div>
</div>
</div>
<script>
const COLORS = {
0: { code: "#0a1538", label: "π" },
1: { code: "#ffa600", label: "π" },
2: { code: "#2eb6b0", label: "π" },
3: { code: "#582bc2", label: "π" },
4: { code: "#412f85", label: "π" }
};
const YEAR_CONTAINER = document.getElementById("yearContainer");
const DAYS_HEADER = document.getElementById("daysHeader");
const MONTH_HEADER = document.getElementById("monthHeader");
const GUIDES = document.getElementById("guide");
const SELECTED_MOOD = document.querySelector("#selectedMood span");
const MOODS = document.getElementById("moods");
const MONTH_LETTERS = [
"J",
"F",
"M",
"A",
"M",
"J",
"J",
"A",
"S",
"O",
"N",
"D"
];
let selectedMood = null;
let init = () => {
checkLocalStorage();
generateVisualStructure();
setMoods();
};
let setMoods = () => {
let colorKeys = Object.keys(COLORS);
colorKeys.forEach(e => {
let mood = document.createElement("div");
let color = document.createElement("span");
color.style.background = getGradient(COLORS[e].code);
mood.setAttribute("mood", e);
color.setAttribute("mood", e);
mood.textContent += COLORS[e].label;
mood.appendChild(color);
MOODS.appendChild(mood);
});
};
let checkLocalStorage = () => {
if (window.localStorage.structure === undefined) {
let structure = generateDataStructure();
localStorage.setItem("structure", JSON.stringify(structure));
}
};
let generateDataStructure = () => {
let data = {};
for (let i = 0; i < 12; i++) {
data[i] = Array.from({ length: getDaysFromMonth(i + 1) }, () => null);
}
return data;
};
let generateVisualStructure = () => {
const data = getCurrentLSStructure();
const months = Object.keys(data);
const dayHeaderLength = 31;
let monthHeaderSet = false;
for (let day = 1; day <= dayHeaderLength; day++) {
let dayHeader = document.createElement("div");
dayHeader.className = "dayHeader";
dayHeader.textContent = day;
DAYS_HEADER.appendChild(dayHeader);
}
months.forEach(month => {
let monthContainer = document.createElement("div");
monthContainer.className = "monthContainer";
let monthHeader = document.createElement("div");
monthHeader.className = "monthHeader";
monthHeader.textContent = MONTH_LETTERS[month];
let days = Object.keys(data[month]);
days.forEach(day => {
let dayContainer = document.createElement("div");
dayContainer.className = "dayContainer";
dayContainer.onclick = () => {
assignMood(month, day, dayContainer);
};
if (data[month][day])
dayContainer.style.background = getGradient(
COLORS[data[month][day]].code
);
monthContainer.appendChild(dayContainer);
});
MONTH_HEADER.appendChild(monthHeader);
YEAR_CONTAINER.appendChild(monthContainer);
});
};
let assignMood = (month, day, item) => {
let data = getCurrentLSStructure();
data[month][day] = selectedMood;
if (selectedMood)
item.style.background = getGradient(COLORS[selectedMood].code);
localStorage.setItem("structure", JSON.stringify(data));
};
let getDaysFromMonth = month => new Date(2023, month, 0).getDate();
let getCurrentLSStructure = () => JSON.parse(window.localStorage.structure);
let getGradient = colorId =>
`radial-gradient(ellipse at center, rgba(255,255,255,.1) -95%, ${colorId} 100%)`;
GUIDES.addEventListener("click", e => {
if (e.target.attributes[0].value) {
selectedMood = e.target.attributes[0].value;
SELECTED_MOOD.style.background = getGradient(COLORS[selectedMood].code);
}
});
init();
</script>
<article> <h2>Instructions:</h2>
<p>Pick your mood by clicking on the color!<br>
-click on the corrispanding day on the grid.<br>
-At the end of the year you will have a visual representation of your mood all throught it.</p>
</article>
<footer>
<p>Created by: Valentina Lynn. (@amygdala_lynn on discord) For: hackatron 2023.<br>
Find me on: twitter <a href="https://twitter.com/Mereoleonasluvr" title="twitter"><i class="fi fi-brands-twitter"></i></a>
codedex <a href="https://www.codedex.io/@ValentinaLynn" title="codedex"><i class="fi fi-rr-square-terminal"></i></a>,
github <a href="https://github.com/lynnthegrinch" title="github"><i class="fi fi-brands-github"></i></a>,
tumblr. <a href="https://lynnlovesthestars.tumblr.com" title="tumblr"> <i class="fi fi-brands-tumblr"></i></a> <br>
(though open tumblr at your own risk)
Uicons by <a href="https://www.flaticon.com/uicons">Flaticon</a>
</footer>
</div>
</body>
</html>
<!-- rgba(85, 129, 189, 1.0)
rgba(93, 85, 189, 1.0)
rgba(145, 85, 189, 1.0)-->