forked from gronnbeck/isomengine.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube.js
52 lines (48 loc) · 1.14 KB
/
cube.js
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
define(function () {
var top = function(cxt, x, y, size) {
cxt.fillStyle = cube.topStyle;
cxt.beginPath();
cxt.moveTo(x,y);
cxt.lineTo(x-size, y+size*0.5);
cxt.lineTo(x, y+size);
cxt.lineTo(x+size, y+size*0.5);
cxt.closePath();
cxt.fill();
cxt.stroke();
};
var left = function(cxt, x, y, size) {
cxt.fillStyle = cube.leftStyle;
cxt.beginPath();
cxt.moveTo(x,y);
cxt.lineTo(x, y+size);
cxt.lineTo(x+size, y+size*1.5);
cxt.lineTo(x+size, y+size*0.5);
cxt.closePath();
cxt.fill();
cxt.stroke();
};
var right = function(cxt, x, y, size) {
cxt.fillStyle = cube.rightStyle;
cxt.beginPath();
cxt.moveTo(x,y);
cxt.lineTo(x, y+size);
cxt.lineTo(x-size, y+size*1.5);
cxt.lineTo(x-size, y+size*0.5);
cxt.closePath();
cxt.fill();
cxt.stroke();
};
cube = {};
cube.strokeStyle = "#000";
cube.leftStyle = "#000";
cube.rightStyle = "#000";
cube.topStyle = "#000";
cube.POS = { 'x': 50, 'y': 0, 'z': 0 };
cube.draw = function(cxt, x, y, size) {
cxt.strokeStyle = cube.strokeStyle;
left(cxt, x-size, y-size*0.5, size);
right(cxt, x+size, y-size*0.5, size);
top(cxt, x, y-size, size);
};
return cube;
});