import times from 'lodash.times';
export default function Grid(cols, rows, step, color, scene) {
	const grid ={
		render() {
			const {screen, scale} = scene;
			screen.save();
				screen.pen = {
					strokeStyle: color,
					lineWidth: 1/scale
				};

				// Vertical guides
				screen.save();
				screen.translate({x: .5/scale, y: .5/scale});
				times(cols, () => {
					screen.translate({x: step, y: 0});
					screen.drawLine({x: 0, y: 0}, {x: 0, y: rows*step});
				});
				screen.restore();

				// Horizontal guides
				screen.save();
				times(rows, () => {
					screen.translate({x: 0, y: step});
					screen.drawLine({x: 0, y: 0}, {x: cols*step, y: 0});
				});
				screen.restore();

			screen.restore();
		}
	}
	scene.add(grid);
	return grid;
}

@@ -1,8 +1,95 @@
+import SceneObject from 'graphics/scene-object';%0A%0Aimport %7BEventEmitter%7D from 'events';%0A
 import t
@@ -114,16 +114,17 @@
 times';%0A
+%0A
 export d
@@ -171,100 +171,107 @@
 olor
-, scene) %7B%0A%09const grid =
+) %7B%0A%09return SceneObject(
 %7B%0A%09%09
-render() %7B%0A%09%09%09const %7Bscreen, scale%7D = scene;%0A%09%09%09screen.save();%0A%09
+zIndex: -Infinity,%0A%09%09emitter: new EventEmitter(),%0A%09%09onRender(screen) %7B%0A
 %09%09%09s
@@ -288,17 +288,16 @@
 = %7B%0A%09%09%09%09
-%09
 strokeSt
@@ -312,17 +312,16 @@
 or,%0A%09%09%09%09
-%09
 lineWidt
@@ -329,23 +329,18 @@
 : 1/
-scale
+16
 %0A%09%09%09
-%09
 %7D;%0A%0A
-%09
 %09%09%09/
@@ -349,33 +349,32 @@
 Vertical guides%0A
-%09
 %09%09%09screen.save()
@@ -374,25 +374,24 @@
 .save();%0A%09%09%09
-%09
 screen.trans
@@ -406,21 +406,18 @@
  .5/
-scale
+16
 , y: .5/
 scal
@@ -416,18 +416,14 @@
  .5/
-scale
+16
 %7D);%0A
-%09
 %09%09%09t
@@ -437,33 +437,32 @@
 ls, () =%3E %7B%0A%09%09%09%09
-%09
 screen.translate
@@ -476,25 +476,24 @@
 ep, y: 0%7D);%0A
-%09
 %09%09%09%09screen.d
@@ -533,25 +533,24 @@
 ows*step%7D);%0A
-%09
 %09%09%09%7D);%0A%09%09%09%09s
@@ -539,33 +539,32 @@
 ep%7D);%0A%09%09%09%7D);%0A%09%09%09
-%09
 screen.restore()
@@ -566,17 +566,16 @@
 ore();%0A%0A
-%09
 %09%09%09// Ho
@@ -589,25 +589,24 @@
 l guides%0A%09%09%09
-%09
 screen.save(
@@ -608,17 +608,16 @@
 save();%0A
-%09
 %09%09%09times
@@ -631,25 +631,24 @@
 () =%3E %7B%0A%09%09%09%09
-%09
 screen.trans
@@ -670,17 +670,16 @@
 step%7D);%0A
-%09
 %09%09%09%09scre
@@ -734,36 +734,12 @@
 %0A%09%09%09
-%09
 %7D);%0A
-%09%09%09%09screen.restore();%0A%0A
 %09%09%09s
@@ -765,39 +765,9 @@
 %7D%0A%09%7D
-%0A%09scene.add(grid);%0A%09return grid
+)
 ;%0A%7D%0A

fix grid object