We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Voxels
Page Index Toggle Pages: 1
Voxels (Read 1439 times)
Voxels
Apr 9th, 2010, 3:19pm
 
I was reading about voxels and decided to make this.
Code:

import processing.opengl.*;
float a;
int Size=20;

int[][][][] voxel=new int[Size][Size][Size][4];

void setup(){
size(400,400,OPENGL);
smooth();
noStroke();
frameRate(30);
}

void draw(){
background(100);
for(int x=0;x<Size/2;x++){
for(int y=0;y<Size/2;y++){
for(int z=0;z<Size/2;z++){
if(voxel[x][y][z][0]==1){
fill(voxel[x][y][z][1],voxel[x][y][z][2],voxel[x][y][z][3]);
pushMatrix();
translate(width/2,height/2);
rotateY(a);
rotateX(a);
translate((x-Size/4)*15,(y-Size/4)*15,(z-Size/4)*15);
box(15);
popMatrix();
if(random(0,100)>99){
voxel[x][y][z][0]=0;
}
}
else{
if(random(0,100)>99){
voxel[x][y][z][0]=1;
voxel[x][y][z][1]=10*x+150;
voxel[x][y][z][2]=10*y+150;
voxel[x][y][z][3]=10*z+150;

}
}

}
}
}
a=a+.01;
}



Re: Voxels
Reply #1 - Apr 9th, 2010, 4:58pm
 
Nice one!
Re: Voxels
Reply #2 - Apr 10th, 2010, 4:04pm
 
I've done quite similar one with some interactions(here)
Re: Voxels
Reply #3 - Apr 12th, 2010, 3:09am
 
Nice!
Small hint (for all): If you use the menu "Copy for Discourse" in Processing, you can copy&paste code-snippets with nice color-formating into the forum. It took me a while (and another post somewhere in the forum) for learning it myself, so I thought I re-teach it.  Wink
Page Index Toggle Pages: 1