]>
git.r.bdr.sh - rbdr/fyr/blob - js/fyr.js
1 var color
= document
.querySelector('.color'),
2 light
= document
.querySelector('.light'),
3 timeline
= document
.querySelector('.timeline'),
4 clear
= document
.querySelector('.clear'),
14 {round
, min
, max
} = Math
;
17 color
.style
.backgroundColor
= `hsl(${h} ${s}% ${l}%)`;
18 light
.style
.transform
= `translateY(-${l*2.2}px)`;
21 function renderTimeline() {
22 var background
= 'linear-gradient(90deg,',
24 for (var {h
, s
, l
, t: now
} of colors
) {
25 background
+= `hsl(${h} ${s}% ${l}%) ${round(100*last/3000)}%,`;
26 background
+= `hsl(${h} ${s}% ${l}%) ${round(100*(last+now)/3000)}%,`;
29 background
+= `black ${round(100*last/3000)}%, black 101%)`;
30 timeline
.style
.background
= background
;
34 return colors
.map((c
) => c
.t
).reduce((s
, t
) => s
+ t
, 0);
39 colors
.push({h
, s
, l
, t: 0});
43 if (recording
) setTimeout(record
, 100);
44 var c
= colors
[colors
.length
- 1],
46 if (c
.h
!== h
|| c
.s
!== s
|| c
.l
!== l
) {
47 c
.t
= min(3000, Date
.now() - t
);
49 c
= colors
[colors
.length
- 1];
51 if (l
>= 3000) return;
52 c
.t
= min(3000, Date
.now() - t
);
56 function preview(current
) {
57 if (selecting
|| recording
) return;
58 window
.requestAnimationFrame(preview
);
59 var dt
= current
- lastFrame
,
62 animationTime
= (animationTime
+ dt
) % 3000
63 color
.style
.background
= `hsl(0 0% 0%)`;
64 for (var {h
, s
, l
, t: now
} of colors
) {
65 if (animationTime
>= last
&& animationTime
< last
+now
) {
66 color
.style
.background
= `hsl(${h} ${s}% ${l}%)`;
75 color
.addEventListener('mousemove', ({offsetX: x
, offsetY: y
}) => {
76 h
= round(360 * x
/ 200);
77 s
= round(100 * (200 - y
) / 200);
81 color
.addEventListener('wheel', ({deltaY: y
}) => {
83 l
= min(max(0, l
+ y
/4), 100)
87 color
.addEventListener('mousedown', () => {
90 setTimeout(record
, 100);
93 color
.addEventListener('mouseup', () => {
97 color
.addEventListener('mouseenter', () => {
101 color
.addEventListener('mouseout', () => {
104 window
.requestAnimationFrame(preview
);
107 clear
.addEventListener('click', () => {