Weird purplish layer on the drawing
in
Programming Questions
•
3 years ago
hello helpers!
I need to fill the mesh faces according to their height and their angle. But there is a strange purple color instead that affects the color mode... (not a problem with the camera position) Any idea ? I think it might be the definition of the 90 degree angle
Here is the code :
import anar.*;
import processing.opengl.*;
PVector[] faceNorm;
PVector[] baseVec;
String[] txtNdx;
String[] txtVtx;
Pt[] meshVtx;
Pt[] nPt;
Pt[] basePt;
float[] ang;
Face testFace = new Face();
Face[] meshFaces;
void setup() {
size (600,600,OPENGL);
Anar.init(this);
Anar.drawAxis();
colorMode(HSB);
txtVtx = loadStrings("MeshVertexP2.txt");
txtNdx = loadStrings("MeshIndexP2.txt");
meshVtx = new Pt[txtVtx.length];
meshFaces=new Face[txtNdx.length];
ReadTxtData_INDEXEDMESH(txtVtx, txtNdx, meshVtx, meshFaces);
faceNorm = new PVector[txtNdx.length];
baseVec = new PVector[txtNdx.length];
nPt = new Pt[txtNdx.length];
basePt = new Pt[txtNdx.length];
ang = new float[txtNdx.length];
for(int i=0; i<txtNdx.length; i++) {
nPt[i] = meshFaces[i].normal();
faceNorm[i] = new PVector( nPt[i].x()-meshFaces[i].center().x(), nPt[i].y()-meshFaces[i].center().y(), nPt[i].z()-meshFaces[i].center().z() );
baseVec[i] = new PVector( faceNorm[i].x, faceNorm[i].y,0) ;
}
}
void draw() {
background(255);
camera(2000.0,2000.0,4000.0,2000.0,2000.0,0.0,0.0,1.0,0.0) ;
for(int i=0; i<meshFaces.length; i++) {
float ang;
if (baseVec[i].x==0 && baseVec[i].y ==0){
ang=radians(90);
} else {
float dotprod = faceNorm[i].dot(baseVec[i]);
ang = acos(dotprod/(baseVec[i].mag()*faceNorm[i].mag())) ;
}
if ((meshFaces[i].center().z()> 20) && (meshFaces[i].center().z()<= 30)) {
color fColor = color(240,((90-degrees(ang))*20), 360);
meshFaces[i].fill(red(fColor), green(fColor), blue(fColor));
}
if ((meshFaces[i].center().z()> 30) && (meshFaces[i].center().z()<= 40)) {
color fColor = color(210,((90-degrees(ang))*20), 360);
meshFaces[i].fill(red(fColor), green(fColor), blue(fColor));
}
if ((meshFaces[i].center().z()> 40) && (meshFaces[i].center().z()<= 50)) {
color fColor = color(180,((90-degrees(ang))*20), 360);
meshFaces[i].fill(red(fColor), green(fColor), blue(fColor));
}
if ((meshFaces[i].center().z()> 50) && (meshFaces[i].center().z()<= 60)) {
color fColor = color(150,((90-degrees(ang))*20), 360);
meshFaces[i].fill(red(fColor), green(fColor), blue(fColor));
}
if ((meshFaces[i].center().z()> 60) && (meshFaces[i].center().z()<= 70)) {
color fColor = color(120,((90-degrees(ang))*20), 360);
meshFaces[i].fill(red(fColor), green(fColor), blue(fColor));
}
if ((meshFaces[i].center().z()> 70) && (meshFaces[i].center().z()<= 80)) {
color fColor = color(90,((90-degrees(ang))*20), 360);
meshFaces[i].fill(red(fColor), green(fColor), blue(fColor));
}
if ((meshFaces[i].center().z()> 80) && (meshFaces[i].center().z()<= 100)) {
color fColor = color(60,((90-degrees(ang))*20), 360);
meshFaces[i].fill(red(fColor), green(fColor), blue(fColor));
}
meshFaces[i].draw();
noStroke();
}
}
void keyPressed() {
if (key =='s') {
saveFrame("image"+".jpg");
}
}
1
