BFont f;
int numNode = 25;
Node[] node = new Node[numNode];
float rotY, rotX;
void setup()
{
size(600,600);
framerate(24);
f = loadFont("Futura-Medium.vlw.gz");
//=========== Draws Nodes ============
for (int i=0;i<numNode;i++)
{
node[i] = new Node();
}
//=========== End Nodes ============
}
void mouseDragged()
{
rotY += mouseX - pmouseX;
rotX += mouseY - pmouseY;
}
void loop()
{
textFont(f, 24);
background(220);
translate(width/2,height/2,0);
rotateY(-rotY*0.005);
rotateX(-rotX*0.005);
//=============== Draws Origin Box ====================
fill(255,0,0);
box(10);
push();
rotateX((-rotX*0.005)*-1);
push();
rotateY((-rotY*0.005)*-1);
fill(0);
text("Origin", 10, 0);
pop();
pop();
//================End Origin ==========================
drawGrid();
for (int i=0;i<numNode;i++) {
node[i].draw(i);
}
}
class Node {
int xpos = 0;
int ypos = 0;
int zpos = 0;
void draw(int Num) {
textFont(f, 14);
xpos = xpos + rand(2);
ypos = ypos + rand(2);
zpos = zpos + rand(2);
// push();
stroke(0,0,0);
line(xpos,ypos,zpos,0,0,0);
translate(xpos,ypos,zpos);
fill(255,255,0);
stroke(255,150,0);
box(10);
// pop();
push();
// translate(xpos,ypos,zpos);
rotateX((-rotX*0.005)*-1);
push();
rotateY((-rotY*0.005)*-1);
fill(0);
text(Num+1, 10, 0);
pop();
pop();
}
}
void drawGrid() {
//======= Y Axis =======
int c=0;
for(int y=-200; y<201; y=y+10) {
stroke(0,20);
c++;
beginShape(LINES);
vertex(200,y,0);
vertex(-200,y,0);
endShape();
}
//======= X Axis =======
c=0;
for(int x=-200; x<201; x=x+10) {
stroke(0,20);
c++;
beginShape(LINES);
vertex(x,200,0);
vertex(x,-200,0);
endShape();
}
}
int rand(int n) {
return int ((random(n) -1) *2);
}