-
Notifications
You must be signed in to change notification settings - Fork 6
/
effect.ts
52 lines (45 loc) · 1.54 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
51
52
namespace color {
const stateNamespace = "__coloreffectstate";
//% fixedInstance whenUsed block="fade to black"
export const FadeToBlack = new FadeEffect("fadetoblack", () => {
return (new Fade())
.setEndPalette(Black);
});
//% fixedInstance whenUsed block="fade to white"
export const FadeToWhite = new FadeEffect("fadetowhite", () => {
return (new Fade())
.setEndPalette(White);
});
//% fixedInstance whenUsed block="darken"
export const Darken = new FadeEffect("darken", darkenEffect, "brighten");
function darkenEffect() {
const f = new Fade();
return f.mapEndHSL(hsl => {
hsl.luminosity *= .75;
hsl.saturation *= .9;
return hsl;
});
}
//% fixedInstance whenUsed block="brighten"
export const Brighten = new FadeEffect("brighten", brightenEffect, "darken");
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("rotate", () => {
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);
});
}