-
Notifications
You must be signed in to change notification settings - Fork 1
/
dragdrop.html
94 lines (80 loc) · 2.49 KB
/
dragdrop.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cyclogram.js prototype</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>
</head>
<style>
html { margin: 10px; }
video { max-width: 100%; height: auto; }
#canvas { text-align: center; }
</style>
<body>
<div id="dragdrop">
<input id="input" type="file" accept=".jpg,.jpeg.,.gif,.png,.mov,.mp4" />
<p><strong>Select a video or image file</strong></p>
</div>
<div id="video"></div>
<div id="canvas"></div>
<script>
let frameRate = 30;
let rowNumber = 0;
let framesPerDay = 288/2; // remove nighttime hours, crudely
let colNumber = 0;
let myX = 100; // where you've clicked
let myY = 400;
let video;
let playVideo = false;
let i = 0;
let dotSize = 6;
let steps;
let density;
function setup() {
createCanvas(1000, 400).parent('canvas');
document.getElementById('input').addEventListener('change', function(event) {
var file = event.target.files[0];
var fileReader = new FileReader();
fileReader.onload = function() {
var blob = new Blob([fileReader.result], {type: file.type});
var url = URL.createObjectURL(blob);
video = createVideo(url).parent('video');
//video.elt.getVideoPlaybackQuality().totalVideoFrames // only how many frames have loaded so far
video.elt.controls = true;
video.elt.load();
noStroke();
steps = parseInt(frameRate * video.elt.duration) // in seconds
density = 1;//pixelDensity();
video.elt.onclick = function click(e) {
myX = parseInt(e.offsetX/video.elt.clientWidth * video.width);
myY = parseInt(e.offsetY/video.elt.clientHeight * video.height);
e.preventDefault();
}
}
fileReader.readAsArrayBuffer(file);
})
}
function draw() {
if (video) {
// video.elt.currentTime = i/frameRate;
video.loadPixels();
let color = [
video.pixels[(myY*video.width*4*density) + (myX*4*density)], // get red
video.pixels[(myY*video.width*4*density) + (myX*4*density + 1)], // get green
video.pixels[(myY*video.width*4*density) + (myX*4*density + 2)] // get blue
];
rect(i % framesPerDay * dotSize, rowNumber * dotSize, dotSize, dotSize);
fill(color);
colNumber += 1;
if (i % framesPerDay == 0) {
rowNumber += 1; // new row
colNumber = 0;
}
if (i == steps) i = 0;
else i++;
}
}
</script>
</body>
</html>