Trying to target an area of square to apply noise function

Hello,

This may be a better example… but still just a quick one.

I was not too confident in my tinkering with the other code (done very quickly!) and added some points (hints and actual points!) to help visualize what was being modified.

Example Code
ArrayList<PVector> square = new ArrayList<PVector>();

PShape s;

public void settings() 
  {  
  size(400, 400, P2D); 
  }

public void setup() 
  {
  //noLoop();

  for(int x = 0; x < 10; x += 1) 
    {
    float y = x;  
    square.add(new PVector(x*10, y*10)); //Should be a diagonal line
    }

  s = createShape();
  s.beginShape();
  s.fill(255, 0, 0);
  for (PVector v : square) {
  s.vertex(v.x, v.y);
  }

  s.endShape(CLOSE);
  }


public void draw() 
  {
  background(255);
  
  // vertices modified and displayed 
  for (int i = 0; i < s.getVertexCount(); i++) 
    {
    PVector v = s.getVertex(i);
    v.y += random(-1, 1);
    //v.y = random(-10, 10);
    s.setFill(color(255, 255, 0));
    s.setVertex(i, v);
    
    // These help to see the modified vertices and NOT part of shape
    strokeWeight(5);
    stroke(255, 0, 0);
    point(v.x, v.y);
    }
  
  // New modified shape
  s.setStrokeWeight(2);
  shape(s, 100, 100);
  }

Once you get the hang of this you won’t be able to stop!

Some nuggets in here:
PShape \ Language (API) \ Processing 3+

If you want to copy a PShape:
Copying a PShape?

:)

image

1 Like