-
Notifications
You must be signed in to change notification settings - Fork 7
/
P5L_p5.glitch-instance.html
86 lines (76 loc) · 2.14 KB
/
P5L_p5.glitch-instance.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
<!DOCTYPE html>
<html>
<head>
<title>p5.glitch-instance</title>
<meta charset="utf-8">
<!-- Compiled w/ P5LIVE, http://github.com/ffd8/p5live -->
<script src="https://cdn.jsdelivr.net/npm/p5@1.3.0/lib/p5.min.js"></script>
<style type="text/css">
body{
margin:0;
overflow:hidden;
background:#000022;
cursor:crosshair;
}
.p5sketch{
box-sizing: border-box;
width:98vw;
height:30vh;
border:1px solid #fff;
margin:1vw;
}
</style>
<script type="text/javascript" src="includes/libs/p5.glitch.js"></script>
<script type="text/javascript">
// p5.glitch-instance
// cc teddavis.org 2021
let id = 0;
let src = 'includes/demos-data/images/fish.png';
function buildSketch(elm, type){
let parent = document.getElementById(elm);
new p5( function(sketch){
sketch.glitch;
sketch.setup = () => {
let cvn = sketch.createCanvas(parent.offsetWidth-2, parent.offsetHeight-2);
sketch.glitch = new Glitch(sketch);
sketch.glitch.loadType(type);
sketch.glitch.loadQuality(1.0);
sketch.glitch.loadImage(src, function(){
sketch.glitched();
});
cvn.mouseMoved(sketch.glitched);
sketch.glitch.errors(false);
sketch.disableFriendlyErrors = true;
sketch.imageMode(sketch.CENTER);
sketch.background(0, 0, 255);
sketch.frameCount = sketch.floor(sketch.random(9999));
sketch.rot = 0;
};
sketch.draw = () => {
sketch.x = sketch.width - sketch.frameCount * 2 % sketch.width;
sketch.y = sketch.height / 2 + sketch.sin(sketch.frameCount * 0.05) * sketch.height/4;
sketch.translate(sketch.x, sketch.y);
sketch.rotate(-sketch.radians(sketch.cos(sketch.frameCount*.05))*5);
sketch.image(sketch.glitch.image, 0, 0);
}
sketch.glitched = () => {
sketch.glitch.resetBytes();
sketch.glitch.randomBytes(15); // randomize 10 bytes
sketch.glitch.buildImage();
}
}, parent);
id++;
}
</script>
</head>
<body>
<div id="sketch1" class="p5sketch"></div>
<div id="sketch2" class="p5sketch"></div>
<div id="sketch3" class="p5sketch"></div>
<script>
buildSketch('sketch1', 'jpg')
buildSketch('sketch2', 'png')
buildSketch('sketch3', 'webp')
</script>
</body>
</html>