Reloading the page dont't causes image lost anymore
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
var canvas_size_y = 100;
|
||||
|
||||
socket.on('setting', onSetting);
|
||||
socket.on('drawn', onDrawn);
|
||||
socket.on('draw', onDraw);
|
||||
socket.on('stats', onStats);
|
||||
|
||||
@@ -51,12 +52,11 @@
|
||||
}
|
||||
|
||||
function drawPixel(x, y, color){
|
||||
context.fillStyle = color;
|
||||
context.fillStyle = '#' + color;
|
||||
context.fillRect(x - (canvas.width * (0.5/canvas_size_x)),y - (canvas.height * (0.5/canvas_size_y)), canvas.width * (1/canvas_size_x), canvas.height * (1/canvas_size_y));
|
||||
}
|
||||
|
||||
function onDraw(data){
|
||||
console.log(data);
|
||||
var w = canvas.width;
|
||||
var h = canvas.height;
|
||||
if (data.type == 'pixel') {
|
||||
@@ -64,6 +64,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
function onDrawn(data){
|
||||
console.log(data);
|
||||
var w = canvas.width;
|
||||
var h = canvas.height;
|
||||
data.forEach(function (d, x){
|
||||
if (d !== null) {
|
||||
d.forEach(function (c, y) {
|
||||
if (c !== null) {
|
||||
drawPixel((x / canvas_size_x) * w, (y / canvas_size_y) * h, c);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onStats(data) {
|
||||
stats.innerHTML = 'px/s: ' + data.pixel + ' connections: ' + data.connections;
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ html, body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.display {
|
||||
@@ -16,12 +17,13 @@ html, body {
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
top: 0;
|
||||
background-color: #000000;
|
||||
}
|
||||
|
||||
.stats {
|
||||
z-index: 100;
|
||||
position: absolute;
|
||||
background-color: #00000022;
|
||||
background-color: #333333aa;
|
||||
padding: 3px;
|
||||
left: 10px;
|
||||
bottom: 10px;
|
||||
@@ -30,7 +32,7 @@ html, body {
|
||||
.play {
|
||||
z-index: 100;
|
||||
position: absolute;
|
||||
background-color: #00000022;
|
||||
background-color: #333333aa;
|
||||
padding: 3px;
|
||||
left: 10px;
|
||||
right: 10px;
|
||||
|
Reference in New Issue
Block a user