xxxxxxxxxx
int cpti = 0; int cptj = 0; int cptk = 0; int cpt3 = 0;
float side ; int carre ; int cube ; float cote; float c;
float ixe0 ; float igrec0 ; float zed0 ; float ixe3 ; float igrec3 ; float zed3 ;
float ixa; float iga; float za;
PFont myFont;
float ixe1[] ; float ygrec1[] ; float zed1[] ; float ixe2[] ; float ygrec2[] ; float zed2[] ;
int nbCube ;
import processing.opengl.*;
void setup() {
size(400,420, OPENGL);
background(255);
strokeWeight(1);
cote = int(width/2); c = cote/2 ;
myFont = createFont("Arial-BoldMT-48.vlw", 10);
}
void draw() {
textFont(myFont, 14); fill(0, 200, 0); text( "Ridge line of the cube of " +str(nbCube), 40 , 10, 0 ) ;
textFont(myFont, 12); fill(0,0,200); text(" cubes places on boustrophedon path", 40, 35 , 0 );
fill(250,0,0); text(" cubes places on usual path" , 40, 55 , 0 );
translate( width/1.3 , height/1.5 , -80); rotateY( -PI/6 );
}
void mouseReleased() {
background(255);
// nbCube = int(mouseX /20) ;
if( int(mouseX /20) %2 == 0) { nbCube = int(mouseX /20) +1 ;}
else {nbCube = int(mouseX /20) ; }
side = cote/nbCube;
/////////////////////////////////////////////////////////////////////////////////////////// starting boustrophedon course
ixe0 = c; igrec0= c ; zed0 = -c;
ixe1 = new float[nbCube+1]; ygrec1 = new float[nbCube+1]; zed1 = new float[nbCube+1];
ixe2 = new float[nbCube+1]; ygrec2 = new float[nbCube+1]; zed2 = new float[nbCube+1];
for(int ig = 0; ig < nbCube; ig++) {
for(int ix = 0; ix < nbCube; ix++) {
if( ig % 2 != 0 ) { ixa = (nbCube-1) - ix ; } // odd layer if ig is odd
else { ixa = ix ; } // even layer
for(int z = 0; z < nbCube; z++) {
cpt3 = cpt3+1;
if( nbCube % 2 == 0) { // even cube
if( ix % 2 != 0 ) { za = (nbCube-1) - z ; } // even layer , odd line
else { za = z ; } // even line
}
if( nbCube % 2 != 0 ) { // odd cube
if( ig %2 == 0 && ix % 2 == 0 ) { za = z ; } // odd layer , even line
if( ig %2 == 0 && ix % 2 != 0 ) { za = (nbCube-1) - z ; }
if( ig %2 != 0 && ix % 2 == 0) { za = (nbCube-1) - z ; }
if( ig %2 != 0 && ix % 2 != 0) { za = z ; }
}
//strokeWeight(1); line(-side * ixa +c , -side*ig +c , side *za -c, ixe0, igrec0, zed0 ); // drawing the course
ixe0 = -side * ixa +c ; igrec0= -side*ig +c ; zed0 = side*za- c;
for(int c = 1; c <=nbCube; c++) {
if( cpt3 == c*c*c) { // looking for the cubes of the numbers
//between 1 and nbCube
//fill(0,0,255); textFont(myFont, 20) ; text(cpt3, ixe0 +10, igrec0 -10, zed0); // displaying values
stroke(0,0,255); strokeWeight(6); point( ixe0, igrec0, zed0); // displaying blue dots
ixe1[c-1] = ixe0 ; ygrec1[c-1] = igrec0 ; zed1[c-1] = zed0; // nbCube array, boustro way
}
}
} //za
} //ixa
} //ig
///////////////////////////////////////////////////////////////////////////////////// ending boustro
cpt3 = 0 ;
//////////////////////////////////////////////////////////////////////////////////// starting usual way
ixe0 = c ; igrec0 = c ; zed0 = -c ;
ixe3 = c ; igrec3 = c ; zed3 = -c ;
for(int ig = 0; ig < nbCube; ig++) {
for(int ix = 0; ix < nbCube; ix++) {
for(int z = 0; z < nbCube; z++) {
cpt3 = cpt3+1;
ixe0 = -side*ix +c ; igrec0 = -side*ig +c ; zed0 = side*z- c; // dots coordinates
for(int c = 1; c <=nbCube; c++) { // looking for the cubes of the first numbers between 1 and nbCube
if( cpt3 == c*c*c) { //cube
//fill(255,0,0); textFont(myFont, 20) ; text(cpt3, ixe0 +2 +10, igrec0-10, zed0); // displaying values
stroke(255,0,0);strokeWeight(6); point( ixe0 +2, igrec0, zed0); // displaying red dots
ixe2[c-1] = ixe0 ; ygrec2[c-1] = igrec0 ; zed2[c-1] = zed0 ; //first nbCube array, usual way
if( ixe2[c-1] == ixe1[c-1] && ygrec2[c-1] == ygrec1[c-1] && zed2[c-1] == zed1[c-1] ) { // looking for common values between usual and boustro ways
fill(0, 180, 0); textFont(myFont, 20); text(cpt3, ixe1[c-1] +3, ygrec1[c-1] , zed1[c-1]) ; // displaying common values
stroke(0,180,0);strokeWeight(3);
line(ixe3, igrec3, zed3, ixe1[c-1], ygrec1[c-1] , zed1[c-1] ) ; // drawing ridge line of the cube
ixe3 = ixe1[c-1] ; igrec3 = ygrec1[c-1] ; zed3 = zed1[c-1] ;
}
}
}
} //z
} //ix
} //ig
////////////////////////////////////////////////////////////////////////////////////////////////////// eending usual way
textFont(myFont, 18); fill(0);
//text( str(nbCube), side*nbCube , side*nbCube, side*nbCube ) ; // displaying side value (nbCube),
//text( "1", side*nbCube +3 , side*nbCube , -side*nbCube ) ; //displaying the 1
//text( str(nbCube*nbCube*nbCube), -cote -10 , -cote , + cote ); // the cube
//text( str(nbCube*nbCube), -cote -10 , cote , + cote ); // the square
translate(-width/4 , -height/8 , 0); //translate(side/2, side/2, -side/2);
stroke(0); strokeWeight(2); noFill(); box(nbCube*side);
//save("dorsale de "+nbCube+".tif"); // save the drawing
cpt3 = 0;
for(int c = 1; c <=nbCube; c++) { // delete values in arrays
ixe1[c-1] = 0 ; ygrec1[c-1] = 0 ; zed1[c-1] = 0 ;
ixe2[c-1] = 0 ; ygrec2[c-1] = 0 ; zed2[c-1] = 0 ;
}
/* // drawing the boustro course
if(z == nbCube-1 && ig == 0 ) { fill(0,0,200); textFont(myFont, 18);
text( cpt3, -side*ix +c , -side*ig +c +15 , side*z -c +10) ; }
if(z == nbCube-1 || z == 0 ) { stroke(0,0, 200); fill(0,0,200); strokeWeight(5);
point( -side*ix +c , -side*ig +c , side*z -c +3) ; }
if(ix == nbCube-1 && ig > 0 && ig < nbCube -1 && z == nbCube-1 ) { fill(0,0,200); textFont(myFont, 14);
text( cpt3, -side*ix +c -32, -side*ig +c , side*z -c +10) ; }
if(ix == 0 && ig > 0 && ig < nbCube && z == 0 ) { textFont(myFont, 15);
text( cpt3, -side*ix +c +5, -side*ig +c , side*z -c -5) ; }
stroke(0); strokeWeight(1); line(-side*ix +c , -side*ig +c , side*z -c, ixe0, igrec0, zed0 ); // end of drawing the boustro course
*/
}