1
PImage ball;

void setup(){
 size(600,500); 
 background(255);
 ball = loadImage("ball.png");
}

void draw(){
  float oldx = 0;
  float oldy = 0.5*height;
  int dif = 1;

  for(float x = 0; x < width; x++) {
    float y = map(noise(x/250),0,1,0.2*height, 0.8*height);
    noiseDetail(dif);
    stroke(0,255,0);
    fill(0,255,0);
    beginShape();
    vertex(oldx,oldy);
    vertex(x,y);
    endShape(CLOSE);
    oldx = x;
    oldy = y;
    if(x == 1){
     image(ball,x+10,y-10,10,10);
    }
  }

}

I tried what someone had recommended which was to create a custom shape using beginShape() but I was still unable to fill underneath the line. Any help would be greatly appreciated.

Joe Smith
  • 11
  • 2

1 Answers1

1

Try adding a PShape s; global variable and then using s = createShape(); in setup(). Use s.fill(); right after s.beginShape(); and use shape(s); after s.endShape();

PImage ball;
PShape s;

void setup(){
 size(600,500); 
 background(255);
 ball = loadImage("ball.png");
 s = createShape();
}

void draw(){
  float oldx = 0;
  float oldy = 0.5*height;
  int dif = 1;

  for(float x = 0; x < width; x++) {
    float y = map(noise(x/250),0,1,0.2*height, 0.8*height);
    noiseDetail(dif);
    s.beginShape();
    s.fill(0,255,0);
    s.vertex(oldx,oldy);
    s.vertex(x,y);
    s.endShape(CLOSE);
    shape(s);
    oldx = x;
    oldy = y;
    if(x == 1){
     image(ball,x+10,y-10,10,10);
    }
  }

}

apodidae
  • 1,988
  • 2
  • 5
  • 9