-
Notifications
You must be signed in to change notification settings - Fork 7
/
P5L_p5.glitch-video.html
107 lines (88 loc) · 2.03 KB
/
P5L_p5.glitch-video.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
<!DOCTYPE html>
<html>
<head>
<title>p5.glitch-video</title>
<meta charset="utf-8">
<!-- Compiled w/ P5LIVE, http://github.com/ffd8/p5live -->
<script src="https://cdn.jsdelivr.net/npm/p5@1.0.0/lib/p5.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/p5@1.0.0/lib/addons/p5.sound.min.js"></script>
<style type="text/css">
body{
margin:0;
overflow:hidden;
}
canvas{
position:fixed;
top:0;
left:0;
z-index:-1;
width:100vw;
height:100vh;
margin:0;
}
</style>
<script type="text/javascript">
// eco-mode = only render if window focused
window.onblur = function () {
noLoop()
}
window.onfocus = function () {
loop();
}
</script>
<script type="text/javascript" src="includes/libs/p5.glitch.js"></script>
<script type="text/javascript">
//p5.glitch-video
// p5.glitch-video
// cc teddavis.org 2020
let libs = ["includes/libs/p5.glitch.js"];
let glitch, vid, rPosition = 1000;
function preload() {
vid = createVideo('includes/demos-data/videos/big_buck_bunny.mp4', function() {
vid.hide();
vid.volume(0);
vid.loop();
});
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
imageMode(CENTER);
glitch = new Glitch();
glitch.pixelate(1);
}
function draw() {
background(255);
// one per second, set single random byte position
if(frameCount % 60 === 0) {
rPosition = random(glitch.bytes.length);
}
if(frameCount % 3 === 0) {
if(!mouseIsPressed) {
glitch.loadImage(vid);
}
glitch.randomByte(rPosition); // single randome byte
glitch.limitBytes(.78); // limit bytes to branch
glitch.randomBytes(10, 2); // set 10 random bytes
glitch.buildImage();
}
image(glitch.image, width / 2, height / 2)
}
/* CUSTOM FUNCTIONS FOR P5LIVE */
// keep fullscreen if window resized
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
// custom ease function
function ease(iVal, oVal, eVal){
return oVal += (iVal - oVal) * eVal;
}
// processing compatibility
function println(msg){
print(msg);
}
</script>
</head>
<body>
</body>
</html>