-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathmain.js
More file actions
86 lines (80 loc) · 2.82 KB
/
main.js
File metadata and controls
86 lines (80 loc) · 2.82 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (c) 2016-2017 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* <http://creativecommons.org/licenses/by/4.0>.
* or send a letter to Creative Commons, PO Box 1866,
* Mountain View, CA 94042, USA.
*
*/
import { CLUT } from "piu/MC";
const blackSkin = new Skin({ fill:"black" });
const panoramaTexture = new Texture("panorama.png");
const panoramaSkin = new Skin({ texture:panoramaTexture, x:0, y:0, width:694, height:240 });
const grayCLUT = new CLUT("gray.cct");
const mainCLUT = new CLUT("main.cct");
class ScrollerBehavior extends Behavior {
onDisplaying(scroller) {
this.state = 0;
this.grayColors = grayCLUT.colors;
this.mainColors = mainCLUT.colors;
this.blueColors = new Array(16).fill(0x192eabFF);
this.whiteColors = new Array(16).fill(0xFFFFFFFF);
this.colors = new Array(16).fill();
scroller.duration = 1000;
//scroller.interval = 50;
scroller.time = 0;
scroller.start();
}
onFinished(scroller) {
this.state++;
if (this.state == 8)
this.state = 0;
switch (this.state) {
case 0: application.clut = mainCLUT; break;
case 1: scroller.scrollTo(0x7FFF, 0); break;
case 3: scroller.scrollTo(0, 0); break;
case 4: application.clut = grayCLUT; break;
case 5: scroller.scrollTo(0x7FFF, 0); break;
case 7: scroller.scrollTo(0, 0); break;
}
scroller.time = 0;
scroller.start();
}
onTimeChanged(scroller) {
let fromColors = this.flag ? this.fromColors : this.toColors;
let toColors = this.flag ? this.toColors : this.fromColors;
switch (this.state) {
case 0: fromColors = this.mainColors; toColors = this.blueColors; break;
case 1: fromColors = this.blueColors; toColors = this.mainColors; break;
case 2: fromColors = this.mainColors; toColors = this.whiteColors; break;
case 3: fromColors = this.whiteColors; toColors = this.mainColors; break;
case 4: fromColors = this.grayColors; toColors = this.blueColors; break;
case 5: fromColors = this.blueColors; toColors = this.grayColors; break;
case 6: fromColors = this.grayColors; toColors = this.whiteColors; break;
case 7: fromColors = this.whiteColors; toColors = this.grayColors; break;
}
let colors = this.colors;
let fraction = Math.quadEaseOut(scroller.fraction);
for (let i = 0; i < 16; i++) {
colors[i] = blendColors(fraction, fromColors[i], toColors[i]);
}
application.animateColors(colors);
}
};
let CLUTApplication = Application.template($ => ({
skin:blackSkin,
contents: [
Scroller($, {
left:0, right:0, height:240, clip:true, Behavior:ScrollerBehavior,
contents: [
Content($, { left:0, top:0, skin:panoramaSkin } ),
],
}),
]
}));
export default new CLUTApplication(null, { displayListLength:4096, touchCount:1 });