-
Notifications
You must be signed in to change notification settings - Fork 7
/
P5L_p5.glitch-almost-everything.html
115 lines (99 loc) · 2.57 KB
/
P5L_p5.glitch-almost-everything.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
<!DOCTYPE html>
<html>
<head>
<title>p5.glitch-almost-everything</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>
<style type="text/css">
body{
margin:0;
overflow:hidden;
background:#000;
}
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-almost-everything
// cc teddavis.org 2020
let glitch;
let fishPath = 'includes/demos-data/images/fish.png';
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
imageMode(CENTER);
glitch = new Glitch();
// glitch.debug(); // debug info
glitch.pixelate(.8); // hard pixels
// glitch.errors(false); // no error messages
// test loadBytes w/ callback
glitch.loadBytes(fishPath, function() {
glitch.randomBytes(50); // 50 random bytes
// glitch.saveBytes('fish_glitch.png'); // toggle saveBytes()
});
glitch.loadType('jpg');
glitch.loadQuality(.96)
glitch.loadImage(fishPath); // glitch loadImage()
loadImage(fishPath, function(img) {
glitch.loadImage(img); // from p5.js loadImage()
});
glitch.debug(false); // turn off before draw()!
}
function draw() {
glitch.resetBytes(); // fresh bytes
glitch.limitBytes(.4, .8) // limit bytes
glitch.randomByte(52) // single random
glitch.randomBytes(5) // 5 random
glitch.randomBytes(5, 150) // 5 random pos, exact val
glitch.replaceByte(53, 255); // single replace
glitch.replaceBytes(123, '7c'); // all replace
glitch.replaceHex('ffdb00430101', 'ffdb00430155');
glitch.swapBytes(88, 100); // swap values
glitch.buildImage();
image(glitch.image, width / 2, height / 2)
}
function keyPressed() {
if(key === 'I') { // image raw
glitch.saveImage('fish_glitched');
} else if(key === 'S') { // image safe
glitch.saveSafe('fish_glitched');
} else if(key === 'C') { // canvas
glitch.saveCanvas('fish_glitched');
}
}
/* 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>