forked from jwunderl/pxt-color
-
Notifications
You must be signed in to change notification settings - Fork 0
/
effect.ts
50 lines (44 loc) · 1.41 KB
/
effect.ts
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
namespace color {
//% fixedInstance whenUsed block="fade to black"
export const FadeToBlack = new FadeEffect(() => {
return (new Fade())
.setEndPalette(Black);
});
//% fixedInstance whenUsed block="fade to white"
export const FadeToWhite = new FadeEffect(() => {
return (new Fade())
.setEndPalette(White);
});
//% fixedInstance whenUsed block="darken"
export const Darken = new FadeEffect(darkenEffect);
function darkenEffect() {
const f = new Fade();
return f.mapEndHSL(hsl => {
hsl.luminosity *= .75;
hsl.luminosity *= .9;
return hsl;
});
}
//% fixedInstance whenUsed block="brighten"
export const Brighten = new FadeEffect(brightenEffect);
function brightenEffect() {
const f = new Fade();
return f.mapEndHSL(hsl => {
hsl.luminosity /= .75;
hsl.saturation /= .9;
return hsl;
});
}
//% fixedInstance whenUsed block="rotate palette"
export const RotatePalette = new FadeEffect(() => {
const l = availableColors();
const p = color._clone(currentPalette())
const lastColor = p.color(l - 1);
for (let i = l - 1; i > 1; --i) {
p.setColor(i, p.color(i - 1));
}
p.setColor(1, lastColor);
return (new Fade())
.setEndPalette(p);
});
}