-
Notifications
You must be signed in to change notification settings - Fork 1
/
prototype.html
78 lines (66 loc) · 1.99 KB
/
prototype.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
<!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 { width: 100%; }
#canvas { text-align: center; }
</style>
<body>
<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');
video = createVideo('river.mp4').parent('video');
//video = createVideo('https://archive.org/download/cyclogram-timelapse-test/9-month-river-timelapse-autumn-winter-sprin.mp4')
//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();
}
}
function draw() {
// 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>