Hi there,
I am writing a program to draw some white squares in 3D space and I would like that, where they intersect, a black line is shown. I can’t find an easy way to do that.
However, if I use different colors for the squares, the lines I want to draw appear between the colors like in the image below.
Can anyone help me find an easy solution?
Thank you very much!
float x,y,z,a,b ;
int num = 50 ;
int side = 500;
int imax = 0;
float y0 = 2./3;
int radius;
int previousDisplayTime; // Keep track of the last time a frame of the animation was displayed
int deltaTime;
boolean sense = true;
boolean pause = false;
void setup() {
size(1000,1000,P3D);
lights();
//ortho();
y0 = height;///2+side/2;
println(y0);
x = width/2;
y = y0;
z = 0;
a = 0;
b = 0;
directionalLight(255, 255, 255, 0, -1, -1);
deltaTime = 100;
previousDisplayTime = 0;
//float fov = PI/2;
//float cameraZ = (4000) / tan(fov/2.0);
//perspective(fov, float(width)/float(height),
// cameraZ/10.0, cameraZ*10.0);
}
void draw() {
radius = side + mouseX;
//lights();
//stroke(220);
stroke(255*1/4);
//noStroke();
background(220, 220, 220);
//background(255);
//fill(255, 0, 0, 10);
camera(//width, 0, width/3, // eyeX, eyeY, eyeZ
width/2-10*width/4, height/2-10*width/4, radius-10*width/4,
0, 0, 0,
//3*width/4, width/4, width/8, // centerX, centerY, centerZ
0.0, 1.0, 0.0);
perspective(PI/3.0, float(width)/float(height), mouseX, 10*radius-100*width/4);//1, 25*radius);
if ((millis() > previousDisplayTime + deltaTime) & sense & !pause) {
imax++;
if (imax > num) {
sense = false;
}
previousDisplayTime = millis();
}
if ((millis() > previousDisplayTime + deltaTime) & !sense & !pause) {
imax--;
if (imax < 0) {
sense = true;
}
previousDisplayTime = millis();
}
for (int i=0; i < imax; i++) {
x = radius * cos(i*2*PI/num);
y = radius * sin(i*2*PI/num);
drawSheet(i);
//y-=side/(num-1); // The rectangle moves forward as z increments.
a+=0.02*mouseX/width*20;
b+=0.02*mouseY/width*20;
}
a = 0;
b = 0;
y = y0;
x=width/2;
}
void mousePressed() {
pause = !pause;
}
void drawSheet(int i) {
pushMatrix();
translate(x,y,0);
rectMode(CENTER);
fill(255, random(255), random(255));
//rotateX(-PI/6);
//rotateY(PI/3);
rotateX(PI/2);
rotateY(2*PI/num*i);
rotateZ(a);
rotateY(b);
rect(0,0,side,side);
popMatrix();
}