forked from rene-dev/pixel
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.html
203 lines (180 loc) · 6.57 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var canvas;
var gl;
var requestAnimFrame;
var shaderProgram;
var vertexBuffer;
var timeStart = 0.0;
var time = 0.0;
var timeDelta = 0.0;
var data = [];
var uploadedData = [];
// data stuff:
function loadData()
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (xhttp.readyState == 4 && xhttp.status == 200)
data = JSON.parse(xhttp.responseText);
};
xhttp.open("GET", "data.json", true);
xhttp.send();
}
//loadData();
setInterval(loadData, 500);
function fadeAndUploadData()
{
var vertices = [];
for (var i = 0; i < 8 * 8 * 8; i++)
{
if (!uploadedData[i])
uploadedData[i] = data[i];
uploadedData[i] = 0.95 * uploadedData[i] + 0.05 * data[i];
vertices[i * 2 + 0] = i;
vertices[i * 2 + 1] = Math.sqrt(uploadedData[i]);
}
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STREAM_DRAW);
}
// WebGL stuff:
function getShader(type, text)
{
var shader = gl.createShader(type);
gl.shaderSource(shader, text);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
{
alert(gl.getShaderInfoLog(shader));
return null;
}
return shader;
}
function loadProgram(vert, frag)
{
var vertexShader = getShader(gl.VERTEX_SHADER, vert);
var fragmentShader = getShader(gl.FRAGMENT_SHADER, frag);
var program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS))
alert("Could not initialise shaders");
return program;
}
function drawScene()
{
requestAnimFrame(drawScene);
fadeAndUploadData();
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.useProgram(shaderProgram);
gl.uniform1f(shaderProgram.tUniform, time);
gl.drawArrays(gl.POINTS, 0, 8 * 8 * 8);
var timeNow = new Date().getTime() * 0.001 - timeStart;
if (time != 0)
timeDelta = timeNow - time;
time = timeNow;
}
function resize()
{
gl.viewportWidth = canvas.width = window.innerHeight*0.70;
gl.viewportHeight = canvas.height = window.innerHeight*0.70;
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
}
function showdata()
{
requestAnimFrame = (function()
{
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback, element)
{
window.setTimeout(callback, 1000/30);
};
})();
canvas = document.getElementById("datacanvas");
canvas.onresize = resize;
var names = [ "webgl", "experimental-webgl", "moz-webgl", "webkit-3d" ];
for (var i = 0; i < names.length; i++)
{
try
{
gl = canvas.getContext(names[i]);
if (gl) break;
}
catch (e) { }
}
if (!gl)
alert("Could not initialise WebGL");
var vs = "attribute vec2 data;\n" +
"uniform float t;\n" +
"const mat4 p = mat4(\n" +
"1.0, 0, 0, 0,\n" +
"0, 1.0, 0, 0,\n" +
"0, 0, -10.01/9.99, -1,\n" +
"0, 0, -2.0*10.0*0.01/9.99, 1);\n" +
"varying mediump vec4 color;\n" +
"void main()\n" +
"{\n" +
"color = vec4(fract(data.x * vec3(1.0 / 512.0, 1.0 / 64.0, 1.0 / 8.0)), 1.0);\n" +
"float ct = cos(0.5 * t), st = sin(0.5 * t);\n" +
"mat4 m = mat4(ct, 0.0, -st, 0.0, 0.0, 1.0, 0.0, 0.0, st, 0.0, ct, 0.0, 0.2 * sin(t * 1.4), 0.2 * sin(t * 2.3), -1.0, 1.0);\n" +
"vec3 pos = fract(data.x * vec3(1.0 / 512.0, 1.0 / 64.0, 1.0 / 8.0));" +
"pos -= vec3(pos.yz / 8.0, 0.0);\n" +
"gl_Position = p * (m * vec4(2.0 * pos - vec3(1.0), 1.0));\n" +
"float z = gl_Position.z / gl_Position.w;\n" +
"gl_PointSize = clamp(2.0 + 20.0 * data.y * 0.005 * (1.0 - z), 1.0, 128.0);\n" +
"}\n";
var fs = "varying mediump vec4 color;\n" +
"void main()\n" +
"{\n" +
"mediump vec2 d = gl_PointCoord - vec2(0.5);\n" +
"mediump float l2 = dot(d, d);\n" +
"if (l2 > 0.25) discard;\n" +
"gl_FragColor = color * (1.0 - l2 * 4.0);\n" +
"}\n";
shaderProgram = loadProgram(vs, fs);
shaderProgram.dataAttribute = gl.getAttribLocation(shaderProgram, "data");
shaderProgram.tUniform = gl.getUniformLocation(shaderProgram, "t");
vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
fadeAndUploadData();
gl.enableVertexAttribArray(shaderProgram.dataAttribute);
gl.vertexAttribPointer(shaderProgram.dataAttribute, 2, gl.FLOAT, false, 0, 0);
//gl.enable(gl.DEPTH_TEST);
//gl.enable(gl.CULL_FACE);
//gl.cullFace(gl.BACK);
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE, gl.ONE);
timeStart = new Date().getTime() * 0.001;
resize();
drawScene();
}
</script>
</head>
<body onload="showdata();" style="background:black;color:white;font-family:monospace;">
<h1>ohai to pixelflut!</h1>
Pixelflut is a collaborative coding game. Project the pixelflut server output onto a wall where many people can see it. Connected clients can then set single pixels by sending a string like "PX [x] [y] [color]\n" (e.g. "PX 100 300 00FF42\n") to its TCP socket. Use netcat, python or whatever you want.<br><br>
Here you get this server: <a href="https://github.com/larsmm/pixelflut" style="color:#FF0000;">https://github.com/larsmm/pixelflut</a><br><br>
<h2>how to flut</h2>
Connect via TCP to this address/port and use the following commandz:
<ul>
<li><b>send pixel:</b> 'PX {x} {y} {GG or RRGGBB or RRGGBBAA as HEX}\n'</li>
<li><b>set offset for future pixels:</b> 'OFFSET {x} {y}\n'</li>
<li><b>request pixel:</b> 'PX {x} {y}\n'</li>
<li><b>request resolution:</b> 'SIZE\n'</li>
<li><b>request client connection count:</b> 'CONNECTIONS\n'</li>
<li><b>request this help message:</b> 'HELP\n'</li>
</ul>
Here some code examples: <a href="https://cccgoe.de/wiki/Pixelflut" style="color:#FF0000;">https://cccgoe.de/wiki/Pixelflut</a><br><br>
<h2>color map</h2>
Real-time usage of the RGB color space quantized to eight sections on each axis. You can <b>not</b> see the actual pixelflut image via http. This is only a color map of this image. You will find it somewhere on a wall or in jitsi.<br>
<canvas id="datacanvas" width="512" height="512" style="border: none;"></canvas><br>
</body>
</html>