-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
130 lines (111 loc) · 3.26 KB
/
index.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Les parasites</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="container">
<canvas id="parasites"></canvas>
<div id="overlay">
<p class="taille">Noise size:</p>
<button onclick="augSize()" type="button" id="aug">+</button>
<button onclick="dimSize()" type="button" id="dim">-</button>
<!--
<p>Taille de l'image :</p>
<form autocomplete="off">
<input type="number" min="1" max="2500" id="inputwidth" class="inputtext" placeholder="1->2500"></input>
<input type="number" min="1" max="2500" id="inputheight" class="inputtext" placeholder="1->2500"></input>
<input type="button" value="OK" onClick="changeRes()" class="inputbutton"><br>
<input type="button" value="RESET" onClick="resetSettings()" class="inputbutton">
</form>
-->
<br>
<br>
<p><a id="download" download="parasites.png" href="" onclick="download_img(this);">Save noise</a></p>
<p class="interface">(<b>SPACE</b> to hide UI)</p>
</div>
</div>
</body>
<script type="text/javascript">
let size = 10;
let seed = '0123456789abcdef';
let width = window.innerWidth;
let height = window.innerHeight;
/*
function changeRes(){
if(document.getElementById("inputwidth").value != 0){
width = document.getElementById("inputwidth").value;
}else{
width = height;
}
if(height = document.getElementById("inputheight").value != 0){
height = document.getElementById("inputheight").value;
}else{
height = width;
}
if((window.innerWidth <= width)||(window.innerHeight <= height)){
document.body.style.overflow="auto";
}
}
*/
function augSize() {
size +=5;
}
function dimSize() {
if (size >=10){
size -=5;
}
}
document.addEventListener("keypress", function(event){
var timeSpace = 0;
if (event.keyCode == 32){
if(document.getElementById('overlay').style.display === "none"){
document.getElementById('overlay').style.display="block";
}else{
document.getElementById('overlay').style.display="none";
}
}
});
function resetSettings(){
width = window.innerWidth;
height = window.innerHeight;
size = 10;
document.body.style.overflow="hidden";
}
function pixels(canvas){
var canvas = document.getElementById('parasites');
var ctx = canvas.getContext('2d');
var canw = width;
var canh = height;
var total = []; canvas.width = width; canvas.height = height;
function random() {
return 'X'.replace(/X/g, function() {
return seed.charAt(Math.floor(Math.random() * seed.length))
})
};
for (var x=0; x <= width; x += size) {
total.push(x)
};
total.forEach(function(value, index){
for (var i = 0; i <= height; i++) {
ctx.fillStyle = '#' + random().repeat(6);
ctx.fillRect(value, total[i], size, size);
}
});
download_img = function(el) {
var image = canvas.toDataURL("image/png");
el.href = image;
};
function removeOldCanvas(parent) {
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
}
removeOldCanvas(canvas);
document.body.appendChild(canvas);
return ctx;
};
setInterval(pixels, 10);
</script>
</html>