-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilterbooth.html
268 lines (264 loc) · 11.6 KB
/
filterbooth.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<meta name="viewport" content="width=device-width">
<html lang="en-us" xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="en-us">
<head>
</head>
<body>
<style>
.big {
font-size: 20px;
font-family: sans-serif;
}
#source {
font-size: 20px;
font-family: Courier, Fixed, monospace;
position: absolute;
color: white;
text-shadow: 2px 2px 0px black;
left: 0px;
bottom: 0px;
}
video {
width: 100%;
height: 100%;
clear: right;
}
</style>
<span class="big">Current filter: </span>
<select class="big" id="select1"></select>
<span class="big"><input type="checkbox" id="showSource">Show Source</input></span>
<video autoplay="true" loop="loop" id="video1" tabindex="0">
</video>
<pre class="big" id="source"></pre>
<svg id="image" width="0" height="0" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="grad1" cx="50%" cy="50%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:rgb(255, 255, 255); stop-opacity:1;"/>
<stop offset="10%" style="stop-color:rgb(0, 0, 0); stop-opacity:1;"/>
<stop offset="20%" style="stop-color:rgb(255, 255, 255); stop-opacity:1;"/>
<stop offset="30%" style="stop-color:rgb(0, 0, 0); stop-opacity:1;"/>
<stop offset="40%" style="stop-color:rgb(255, 255, 255); stop-opacity:1;"/>
<stop offset="50%" style="stop-color:rgb(0, 0, 0); stop-opacity:1;"/>
<stop offset="60%" style="stop-color:rgb(255, 255, 255); stop-opacity:1;"/>
<stop offset="70%" style="stop-color:rgb(0, 0, 0); stop-opacity:1;"/>
<stop offset="80%" style="stop-color:rgb(255, 255, 255); stop-opacity:1;"/>
<stop offset="90%" style="stop-color:rgb(0, 0, 0); stop-opacity:1;"/>
<stop offset="100%" style="stop-color:rgb(0,0,0); stop-opacity:1;"/>
</radialGradient>
<circle id="circle" cx="500" cy="300" r="500" fill="url(#grad1)"/>
<filter id="big-squares" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feMorphology radius="15" operator="dilate" id="BigSquaresMorph"/>
</filter>
<filter id="turbulence" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feTurbulence baseFrequency=".01" type="fractalNoise" numOctaves="3" seed="23" stitchTiles="stitch"/>
</filter>
<filter id="displaceleaf" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feImage xlink:href="IMG_0854_SMALL.JPG" result="image"/>
<feDisplacementMap scale="50" xChannelSelector="G" yChannelSelector="G" in="SourceGraphic" in2="image"/>
</filter>
<filter id="displacewave" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feImage xlink:href="#circle" result="image"/>
<feDisplacementMap scale="40" xChannelSelector="G" yChannelSelector="G" in="SourceGraphic" in2="image"/>
</filter>
<filter id="x-blur" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feGaussianBlur stdDeviation="20 0" id="XBlur"/>
</filter>
<filter id="classic-trek" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feColorMatrix id="Saturate1" type="saturate" values="5.35" result="Saturate1"/>
<feGaussianBlur id="Blur1" in="Saturate1" result="Blur1"
stdDeviation="20"/>
<feColorMatrix id="Opacity1" values="1 0 0 0 0,
0 1 0 0 0,
0 0 1 0 0,
0 0 0 0.64 0" in="Blur1" result="Opacity1"/>
<feComposite id="Composite1" operator="over" in="Opacity1" in2="Saturate1"/>
</filter>
<filter id="edgy-squares" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feMorphology operator="dilate" radius="5" id="EdgySquaresMorph"/>
<feConvolveMatrix kernelMatrix="1 -1 1 -1 -0.01 -1 1 -1 1" order="3"/>
</filter>
<filter id="inverse" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feComponentTransfer>
<feFuncR type="table" tableValues="1 0"/>
<feFuncG type="table" tableValues="1 0"/>
<feFuncB type="table" tableValues="1 0"/>
</feComponentTransfer>
</filter>
<filter id="jimi" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feColorMatrix type="hueRotate" values="275"/>
<feColorMatrix type="saturate" values="15"/>
<feDisplacementMap scale="50" xChannelSelector="R" yChannelSelector="G"/>
</filter>
<filter id="inverse" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feComponentTransfer>
<feFuncR type="table" tableValues="1 0"/>
<feFuncG type="table" tableValues="1 0"/>
<feFuncB type="table" tableValues="1 0"/>
</feComponentTransfer>
</filter>
<filter id="edgy" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feConvolveMatrix order="3" kernelMatrix="1 -1 1 -1 -0.01 -1 1 -1 1" edgeMode="duplicate" result="convo"/>
</filter>
<filter id="edgy-blur" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feGaussianBlur in="SourceGraphic" stdDeviation="6" result="blur" id="EdgyBlur"/>
<feConvolveMatrix order="3" kernelMatrix="1 -1 1 -1 -0.01 -1 1 -1 1" edgeMode="none" result="convo"/>
</filter>
<filter id="pointlight" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feDiffuseLighting surfaceScale="1" diffuseConstant="1">
<fePointLight x="0" y="0" z="100" id="fePointLight1"/>
</feDiffuseLighting>
<feBlend mode="multiply" in2="SourceGraphic"/>
</filter>
<filter id="spotlight" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feDiffuseLighting surfaceScale="1" diffuseConstant="1">
<feSpotLight x="0" y="0" z="100" specularExponent="1" limitingConeAngle="30
" id="feSpotLight1"/>
</feDiffuseLighting>
<feBlend mode="multiply" in2="SourceGraphic"/>
</filter>
<filter id="black-and-white" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feColorMatrix values="0.3333 0.3333 0.3333 0 0,
0.3333 0.3333 0.3333 0 0,
0.3333 0.3333 0.3333 0 0,
0 0 0 1 0"/>
</filter>
<filter id="edgy2" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feConvolveMatrix filterRes="100 100" order="3" kernelMatrix="0 -1 0 -1 4 -1 0 -1 0" preserveAlpha="true"/>
</filter>
<filter id="funhouse" x="0%" y="0%" height="100%" width="100%" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feDisplacementMap scale="100" in2="SourceGraphic" xChannelSelector="G" yChannelSelector="R"/>
</filter>
<filter id="tron" x="0%" y="0%" width="100%" height="100%" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feFlood flood-color="blue" result="A"/>
<feColorMatrix type="matrix" in="SourceGraphic" result="B"
values="1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
1 1 1 0 0"/>
<feMerge>
<feMergeNode in="A"/>
<feMergeNode in="B"/>
</feMerge>
</filter>
<filter id="noir" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feComponentTransfer>
<feFuncR type="discrete" tableValues="0 .5 1 1"/>
<feFuncG type="discrete" tableValues="0 .5 1"/>
<feFuncB type="discrete" tableValues="0"/>
</feComponentTransfer>
</filter>
<filter id="glassy" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feTurbulence baseFrequency="0.057" numOctaves="1" type="fractalNoise"/>
<feDisplacementMap scale="150" xChannelSelector="R" yChannelSelector="G" in="SourceGraphic" id="GlassyDispl"/>
</filter>
</defs>
</svg>
<script>
var video = document.querySelector('video');
var select = document.getElementById('select1');
var showSource = document.getElementById('showSource');
var filters = ['x-blur', 'classic-trek', 'edgy-squares', 'pointlight', 'spotlight', 'jimi', 'big-squares', 'inverse','edgy','edgy-blur', 'black-and-white','noir','tron', 'funhouse', 'glassy' /*, 'displaceleaf', 'displacewave' */];
navigator.getMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
if (navigator.getMedia) {
navigator.getMedia({video: true}, function(localMediaStream) {
video.srcObject = localMediaStream;
}, function(e) { console.log(e); });
}
video.addEventListener('loadedmetadata', function() {
var centerX = document.body.clientWidth / 2;
var centerY = document.body.clientHeight / 2;
var xBlur = document.getElementById("XBlur");
var edgyBlur = document.getElementById("EdgyBlur");
var edgySquaresMorph = document.getElementById("EdgySquaresMorph");
var bigSquaresMorph = document.getElementById("BigSquaresMorph");
var pointLight = document.getElementById("fePointLight1");
var spotLight = document.getElementById("feSpotLight1");
var glassyDispl = document.getElementById("GlassyDispl");
spotLight.setAttribute("pointsAtX", centerX);
spotLight.setAttribute("pointsAtY", centerY);
spotLight.setAttribute("pointsAtZ", 0);
var prevX, prevY, mouseIsDown = false;
video.onmousedown = function(event) {
var x = event.pageX - video.offsetLeft;
var y = event.pageY - video.offsetTop;
mouseIsDown = true;
prevX = x; prevY = y;
}
video.onmouseup = function(event) {
mouseIsDown = false;
}
video.onmousemove = function(event) {
var x = event.pageX - video.offsetLeft;
var y = event.pageY - video.offsetTop;
pointLight.setAttribute("x", x);
pointLight.setAttribute("y", y);
spotLight.setAttribute("x", x);
spotLight.setAttribute("y", y);
var deltaX = x - prevX;
var deltaY = y - prevY;
prevX = x;
prevY = y;
if (mouseIsDown) {
if (select.value == 'x-blur') {
xBlur.setStdDeviation(xBlur.stdDeviationX.baseVal + deltaX, xBlur.stdDeviationY.baseVal);
} else if (select.value == 'edgy-blur') {
edgyBlur.setStdDeviation(edgyBlur.stdDeviationX.baseVal + deltaX,
edgyBlur.stdDeviationY.baseVal + deltaX);
} else if (select.value == 'glassy') {
glassyDispl.scale.baseVal += deltaX;
} else if (select.value == 'edgy-squares') {
var newRadius = edgySquaresMorph.radiusX.baseVal + deltaX;
newRadius = Math.min(Math.max(newRadius, 5), 30);
edgySquaresMorph.setAttribute("radius", newRadius);
} else if (select.value == 'big-squares') {
var newRadius = bigSquaresMorph.radiusX.baseVal + deltaX;
newRadius = Math.min(Math.max(newRadius, 0), 30);
bigSquaresMorph.setAttribute("radius", newRadius);
}
}
updateSource();
}
video.addEventListener('touchmove', function(event) {
if (event.targetTouches.length == 1) {
event.preventDefault();
video.onmousemove(event.targetTouches[0]);
}
});
video.addEventListener('touchstart', function(event) {
if (event.targetTouches.length == 1) {
event.preventDefault();
video.onmousedown(event.targetTouches[0]);
}
});
video.addEventListener('touchend', function(event) {
video.onmouseup(event.targetTouches[0]);
});
});
for (var i = 0; i < filters.length; ++i) {
var o = document.createElement("option");
o.innerHTML = filters[i];
o.value = filters[i];
select.appendChild(o);
}
updateSource = function() {
var elem = document.getElementById(select.value);
var source = document.getElementById('source');
if (showSource.checked) {
source.textContent = elem.innerHTML;
} else {
source.textContent = "";
}
}
showSource.onchange = function() { updateSource(); }
select.onchange = function() {
video.style.filter='url(#'+select.value+')';
video.style.webkitFilter='url(#'+select.value+')';
updateSource();
};
select.onchange();
</script>
</body>
</html>