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
Joe Berthelot
7354 gold badges17 silver badges33 bronze badges
1 Answer 1
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);
}
}
}
Sign up to request clarification or add additional context in comments.
Comments
lang-js