forked from shabaz123/grid-eye
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
73 lines (72 loc) · 1.7 KB
/
Copy pathscripts.js
File metadata and controls
73 lines (72 loc) · 1.7 KB
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
(function() {
var App;
App = {};
/*
Init
*/
App.init = function() {
App.canvas = document.createElement('canvas');
App.canvas.height = 64*4;
App.canvas.width = 64*4;
document.getElementsByTagName('article')[0].appendChild(App.canvas);
App.ctx = App.canvas.getContext("2d");
App.ctx.fillStyle = "solid";
App.ctx.strokeStyle = "#ECD018";
App.ctx.lineWidth = 5;
App.ctx.lineCap = "round";
App.socket = io.connect();
App.socket.on('pixdata', function(data) {
var y=0;
var x=0;
for (var i=0; i<(64*64); i++)
{
var r=data[i][0];
var g=data[i][1];
var b=data[i][2];
var rgbval=data[i];
var rgbtxt='rgb('+r+','+g+','+b+')';
App.ctx.strokeStyle=rgbtxt;
App.ctx.fillStyle=rgbtxt;
App.ctx.fillRect(x*4, y*4, 4, 4);
x++;
if (x>63){
x=0;
y++;
}
}
return(0);
});
App.draw = function(x, y, type) {
if (type === "dragstart") {
App.ctx.beginPath();
return App.ctx.moveTo(x, y);
} else if (type === "drag") {
App.ctx.lineTo(x, y);
return App.ctx.stroke();
} else {
return App.ctx.closePath();
}
};
};
/*
Draw Events
*/
$('canvas').live('drag dragstart dragend', function(e) {
var offset, type, x, y;
type = e.handleObj.type;
offset = $(this).offset();
e.offsetX = e.layerX - offset.left;
e.offsetY = e.layerY - offset.top;
x = e.offsetX;
y = e.offsetY;
//App.draw(x, y, type);
//App.socket.emit('drawClick', {
// x: x,
// y: y,
// type: type
//});
});
$(function() {
return App.init();
});
}).call(this);