Skip to content

Instantly share code, notes, and snippets.

@Synvox
Created July 18, 2013 18:57
Show Gist options
  • Save Synvox/6031979 to your computer and use it in GitHub Desktop.
Save Synvox/6031979 to your computer and use it in GitHub Desktop.
For Robbie
float scale = 50; // Each block is 1m big which translates to 50 3d units.
class Block
{
int x;
int y;
int z;
Block(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
void draw() {
pushMatrix();
translate(x * scale, y * scale, z * scale);
box(scale);
popMatrix();
}
}
class World
{
ArrayList<Block> blocks;
PVector view;
World() {
blocks = new ArrayList<Block>();
for(int x = -5; x <= 5; x++)
for(int y = -5; y <= 5; y++) {
int z = (int)(noise(x,y)*10);
blocks.add(new Block(x,y,z));
}
view = new PVector(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0));
}
void draw() {
background(100);
stroke(0, 0, 0);
fill(255, 255, 255);
lights();
shininess(5.0);
camera(view.x,view.y,view.z, width/2.0, height/2.0, 0, 0, 1, 0);
translate(50, 50, 0);
rotateX(-PI/6);
rotateY(PI/3);
// count from 0 to the end of the list of blocks and draw them.
for(int i = 0; i < blocks.size(); i++){
blocks.get(i).draw();
}
}
}
World world;
void setup()
{
world = new World();
size(800, 600, OPENGL);
noiseDetail(0,0.65);
}
void draw()
{
world.draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment