0

I'm creating a 3d grid with the Isomer JS library and need help figuring out the logic for an incremental loop. Here is the Codepen:

https://codepen.io/anon/pen/wqwrzL

Javascript:

function draw() {
 var iso = new Isomer(document.getElementById("grid"));
 var Shape = Isomer.Shape;
 var Point = Isomer.Point;
 var Path = Isomer.Path;
 var Color = Isomer.Color;
 var cube = Shape.Prism(Point.ORIGIN);
 var white = new Color(255, 255, 255, 0.4);
 makeGrid(8, 8, 0, new Color(100, 100, 100, 0.6));
 for (x = 0; x < 8; x++) {
 iso.add(Shape.Prism(new Point(x, 0, 0), 1, 1, .5), white);
 }
 // GridMaker
 function makeGrid(xSize, ySize, zHeight, gridColor) {
 for (x = 0; x < xSize + 1; x++) {
 iso.add(new Path([
 new Point(x, 0, zHeight),
 new Point(x, xSize, zHeight),
 new Point(x, 0, zHeight)
 ]), gridColor);
 }
 for (y = 0; y < ySize + 1; y++) {
 iso.add(new Path([
 new Point(0, y, zHeight),
 new Point(ySize, y, zHeight),
 new Point(0, y, zHeight)
 ]), gridColor);
 }
 }
}

This snippet creates the solid blocks:

for (x = 0; x < 8; x++) {
 iso.add(Shape.Prism(new Point(x, 0, 0), 1, 1, .5), white);
 }

new Point() values are ordered: x, y, z. After every 8th iteration, I need the y value to increase by 1, which would start placing blocks on a new row. This should also happen 8 times, effectively filling the grid.

asked Jul 22, 2017 at 3:57
0

1 Answer 1

3
function draw() {
 var iso = new Isomer(document.getElementById("grid"));
 var Shape = Isomer.Shape;
 var Point = Isomer.Point;
 var Path = Isomer.Path;
 var Color = Isomer.Color;
 var cube = Shape.Prism(Point.ORIGIN);
 var white = new Color(255, 255, 255, 0.4);
 makeGrid(8, 8, 0, new Color(100, 100, 100, 0.6));
 for (x = 0; x < 8; x++) {
 for (y = 0; y < 8; y++) {
 iso.add(Shape.Prism(new Point(x, y, 0), 1, 1, .5), white);
 }
 }
 // GridMaker
 function makeGrid(xSize, ySize, zHeight, gridColor) {
 for (x = 0; x < xSize + 1; x++) {
 iso.add(new Path([
 new Point(x, 0, zHeight),
 new Point(x, xSize, zHeight),
 new Point(x, 0, zHeight)
 ]), gridColor);
 }
 for (y = 0; y < ySize + 1; y++) {
 iso.add(new Path([
 new Point(0, y, zHeight),
 new Point(ySize, y, zHeight),
 new Point(0, y, zHeight)
 ]), gridColor);
 }
 }
}
answered Jul 22, 2017 at 4:16
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.