-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.html
220 lines (185 loc) · 5.95 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
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
<html>
<head>
<script src="lib/Seriously.js/seriously.js"></script>
<script src="lib/Seriously.js/effects/seriously.accumulator.js"></script>
<script src="lib/Seriously.js/effects/seriously.displacement.js"></script>
<script src="lib/Seriously.js/effects/seriously.hue-saturation.js"></script>
<script src="lib/Seriously.js/effects/seriously.color-select.js"></script>
<style>
html,
body {
margin: 0;
padding: 0;
background: black;
color: white;
font-family: sans-serif;
}
#target {
max-width: 100%;
max-height: 100%;
}
video,
.controls {
width: 400px;
float: left;
margin: 10px 5px;
}
.control {
width: 100%
}
.control input[type="range"] {
width: 100%;
}
</style>
</head>
<body>
<canvas id="target" width="1920" height="1080"></canvas>
<div class="controls">
<div>
<h3>Chromavore</h3>
<p>
Load your own videos by dropping a video file onto the one you want to replace. Use the controls to affect the
canvas. Right-click -> save-as to save an image.
</p>
</div>
<hr>
<div class="control">
<p>opacity</p>
<input type="range" min="0" max="1" value=".1" step=".01" id="opacity" />
</div>
<div class="control">
<p>displacement</p>
<input type="range" min="0" max="30" value="15" step=".01" id="displacement" />
</div>
<div class="control">
<p>lightness min</p>
<input type="range" min="0" max="1" value=".5" step=".01" id="lightness-min" />
</div>
<div class="control">
<p>mode</p>
<select id="blendMode">
<option value="normal">normal</option>
<option value="screen">screen</option>
<option value="multiply">multiply</option>
</select>
</div>
</div>
<div id="v1">
<img style="display: none">
<video muted autoplay loop controls>
<source src="videos/KOLL-HD.mp4" type="video/mp4" />
</video>
</div>
<div id="v2">
<img style="display: none">
<video muted autoplay loop controls>
<source src="videos/crystmounts-HD.mp4" type="video/mp4" />
</video>
</div>
<script>
window.addEventListener('load', function () {
setupDragDrop()
document.querySelector('#v1 video').playbackRate = .5
document.querySelector('#v2 video').playbackRate = .5
var seriously = new Seriously(),
v1 = seriously.source('#v1 video'),
v2 = seriously.source('#v2 video'),
v1Format = seriously.transform('reformat'),
v2Format = seriously.transform('reformat'),
colorSelect = seriously.effect('color-select'),
hueSat = seriously.effect('hue-saturation'),
accumulator = seriously.effect('accumulator'),
displacement = seriously.effect('displacement'),
target = seriously.target('#target')
// make the videos cover the canvas.
v1Format.mode = 'cover'
v1Format.width = 1920
v1Format.height = 1080
v2Format.mode = 'cover'
v2Format.width = 1920
v2Format.height = 1080
// colorSelect.lightnessMax = .3
colorSelect.lightnessMin = '#lightness-min'
// colorSelect.saturationMin = 10
hueSat.hue = 0
// hueSat.saturation = -.2
accumulator.blendMode = '#blendMode'
accumulator.opacity = '#opacity'
displacement.fillMode = 'color' // wrap, color, ignore, clamp
displacement.mapScale = [.01, .01]
displacement.color = [0, 0, 0, 0]
displacement.offset = .1
displacement.amount = '#displacement'
// hook up nodes
v1Format.source = v1
v2Format.source = v2
hueSat.source = v1Format
colorSelect.source = hueSat
displacement.source = colorSelect
displacement.map = v2Format
accumulator.source = displacement
target.source = accumulator
// every frame
var time = 0
seriously.go(function () {
time++
// displacement.amount = Math.sin(time*.008) * 100
// hueSat.hue = Math.sin(time*.002)
// accumulator.opacity = Math.abs(Math.sin(time*.003)) * .5
})
// setTimeout(function () {
// seriously.stop()
// }, 5000) // ??
function setupDragDrop() {
// prevent accidental drop, which would load the file and kick you out of chromavore
document.addEventListener('dragover', function (e) {
e.preventDefault()
}, false)
document.getElementById('v1').addEventListener('dragover', onDragOver, true)
document.getElementById('v2').addEventListener('dragover', onDragOver, true)
document.getElementById('v1').addEventListener('drop', onDrop, true)
document.getElementById('v2').addEventListener('drop', onDrop, true)
}
function onDragOver(e) {
e.dataTransfer.dropEffect = 'copy'
}
function onDrop(e) {
console.log(e.currentTarget)
var file = e.dataTransfer.files[0]
// console.log(file)
e.preventDefault()
e.stopPropagation()
var targetContainer = e.currentTarget
var reader = new FileReader()
reader.readAsDataURL(file)
reader.addEventListener('load', function () {
var isImage = file.type.match('image/') !== null
// console.log('isImage', isImage)
var img = targetContainer.querySelector('img')
var vid = targetContainer.querySelector('video')
var targetElType = isImage ? 'img' : 'video'
if (isImage) {
img.src = reader.result
img.style.display = 'block'
vid.style.display = 'none'
vid.pause()
} else {
img.style.display = 'none'
vid.style.display = 'block'
vid.src = reader.result
target.playbackRate = .5
vid.play()
}
var formatter = targetContainer.id === 'v1' ? v1Format : v2Format
formatter.source = seriously.source(`#${targetContainer.id} ${targetElType}`)
})
}
})
</script>
<a href="https://github.com/positlabs/chromavore" target="_blank"><img
style="position: absolute; top: 0; left: 0; border: 0;"
src="https://camo.githubusercontent.com/567c3a48d796e2fc06ea80409cc9dd82bf714434/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f6461726b626c75655f3132313632312e706e67"
alt="Fork me on GitHub"
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_darkblue_121621.png"></a>
</body>
</html>