Skip to content

Animated PShape, P2D and non-PShape Geometry disappearing #208

@rich-gg

Description

@rich-gg

Using the PShape code I copied from WigglePShape sample, I can have an animated PShape with the desired strokeWeight running smoothly in my Android App.

But, as soon as I run the method that plays with the shape vertexes all the non PShape object in the class just disappear. And this happens only with P2D and Android

no problem with JAVA2D and P3D rendering, and no problem on P2D on PC

  • might be interesting to know that, objects that I draw in the main Class do not disappear
    (for instance if I have the PShape Wiggle Object in a Wiggler Class, objects drawn in main remain visible as the Wiggler Wiggles, and Objects that are drawn in another Class do disappear)

I made a very simple sketch to show the thing I suppose to be a bug.
Touch the screen, it will run the wiggle method, and the black circle will disappear


//Wiggler
// The PShape to be "wiggled"
PShape s;
// Its location
float x, y;
// For 2D Perlin noise
float yoff = 0;
// We are using an ArrayList to keep a duplicate copy
// of vertices original locations.
ArrayList<PVector> original;
//
boolean wiggleBool;

public void setup() {
  size(800, 600, P2D);

  //Wiggler
  x =  width/2;
  y =  height/2;
  // The "original" locations of the vertices make up a circle
  original = new ArrayList<PVector>();
  for (float a = 0; a <  TWO_PI; a+=0.2) {
    PVector v = PVector.fromAngle(a);
    v.mult(120/2);
    original.add(v);
  }
  // Now make the PShape with those vertices
  s =  createShape();
  s.beginShape();
  s.noFill();

  s.stroke(255, 0, 0);
  //s.setFill(p5.color(255,0,0));
  s.strokeWeight(10);
  //s.setStrokeWeight(10);
  for (PVector v : original) {
    s.vertex(v.x, v.y);
  }
  s.endShape( CLOSE);
}


public void draw() {
  background(128, 255, 0);

  textSize(40);
  text(frameRate, 20, 50);

  shape(s, width/2, height/2);

  noFill();
  ellipse(width/2, height/3, 120, 120);

  if (wiggleBool) {
    wiggle();
  }
}

public void mousePressed() {
  wiggleBool = !wiggleBool;
}

void wiggle() {
  float xoff = 0;
  // Apply an offset to each vertex
  for (int i = 0; i < s.getVertexCount(); i++) {
    // Calculate a new vertex location based on noise around "original" location
    PVector pos = original.get(i);
    float a =  TWO_PI* noise(xoff, yoff);
    PVector r = PVector.fromAngle(a);
    r.mult(32);
    r.add(pos);
    // Set the location of each vertex to the new one
    s.setVertex(i, r.x, r.y);
    // increment perlin noise x value
    xoff+= 0.5;
  }
  // Increment perlin noise y value
  yoff += 0.52;
}



ps I use RC3 that I downloaded this morning

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions