3 <html lang=
"en" xmlns=
"http://www.w3.org/1999/xhtml">
5 <meta charset=
"utf-8" />
7 <style type=
"text/css">
9 background-color: #262926;
18 display: inline-block
;
21 background-color: #ff00ff;
28 <input id=
"offset-x" type=
"number" value=
"18" /></div>
30 <input id=
"offset-y" type=
"number" value=
"20" /></div>
32 <input id=
"skew-x" type=
"number" value=
"0" /></div>
34 <input id=
"skew-y" type=
"number" value=
"10" /></div>
36 <div id=
"color-1"></div>
37 <div id=
"color-2"></div>
38 <div id=
"color-3"></div>
39 <div id=
"color-4"></div>
42 <!-- Fullscreen canvas -->
43 <script type=
"text/javascript">
44 function fullscreenCanvas() {
45 var c
= window
.document
.createElement('canvas');
46 window
.document
.body
.appendChild(c
);
48 var ctx
= c
.getContext('2d');
50 ctx
.canvas
.width
= window
.innerWidth
;
51 ctx
.canvas
.height
= window
.innerHeight
;
52 ctx
.canvas
.style
.position
= 'absolute';
53 ctx
.canvas
.style
.top
= 0;
54 ctx
.canvas
.style
.left
= 0;
60 <script type=
"text/javascript">
64 var ctx
= fullscreenCanvas();
65 var cursor
= fullscreenCanvas();
66 cursor
.fillStyle
= cursor
.strokeStyle
= 'rgba(255, 255, 255, .7)';
68 var colors
= ['#304439', '#506a60', '#80aa89', '#d0ffd9'];
69 ctx
.fillStyle
= colors
[0];
71 colors
.forEach(function (color
, i
) {
72 var e
= document
.getElementById('color-' + (i
+ 1));
74 e
.style
.backgroundColor
= colors
[i
];
75 var color
= colors
[i
];
77 e
.addEventListener('mousedown', function () { ctx
.fillStyle
= color
});
85 function bind(id
, callback
) {
86 var e
= document
.getElementById(id
);
88 var fn = function () {
89 callback(parseInt(e
.value
, 10));
92 e
.addEventListener('keyup', fn
);
93 e
.addEventListener('mouseup', fn
);
96 bind('offset-x', function (val
) { deltax
= val
});
97 bind('offset-y', function (val
) { deltay
= val
});
98 bind('skew-x', function (val
) { skewx
= val
});
99 bind('skew-y', function (val
) { skewy
= val
});
104 function addPoint(x
, y
) {
107 if (mouseDown
> 0) down
= next
;
112 function downAt(x
, y
) {
117 function putCursor(x
, y
) {
121 var a
= (size
/ 2) | 0;
126 for (var i
= -dx
; i
<= dx
; ++i
) {
127 for (var j
= -dy
; j
<= dy
; ++j
) {
128 if (i
== 0 && j
== 0) continue;
130 var p
= x
+ i
* size
* deltax
+ a
- j
* size
* skewx
;
131 var q
= y
+ j
* size
* deltay
+ a
- i
* size
* skewy
;
133 cursor
.fillRect(p
, q
, 1, 1);
137 cursor
.strokeRect(x
+ .5, y
+ .5, size
- 1, size
- 1);
140 function draw(x
, y
) {
147 for (var i
= -dx
; i
<= dx
; ++i
) {
148 for (var j
= -dy
; j
<= dy
; ++j
) {
150 var p
= x
+ i
* size
* deltax
- j
* size
* skewx
;
151 var q
= y
+ j
* size
* deltay
- i
* size
* skewy
;
153 ctx
.fillRect(p
, q
, size
, size
);
165 cursor
.clearRect(0, 0, cursor
.canvas
.width
, cursor
.canvas
.height
);
166 putCursor(next
[0], next
[1]);
171 draw(down
[0], down
[1]);
175 window
.requestAnimationFrame(frame
);
178 window
.requestAnimationFrame(frame
);
180 cursor
.canvas
.addEventListener('mousemove', function (e
) { addPoint(e
.clientX
, e
.clientY
) });
181 cursor
.canvas
.addEventListener('mousedown', function (e
) { downAt(e
.clientX
, e
.clientY
) });
182 cursor
.canvas
.addEventListener('mouseup', function (e
) { --mouseDown
; });
183 cursor
.canvas
.addEventListener('mouseout', function (e
) { mouseDown
= 0; });