Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

PShape bug?

$
0
0
Hi, I have code that draws a group of pshapes.  Each child is a line of random data like a spectrogram.  The drawing looks screwed up on one side and I'm pretty sure I'm not doing anything wrong in the code.  I'm already aware of a memory leak problem with PShapes with removing children and setting vertices, so running this code will probably eat up a lot of your memory, but you should be able to see the problem i'm having with drawing.  I'm running this on Windows 7.

PShape parent;

int lineCount;

void setup() {
  parent = createShape(GROUP);
  lineCount = 0;
  size(1280, 720, OPENGL);
}

void draw() {

  float[] data = new float[65];
  for (int i = 0; i < 65; i++) {
    if (i == 1 || i == 2)
      data[i] = 1;
    else
      data[i] = (float) Math.random();
  }

  PShape newLine = createShape();
  newLine.beginShape();
  for (int i = 0; i < 65; i++) {
    newLine.stroke(map(data[i], 0, 1, 0, 255));
    newLine.vertex(i*10, -lineCount);
  }
  newLine.endShape();
  parent.translate(0, 1);
  parent.addChild(newLine);
  
  if (parent.getChildCount() > height / 2)
    parent.removeChild(0);
  
  shape(parent);


  lineCount++;
}


Viewing all articles
Browse latest Browse all 1768

Trending Articles