Permalink
Browse files

Makes a new testbed, add some docs, and a new RenderType. Beginnings …

…of handling different directions of side rendering.
  • Loading branch information...
pforhan committed Aug 30, 2015
1 parent ea49c5f commit 7b67378c0bfaae60cb8f330f1c8b815e19f6b934
@@ -8,7 +8,9 @@
public int left;
public int top;
public int size;
/** Horizontal space to use to indicate height. */
public int hDepth;
/** Vertical space to use to indicate height. */
public int vDepth;
public Color color;
public Color darkerColor;
@@ -8,7 +8,14 @@
public class Projections {
public static final List<Projection> PROJECTIONS =
Arrays.asList(new Cabinet(), new Cabinet(-5, -5), new Flat(), new PseudoPerspective());
Arrays.asList(
new Cabinet(),
new Cabinet(-5, -5),
new Cabinet(-5, 5),
new Cabinet(5, 5),
new Cabinet(5, -5),
new Flat(),
new PseudoPerspective());
public static Projection next(Projection current) {
int nextIdx = PROJECTIONS.indexOf(current) + 1;
@@ -21,7 +21,91 @@
import wannabe.grid.SimpleGrid;
public class SampleGrids {
/** Grid stretching 30x30 with pixels every 10 along the edge, and 600 random pixels. */
public static final class ColumnColorStairs implements Path {
private final int xIncrement;
private final int yIncrement;
private final Position start;
private final int[] colors;
public ColumnColorStairs(int xIncrement, int yIncrement, Position start, int... colors) {
this.xIncrement = xIncrement;
this.yIncrement = yIncrement;
this.start = start;
this.colors = colors;
}
@Override public Position start() {
return start.clone();
}
@Override public Position drawAndMove(MutableGrid grid, Position pos) {
Position lineEnd = new Position(pos.x, pos.y, 0);
line(grid, pos, lineEnd, getColor(pos));
pos.x += xIncrement;
pos.y += yIncrement;
pos.z++;
return pos.z == 6 ? null : pos;
}
private int getColor(Position pos) {
int offset = Math.abs(pos.x - start.x);
if (offset == 0) {
offset = Math.abs(pos.y - start.y);
}
if (offset >= colors.length) offset = colors.length - 1;
return colors[offset];
}
}
/**
* TODO figure out if this is viable. Need some way of iteratively creating data.
* Can I clean up? Can I make an Iterable?
*/
interface Path {
Position start();
Position drawAndMove(MutableGrid grid, Position pos);
}
/** Simple stairs on x or y axis that may vary in color by height. */
public static final class HeightColorStairs implements Path {
private final int xIncrement;
private final int yIncrement;
private final int[] colors;
private final Position start;
private final Position endXY;
public HeightColorStairs(int xIncrement, int yIncrement, Position start, Position endXY,
int... colors) {
this.start = start;
this.endXY = endXY;
this.xIncrement = xIncrement;
this.yIncrement = yIncrement;
this.colors = colors;
}
@Override public Position start() {
return start.clone();
}
@Override public Position drawAndMove(MutableGrid grid, Position pos) {
Position lineEnd = new Position(endXY.x, endXY.y, pos.z);
line(grid, pos, lineEnd, getColor(pos));
pos.x += xIncrement;
pos.y += yIncrement;
pos.z++;
return pos.z == 6 ? null : pos;
}
private int getColor(Position pos) {
if (colors.length == 0) return 0x888888;
int offset = pos.z;
if (offset >= colors.length) offset = colors.length - 1;
return colors[offset];
}
}
/** Grid stretching 30x30 with voxels every 10 along the edge, and 600 random voxels. */
public static Grid randomGrid() {
MutableGrid grid = new SimpleGrid("random sparse 30x30");
grid.add(new Voxel(0, 0, 0, 0xFFEEDD));
@@ -42,6 +126,50 @@ public static Grid randomGrid() {
return grid;
}
/** Grid stretching 30x30 with voxels in simple patterns like stairsteps, etc */
public static Grid testBed() {
MutableGrid grid = new SimpleGrid("testbed 30x30");
// First set of steps: single color stairs to floor.
Position start = new Position(5, 5, 0);
drawPath(grid,
new HeightColorStairs(1, 0, start, new Position(10, 5, 0), 0xFFEEDD));
drawPath(grid,
new HeightColorStairs(0, 1, start, new Position(5, 10, 0), 0xFFEEDD));
drawPath(grid,
new HeightColorStairs(-1, 0, start, new Position(0, 5, 0), 0xFFEEDD));
drawPath(grid,
new HeightColorStairs(0, -1, start, new Position(5, 0, 0), 0xFFEEDD));
// Second set of steps: color varies by height
int[] stairColors = {0xDFFEED, 0xDEEEED, 0xDDDEED, 0xDCCEED, 0xDBBEED, 0xDAAEED};
start = new Position(20, 5, 0);
drawPath(grid,
new HeightColorStairs(1, 0, start, new Position(25, 5, 0), stairColors));
drawPath(grid,
new HeightColorStairs(0, 1, start, new Position(20, 10, 0), stairColors));
drawPath(grid,
new HeightColorStairs(-1, 0, start, new Position(15, 5, 0), stairColors));
drawPath(grid,
new HeightColorStairs(0, -1, start, new Position(20, 0, 0), stairColors));
// Third set of steps: color varies by column
stairColors = new int[] {0xFEEDDF, 0xEEEDDE, 0xDEEDDD, 0xCEEDDC, 0xBEEDDB, 0xAEEDDA};
start = new Position(5, 20, 0);
drawPath(grid, new ColumnColorStairs(1, 0, start, stairColors));
drawPath(grid, new ColumnColorStairs(0, 1, start, stairColors));
drawPath(grid, new ColumnColorStairs(-1, 0, start, stairColors));
drawPath(grid, new ColumnColorStairs(0, -1, start, stairColors));
return grid;
}
private static void drawPath(MutableGrid grid, Path path) {
Position pos = path.start();
while (pos != null) {
pos = path.drawAndMove(grid, pos);
}
}
public static Grid cube(int size, int color) {
MutableGrid grid = new SimpleGrid("cube of size " + size);
@@ -471,6 +599,7 @@ public static FrameAnimatedGrid megaManRunning() {
public static final List<Grid> GRIDS = Collections.unmodifiableList(Arrays.asList(
heightMap("heightMap 256x256", false),
testBed(),
linkGrid(),
heightMap("deep heightmap 256x256", true),
cloudySky(),
@@ -28,16 +28,60 @@
},
filledThreeDSquareWithCabinetSides {
@Override void draw(Graphics g, Rendered r) {
int bottom = r.top + r.size;
int right = r.left + r.size;
if (r.hDepth < 0) {
// Height indicated by drawing to the left of the face.
if (r.vDepth < 0) {
// Height indicated by drawing above-left the face. TODO finish
} else {
// Height indicated by drawing below-left the face. TODO finish
}
} else {
// Height indicated by drawing to the right of the face.
if (r.vDepth < 0) {
// Height indicated by drawing above-right the face. TODO finish
} else {
// Height indicated by drawing below-right the face.
// From bottom-left:
g.drawLine(r.left, bottom, r.left + r.hDepth, bottom + r.vDepth);
// From bottom-right:
g.drawLine(right , bottom, right + r.hDepth, bottom + r.vDepth);
// From top-right
g.drawLine(right, r.top, right + r.hDepth, r.top + r.vDepth);
}
}
g.fill3DRect(r.left, r.top, r.size, r.size, true);
}
},
filledSquareWithCabinetSides {
@Override void draw(Graphics g, Rendered r) {
int bottom = r.top + r.size;
int right = r.left + r.size;
// TODO need to handle cases where I need to draw from any set of corners.
// From bottom-left:
g.drawLine(r.left, bottom, r.left + r.hDepth, bottom + r.vDepth);
// From bottom-right:
g.drawLine(right , bottom, right + r.hDepth, bottom + r.vDepth);
// From top-right
g.drawLine(right, r.top, right + r.hDepth, r.top + r.vDepth);
if (r.hDepth < 0) {
// Height indicated by drawing to the left of the face.
if (r.vDepth < 0) {
// Height indicated by drawing above-left the face. TODO finish
} else {
// Height indicated by drawing below-left the face. TODO finish
}
} else {
// Height indicated by drawing to the right of the face.
if (r.vDepth < 0) {
// Height indicated by drawing above-right the face. TODO finish
} else {
// Height indicated by drawing below-right the face.
// From bottom-left:
g.drawLine(r.left, bottom, r.left + r.hDepth, bottom + r.vDepth);
// From bottom-right:
g.drawLine(right , bottom, right + r.hDepth, bottom + r.vDepth);
// From top-right
g.drawLine(right, r.top, right + r.hDepth, r.top + r.vDepth);
}
}
g.fillRect(r.left, r.top, r.size, r.size);
}
},
pixel {

0 comments on commit 7b67378

Please sign in to comment.