why is my text() under line()

Hey :)

I use peasycam to rotate my sphere, and cam.beginHUD() to display some information on the screen. ** in line 120-130 I create 3 lines in line 219-233 I create 3 texts which should be on this lines - but they are UNDER the lines**

why?

int ptsW, ptsH;
import peasy.*;

PeasyCam cam;

PImage img;

int numPointsW;
int numPointsH_2pi; 
int numPointsH;

float[] coorX;
float[] coorY;
float[] coorZ;
float[] multXZ;



PImage heatmap;
PImage cancer;
PImage suicide;
PImage traffic;

PImage currentIcon;


float currentCancer = 0;
float currentTraffic = 0;
float currentSuicide = 0;

int imagestate;
int alphavalue = 255;
int cancerTrigger;
int trafficTrigger;
int suicideTrigger;



void setup() {
  fullScreen(P3D);

  cam = new PeasyCam(this, 100);
  cam.setMinimumDistance(10);
  cam.setMaximumDistance(100);

  background(0);
  noStroke();
  img=loadImage("Heatmap_Cancer_traffic_Suicide_02.png");
  ptsW=30;
  ptsH=30;
  // Parameters below are the number of vertices around the width and height
  initializeSphere(ptsW, ptsH);
    heatmap = loadImage("Heatmap_Cancer_traffic_Suicide_02.png");
  cancer = loadImage("Cancer_01.png");
  suicide = loadImage("Suicide_01.png");
  traffic = loadImage("Traffic_01.png");
  heatmap.loadPixels();

  currentIcon = traffic; // nur für den Anfang, damit es nicht nichts ist.


}

// Use arrow keys to change detail settings
void keyPressed() {
  if (keyCode == ENTER) saveFrame();
  if (keyCode == UP) ptsH++;
  if (keyCode == DOWN) ptsH--;
  if (keyCode == LEFT) ptsW--;
  if (keyCode == RIGHT) ptsW++;
  if (ptsW == 0) ptsW = 1;
  if (ptsH == 0) ptsH = 2;
  // Parameters below are the number of vertices around the width and height
  initializeSphere(ptsW, ptsH);
}

void draw() {
  background(0);
  pushMatrix();
  rotateX(-.5);
  rotateY(-.5);



  textureSphere(400, 400, 400, img);
  popMatrix();

  cam.beginHUD();

  fill(0,120);
  noStroke();
  rect(0,0,width,height/2-1);
  rect(0,height/2+10,width,height);

    pushMatrix();

  currentCancer = red(get(width/2, height/2));
  currentTraffic = blue(get(width/2, height/2));
  currentSuicide = green(get(width/2, height/2));
  //  image (heatmap, 0,0, width, height);

  // debug
  if (keyPressed) {
    if (key == 's') {
      currentSuicide = 150;
    }
    if (key == 't') {
      currentTraffic = 150;
    }
    if (key == 'c') {
      currentCancer = 150;
    }
  }

  cancerTrigger = 0;
  trafficTrigger = 0;
  suicideTrigger = 0;

  //Diagram - tode / 100.000
  stroke(255);
  strokeWeight(36);
  fill(255);
  translate(width/2, height/2);
  line(75, 0, 75+currentCancer, 0);

  rotate(PI*2/3);
  line(75, 0, 75+currentTraffic, 0);

  rotate(PI*2/3);  
  line(75, 0, 75+currentSuicide, 0);

  popMatrix() ;

  //Punkte - "live DeathCounter"
  pushMatrix() ;
  translate(width/2, height/2);

  cancer.resize(70, 70);
  suicide.resize(70, 70);
  traffic.resize(70, 70);


  strokeWeight(1);
  fill(255);
  if (frameCount % (170-currentCancer) == 0) {
    if (random(255) < currentCancer) {
      cancerTrigger = 1;
    }
  }

  if (frameCount % (170-currentTraffic) == 0) {
    if (random(255) < currentTraffic) {
      trafficTrigger = 1;
    }
  }

  if (frameCount % (170-currentSuicide) == 0) {
    if (random(255) < currentSuicide) {
      suicideTrigger = 1;
    }
  }

  //ICONS
  if (cancerTrigger == 1) {
    currentIcon = cancer;
    imagestate=1;
    alphavalue = 255;
  }

  if (trafficTrigger == 1) {
    currentIcon = traffic;
    imagestate=1;
    alphavalue = 255;
  }

  if (suicideTrigger == 1) {
    currentIcon = suicide;
    imagestate=1;
    alphavalue = 255;
  }
  // QUADS

  if (cancerTrigger == 1) {
    quad(0, 35, 0, -35, 75, -18, 75, 18);
    imagestate=1;
    alphavalue = 255;
  }
  rotate(PI*2/3);
  if (trafficTrigger == 1) {
    quad(0, 35, 0, -35, 75, -18, 75, 18);
    imagestate=1;
    alphavalue = 255;
  }
  rotate(PI*2/3);

  if (suicideTrigger == 1) {
    quad(0, 35, 0, -35, 75, -18, 75, 18);
    imagestate=1;
    alphavalue = 255;
  }


  //FADING
  if (imagestate==1) {
    if (frameCount % 2 == 0) {
      alphavalue -= 5;
      if (alphavalue < 10) {
        imagestate = 0;
      }
    }
  }
  tint(255, alphavalue);
  image(currentIcon, -35, -35);
  tint (255, 255);



  // Text auf dem Diagram
  fill(0);

  rotate(PI*2/3);

  textSize(32);
  text(round(currentCancer), 65, 10); 
  rotate(PI*2/3);

  textSize(32);
  text(round(currentTraffic), 65, 10); 
  rotate(PI*2/3);

  textSize(32);
  text(round(currentSuicide), 65, 10); 
  rotate(PI*2/3);

  popMatrix();

  cam.endHUD();

}

void initializeSphere(int numPtsW, int numPtsH_2pi) {

  // The number of points around the width and height
  numPointsW=numPtsW+1;
  numPointsH_2pi=numPtsH_2pi;  // How many actual pts around the sphere (not just from top to bottom)
  numPointsH=ceil((float)numPointsH_2pi/2)+1;  // How many pts from top to bottom (abs(....) b/c of the possibility of an odd numPointsH_2pi)

  coorX=new float[numPointsW];   // All the x-coor in a horizontal circle radius 1
  coorY=new float[numPointsH];   // All the y-coor in a vertical circle radius 1
  coorZ=new float[numPointsW];   // All the z-coor in a horizontal circle radius 1
  multXZ=new float[numPointsH];  // The radius of each horizontal circle (that you will multiply with coorX and coorZ)

  for (int i=0; i<numPointsW ;i++) {  // For all the points around the width
    float thetaW=i*2*PI/(numPointsW-1);
    coorX[i]=sin(thetaW);
    coorZ[i]=cos(thetaW);
  }

  for (int i=0; i<numPointsH; i++) {  // For all points from top to bottom
    if (int(numPointsH_2pi/2) != (float)numPointsH_2pi/2 && i==numPointsH-1) {  // If the numPointsH_2pi is odd and it is at the last pt
      float thetaH=(i-1)*2*PI/(numPointsH_2pi);
      coorY[i]=cos(PI+thetaH); 
      multXZ[i]=0;
    } 
    else {
      //The numPointsH_2pi and 2 below allows there to be a flat bottom if the numPointsH is odd
      float thetaH=i*2*PI/(numPointsH_2pi);

      //PI+ below makes the top always the point instead of the bottom.
      coorY[i]=cos(PI+thetaH); 
      multXZ[i]=sin(thetaH);
    }
  }
}

void textureSphere(float rx, float ry, float rz, PImage t) { 
  // These are so we can map certain parts of the image on to the shape 
  float changeU=t.width/(float)(numPointsW-1); 
  float changeV=t.height/(float)(numPointsH-1); 
  float u=0;  // Width variable for the texture
  float v=0;  // Height variable for the texture

  beginShape(TRIANGLE_STRIP);
  texture(t);
  for (int i=0; i<(numPointsH-1); i++) {  // For all the rings but top and bottom
    // Goes into the array here instead of loop to save time
    float coory=coorY[i];
    float cooryPlus=coorY[i+1];

    float multxz=multXZ[i];
    float multxzPlus=multXZ[i+1];

    for (int j=0; j<numPointsW; j++) { // For all the pts in the ring
      normal(-coorX[j]*multxz, -coory, -coorZ[j]*multxz);
      vertex(coorX[j]*multxz*rx, coory*ry, coorZ[j]*multxz*rz, u, v);
      normal(-coorX[j]*multxzPlus, -cooryPlus, -coorZ[j]*multxzPlus);
      vertex(coorX[j]*multxzPlus*rx, cooryPlus*ry, coorZ[j]*multxzPlus*rz, u, v+changeV);
      u+=changeU;
    }
    v+=changeV;
    u=0;
  }
  endShape();
}

Answers

  • Answer ✓

    Can't run your sketch to see the problem because we don't have the image files so this is based on your description.

    Add the statement hint(DISABLE_OPTIMIZED_STROKE); to your setup() function.

  • thank you very much @quark

    I'm pretty new to processing and ur suggestion did magic - thanks :x

Sign In or Register to comment.