-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeonIncident.js
74 lines (65 loc) · 2.08 KB
/
LeonIncident.js
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
import { Effect } from "@donkeyclip/motorcortex";
import compAtrrs from "./compoAttributes";
class LeonIncident extends Effect {
getScratchValue() {
const scratchValues = {};
const LeonClip = this.element.entity.leon;
compAtrrs.LeonAttrs.forEach(
(key) => (scratchValues[key] = LeonClip[key] ?? 0)
);
return scratchValues;
}
drawning() {
// handle different cases of drawing functionalities
const { drawing, ctx, leon, patternHeight, patternWidth } =
this.element.entity;
switch (drawing) {
case "colorful":
leon.drawColorful(ctx);
break;
case "pattern":
leon.pattern(
ctx,
leon.patternWidth ?? patternWidth,
leon.patternHeight ?? patternHeight
);
break;
default:
leon.draw(ctx);
}
}
clearRect() {
// this function clears the canvas in every RAF
const { ctx, sw, sh } = this.element.entity;
ctx.clearRect(0, 0, sw, sh);
}
animate(fraction) {
// this function animate the attributes before drawing them
const { leon } = this.element.entity;
compAtrrs.LeonAttrs.forEach((compoAttribute) => {
const targetValue = this.targetValue[compoAttribute];
const initialValue = this.initialValue[compoAttribute];
const difference = targetValue - initialValue;
const finalValue = fraction * difference + initialValue;
leon[compoAttribute] = finalValue;
if (compoAttribute === "completion_rate") {
leon.drawing.forEach((drawingElement) => {
drawingElement.value = finalValue;
});
}
});
}
onProgress(m) {
compAtrrs.LeonAttrs.forEach((compoAttribute) => {
const initialValue = this.initialValue[compoAttribute];
const targetValue = this.targetValue[compoAttribute];
const difference = targetValue - initialValue;
const { leon } = this.element.entity;
leon[compoAttribute] = this.getFraction(m) * difference + initialValue;
});
this.clearRect();
this.animate(this.getFraction(m));
this.drawning();
}
}
export default LeonIncident;