]>
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'),
16 color
.style
.backgroundColor
= `hsl(${h} ${s}% ${l}%)`;
17 light
.style
.transform
= `translateY(-${l*2.2}px)`;
20 function renderTimeline() {
21 var background
= 'linear-gradient(90deg,',
23 for (var {h
, s
, l
, t: now
} of colors
) {
24 background
+= `hsl(${h} ${s}% ${l}%) ${Math.round(100*last/3000)}%,`;
25 background
+= `hsl(${h} ${s}% ${l}%) ${Math.round(100*(last+now)/3000)}%,`;
28 background
+= `black ${Math.round(100*last/3000)}%, black 101%)`;
29 timeline
.style
.background
= background
;
33 return colors
.map((c
) => c
.t
).reduce((s
, t
) => s
+ t
, 0);
38 colors
.push({h
, s
, l
, t: 0});
42 if (recording
) setTimeout(record
, 100);
43 var c
= colors
[colors
.length
- 1],
45 if (c
.h
!== h
|| c
.s
!== s
|| c
.l
!== l
) {
46 c
.t
= Math
.min(3000, Date
.now() - t
);
48 c
= colors
[colors
.length
- 1];
50 if (l
>= 3000) return;
51 c
.t
= Math
.min(3000, Date
.now() - t
);
55 function preview(current
) {
56 if (selecting
|| recording
) return;
57 window
.requestAnimationFrame(preview
);
58 var dt
= current
- lastFrame
,
61 animationTime
= (animationTime
+ dt
) % 3000
62 color
.style
.background
= `hsl(0 0% 0%)`;
63 for (var {h
, s
, l
, t: now
} of colors
) {
64 if (animationTime
>= last
&& animationTime
< last
+now
) {
65 color
.style
.background
= `hsl(${h} ${s}% ${l}%)`;
74 color
.addEventListener('mousemove', ({offsetX: x
, offsetY: y
}) => {
75 h
= Math
.round(360 * x
/ 200);
76 s
= Math
.round(100 * (200 - y
) / 200);
80 color
.addEventListener('wheel', ({deltaY: y
}) => {
82 l
= Math
.min(Math
.max(0, l
+ y
/4), 100)
86 color
.addEventListener('mousedown', () => {
89 setTimeout(record
, 100);
92 color
.addEventListener('mouseup', () => {
96 color
.addEventListener('mouseenter', () => {
100 color
.addEventListener('mouseout', () => {
103 window
.requestAnimationFrame(preview
);
106 clear
.addEventListener('click', () => {