Skip to content
Permalink
Browse files

Adds plotting infrastructure, more projection configs

  • Loading branch information...
pforhan committed Aug 30, 2015
1 parent 7b67378 commit 5c72fcf36f3d78d08830c73af81aa14c9217c8a4
@@ -9,7 +9,10 @@

public static final List<Projection> PROJECTIONS =
Arrays.asList(
new Cabinet(),
new Cabinet(-1, -1),
new Cabinet(-1, 1),
new Cabinet(1, 1),
new Cabinet(1, -1),
new Cabinet(-5, -5),
new Cabinet(-5, 5),
new Cabinet(5, 5),
@@ -22,6 +22,25 @@

public class SampleGrids {

/**
* 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);
}

/**
* TODO does it make sense to restrict to x, y inputs? And when I make it generic this way,
* I bet there's better function interfaces out there...
* It may be worth letting the plotter plot voxels directly, could make more accurate color
* decisions... or could plot multiple points. This reduces capability to a single scalar.
*/
interface Plotter {
int plot(int x, int y);
}

public static final class ColumnColorStairs implements Path {
private final int xIncrement;
private final int yIncrement;
@@ -58,15 +77,6 @@ private int getColor(Position pos) {
}
}

/**
* 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;
@@ -170,6 +180,43 @@ private static void drawPath(MutableGrid grid, Path path) {
pos = path.drawAndMove(grid, pos);
}
}

/** Plot of an exaggerated sine. Note that for pleasing results, the origin is shifted. */
public static Grid plotSin(final int mulitplyer) {
// TODO at low multiplyers the colors aren't distinct enough.
MutableGrid grid = new SimpleGrid("Sine plot x" + mulitplyer + " 40x40");
Plotter plotter = new Plotter() {
@Override public int plot(int x, int y) {
double distanceFromOrigin = Math.hypot(x, y);
return (int) (mulitplyer * (Math.sin(distanceFromOrigin)));
}
};
plot(grid, plotter);
return grid;
}

/** Plot of a flattened hyperbola. Note that for pleasing results, the origin is shifted. */
public static Grid plotHyperbola(final double d) {
MutableGrid grid = new SimpleGrid("Hyperbola x" + d + " 40x40");
Plotter plotter = new Plotter() {
@Override public int plot(int x, int y) {
double distanceFromOrigin = Math.hypot(x, y);
return (int) (d * distanceFromOrigin * distanceFromOrigin);
}
};
plot(grid, plotter);
return grid;
}

private static void plot(MutableGrid grid, Plotter plotter) {
for (int x = 0; x < 40; x++) {
for (int y = 0; y < 40; y++) {
int height = plotter.plot(x - 20, y - 20);
grid.add(new Voxel(x, y, height, 0x888888 + height * 10));
}
}
}

public static Grid cube(int size, int color) {
MutableGrid grid = new SimpleGrid("cube of size " + size);

@@ -180,11 +227,10 @@ public static Grid cube(int size, int color) {
Position br = new Position(size, size, 0);
line(grid, tl, tr, color);
line(grid, bl, br, color);
// TODO this duplicates some voxels!
line(grid, tl, bl, color);
line(grid, tr, br, color);

// Risers:
// Risers: TODO just draw with line() method
for (int z = 1; z < size; z++) {
tl.z = z;
tr.z = z;
@@ -600,6 +646,9 @@ public static FrameAnimatedGrid megaManRunning() {
public static final List<Grid> GRIDS = Collections.unmodifiableList(Arrays.asList(
heightMap("heightMap 256x256", false),
testBed(),
plotSin(5),
plotSin(2),
plotHyperbola(.2),
linkGrid(),
heightMap("deep heightmap 256x256", true),
cloudySky(),

0 comments on commit 5c72fcf

Please sign in to comment.
You can’t perform that action at this time.