-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor-flood.js
66 lines (57 loc) · 1.83 KB
/
color-flood.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
var canvas = document.getElementById('2dgrid');
var isoCanvas = document.getElementById('3dgrid');
var TOP_COLOR = 0;
var LEFT_COLOR = 1;
var RIGHT_COLOR = 2;
var colorsHash = {
'A' : ['#655643'],
'B' : ['#80BCA3'],
'C' : ['#F6F7BD'],
'D' : ['#E6AC27'],
'E' : ['#BF4D28']
};
var colors = [];
for (var color in colorsHash) {
if (colorsHash.hasOwnProperty(color)) {
var leftColor = toLeftColor(colorsHash[color][TOP_COLOR]);
var rightColor = toRightColor(colorsHash[color][TOP_COLOR]);
colorsHash[color].push(leftColor);
colorsHash[color].push(rightColor);
colors.push(color);
}
}
var grid1 = new Grid(10,10,colors, canvas, isoCanvas);
function initButtons() {
for (var localColor in colorsHash) {
if (colorsHash.hasOwnProperty(localColor)) {
var button = _addElement(document.body, 'button', {id: localColor});
button.appendChild(document.createTextNode(localColor));
button.style.background = colorsHash[localColor][0];
button.onclick = function (closureColor) {
return function () {
grid1.changeColor(closureColor);
}
}(localColor);
}
}
}
initButtons();
grid1.draw();
grid1.draw3dGrid();
function valueBetween(value, min, max) {
return Math.max(min, Math.min(max, value));
}
isoCanvas.addEventListener('mousemove', function (e) {
if (e.buttons === 1) {
if (e.ctrlKey) {
origin.x += e.movementX;
origin.y += e.movementY;
grid1.draw3dGrid();
} else {
zHorizontalAngle = valueBetween(zHorizontalAngle - e.movementY / 100, 0, Math.PI/2);
zRotationAngle = valueBetween(zRotationAngle - e.movementX / 100, 0, Math.PI/2);
grid1.draw3dGrid();
}
}
});