Scripts run differently since updating Processing

edited January 2014 in Using Processing

Hi, I updated from 2.1 to 2.1.1 earlier and discovered that lots of scripts I have been working on recently using square grids and perlin noise as the z-coordinate value have changed in appearance, despite being exactly the same file. They basically look as if all the little shapes have been filled in or the stroke weight is very heavy. I tried the obvious things like specifying noFill() and strokeWeight() which I hadn't before, in case the defaults had changed, but it's not made any difference.

Any ideas?

Script as it looked yesterday: image alt text

And today: image alt text

Code: (left out the gradient code, wasn't sure it was relevant- let me know if you want to see it)

int uCount = 100;
float uMin = -10;
float uMax = 10;

int vCount = 100;
float vMin = -10;
float vMax = 10;

int noiseXRange = 120;
int noiseYRange = 120;

PVector[][] points = new PVector[vCount+1][uCount+1];

Gradient g;

void setup(){
  size(1600, 1600, P3D);
  smooth();
  noFill();

  g = new Gradient();
  g.addColor(color(62, 24, 199));
  g.addColor(color(255, 235, 87));
  g.addColor(color(255, 119, 28));

  float u, v;
  for (int iv = 0; iv <= vCount; iv++) {
    for (int iu = 0; iu <= uCount; iu++) {
      u = map(iu, 0, uCount, uMin, uMax);
      v = map(iv, 0, vCount, vMin, vMax);

      points[iv][iu] = new PVector();
      points[iv][iu].x = u;
      points[iv][iu].y = sin(sq(v))*0.85;
      points[iv][iu].z = 0;

    }
  }

}

void draw() {
  background(255);

    int num = 5; // number of times shape is drawn on screen
    float gap = 0.125; // gap between drawn shapes
    for(int i=0; i<num; i++){
      pushMatrix();
        println(height/(8f * (3+i)));
        translate(width/2, (height*(1+gap*(1-num+2*i)))/2); // spaces them out evenly
        scale(45);
        drawShape();
      popMatrix();
    }
}

void drawShape(){
  float noiseValue = 0.0;
  float noiseValue2= 0.0;

  for(int iv = 0; iv < vCount; iv++) {
    beginShape(TRIANGLE);
    for(int iu = 0; iu < uCount; iu++) {      
      float u2 = map(iu, 0, uCount, 0, 2);
      color h = g.getGradient(u2);
      stroke(h);

      float noiseX = map(iu, 0, width, 0, noiseXRange);
      float noiseY = map(iv, 0, height, 0, noiseYRange);
      float noiseY2= map(iv+1, 0, height, 0, noiseYRange);
      //noiseDetail(4, 0.5);
      noiseValue = noise(noiseX, noiseY);
      noiseValue2= noise(noiseX*2, noiseY2);


      vertex(points[iv][iu].x, points[iv][iu].y, noiseValue*15);
      vertex(points[iv+1][iu].x, points[iv+1][iu].y*1.5, noiseValue2*15);

    }
    endShape();
  }
}

Answers

  • Hello, the stroke weight is affected by the scale factor, and this is the expected behavior across all renderers, for example:

    void setup() {
      size(400, 400);
    }
    
    void draw() {
      background(180);
      translate(200, 200);
      scale(map(mouseX, 0, width, 1, 20));
      rect(-1, -1, 2, 2);  
    }
    

    I run a simplified version of your code, adjusting the stroke weight according to the scale factor, and the output is the same between 2.1 and 2.1.1:

    int uCount = 50;
    float uMin = -10;
    float uMax = 10;
    
    int vCount = 50;
    float vMin = -10;
    float vMax = 10;
    
    int noiseXRange = 120;
    int noiseYRange = 120;
    
    PVector[][] points = new PVector[vCount+1][uCount+1];
    
    void setup(){
      size(800, 800, P3D);
      smooth();
      noFill();
    
      float u, v;
      for (int iv = 0; iv <= vCount; iv++) {
        for (int iu = 0; iu <= uCount; iu++) {
          u = map(iu, 0, uCount, uMin, uMax);
          v = map(iv, 0, vCount, vMin, vMax);
    
          points[iv][iu] = new PVector();
          points[iv][iu].x = u;
          points[iv][iu].y = sin(sq(v))*0.85;
          points[iv][iu].z = 0;
        }
      }
    }
    
    void draw() {
      background(255);
    
        int num = 5; // number of times shape is drawn on screen
        float gap = 0.125; // gap between drawn shapes
        for(int i=0; i<num; i++){
          pushMatrix();
            println(height/(8f * (3+i)));
            translate(width/2, (height*(1+gap*(1-num+2*i)))/2); // spaces them out evenly
            scale(45);
            drawShape();
          popMatrix();
        }
    }
    
    void drawShape(){
      float noiseValue = 0.0;
      float noiseValue2= 0.0;
    
      for(int iv = 0; iv < vCount; iv++) {
        beginShape(TRIANGLE);
        for(int iu = 0; iu < uCount; iu++) {     
          float u2 = map(iu, 0, uCount, 0, 2);
          stroke(0);
          strokeWeight(1/45.0);
    
          float noiseX = map(iu, 0, width, 0, noiseXRange);
          float noiseY = map(iv, 0, height, 0, noiseYRange);
          float noiseY2= map(iv+1, 0, height, 0, noiseYRange);
          noiseValue = noise(noiseX, noiseY);
          noiseValue2= noise(noiseX*2, noiseY2);
    
          vertex(points[iv][iu].x, points[iv][iu].y, noiseValue*15);
          vertex(points[iv+1][iu].x, points[iv+1][iu].y*1.5, noiseValue2*15);
        }
        endShape();
      }
    }
    

    img

  • thanks for the fix. strange that the behaviour changed between versions!

Sign In or Register to comment.