-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
131 lines (107 loc) · 2.81 KB
/
index.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Imgstry Spline Curve Widget</title>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<section id="menu">
<button data-target="imgstry">Editor</button>
<button data-target="curve">Spline</button>
</section>
<section id="imgstry">
<div>
<canvas id="editor" width="500" height="500">
</div>
<button id="run">Run</button>
</section>
<section id="curve">
<div>
<canvas id="spline" width="500" height="500">
</div>
</section>
</canvas>
<script type="module">
import { Imgstry, ImgstrySpline, Theme, GaussianBlur } from './source';
async function editor() {
const URL = 'https://www.wescreenplay.com/wp-content/uploads/2017/11/rick-and-morty-portal.jpg';
const editorCanvas = Imgstry.getCanvas('#editor');
const processor = new Imgstry(editorCanvas, {
thread: {
isDebugEnabled: true,
}
});
const image = await Imgstry.loadImage(URL);
processor.drawImage(image);
async function listener() {
const canvas = await processor
.brightness(10)
.tint('#16a085')
.contrast(20)
.render();
}
const button = document.getElementById('run');
button.addEventListener('click', listener);
return () => {
processor.dispose();
button.removeEventListener('click', listener);
}
};
async function spline() {
const splineCanvas = Imgstry.getCanvas('#spline');
const curve = new ImgstrySpline(splineCanvas, {
theme: Theme.Dark,
anchorSize: 18,
gridSize: 5
});
[
{
x: .11,
y: .35
},
{
x: .33,
y: .56
},
{
x: .65,
y: .8
},
{
x: .93,
y: .6
}
].forEach(p => curve.add(p));
return () => {
curve.dispose();
}
}
let teardown = undefined;
async function switchTo(id) {
const sections = document.querySelectorAll('section');
sections.forEach(section => {
if (section.id === 'menu') {
return;
}
section.style.display = 'none';
});
const section = document.getElementById(id);
section.style.display = 'block';
teardown && teardown();
if (id === 'imgstry') {
teardown = await editor();
}
if (id === 'curve') {
teardown = await spline();
}
}
const menu = document.getElementById('menu');
menu.addEventListener('click', event => {
const target = event.target;
const id = target.getAttribute('data-target');
switchTo(id);
});
</script>
<body>
</html>