-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser.js
125 lines (96 loc) · 2.85 KB
/
browser.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
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
require('fastclick')(document.body);
var assign = require('object-assign');
var createConfig = require('./config');
var createRenderer = require('./lib/createRenderer');
var contrast = require('wcag-contrast');
var oflow = require('oflow');
var zoneSize = 6; //4;
var videoElement = document.getElementById('videoOut');
var canvas = document.querySelector('#canvas');
var background = new window.Image();
var context = canvas.getContext('2d');
var renderer = null;
var flow = new oflow.WebCamFlow(videoElement, zoneSize);
var seedContainer = document.querySelector('.seed-container');
var config = createConfig();
var isIOS = /(iPad|iPhone|iPod)/i.test(navigator.userAgent);
if (isIOS) { // iOS bugs with full screen ...
const fixScroll = () => {
setTimeout(() => {
window.scrollTo(0, 1);
}, 500);
};
fixScroll();
window.addEventListener('orientationchange', () => {
fixScroll();
}, false);
}
document.body.style.margin = '0';
document.body.style.overflow = 'hidden';
canvas.style.position = 'absolute';
var opts = assign({
context: context,
}, config);
var randomize = (ev) => {
if (ev) ev.preventDefault();
renderer = null;
};
// randomize();
reload();
resize();
function reload () {
var pixelRatio = typeof opts.pixelRatio === 'number' ? opts.pixelRatio : 1;
canvas.width = opts.width * pixelRatio;
canvas.height = opts.height * pixelRatio;
var init = function() {
var stepCount;
flow.onCalculated((direction) => {
if(!renderer) {
stepCount = 0;
opts.videoWidth = videoElement.videoWidth;
opts.videoHeight = videoElement.videoHeight;
config = createConfig();
opts = assign({
context: context,
}, config);
setBackgroundColor();
renderer = createRenderer(opts, direction);
renderer.clear();
renderer.clear();
renderer.clear();
renderer.clear();
}
// direction.zones[n] =
// {
// x, y // zone center
// u, v // vector of flow in the zone
// }
renderer.step(opts.interval, direction);
stepCount++;
if (stepCount > opts.steps) {
stepCount = 0;
renderer = null;
}
});
videoElement.removeEventListener('playing', init, false);
};
videoElement.addEventListener('playing', init, false);
flow.startCapture();
}
function setBackgroundColor() {
document.body.style.background = opts.palette[0];
seedContainer.style.color = getBestContrast(opts.palette[0], opts.palette.slice(1));
// seedText.textContent = opts.seedName;
}
function getBestContrast (background, colors) {
var bestContrastIdx = 0;
var bestContrast = 0;
colors.forEach((p, i) => {
var ratio = contrast.hex(background, p);
if (ratio > bestContrast) {
bestContrast = ratio;
bestContrastIdx = i;
}
});
return colors[bestContrastIdx];
}