在随机生成的山丘下填充

问题描述 投票:0回答: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);
    }
  }

}

我尝试了有人推荐的方法,即使用 beginShape() 创建自定义形状,但我仍然无法在线下填充。任何帮助将不胜感激。

processing
1个回答
0
投票

尝试添加一个 PShape s; 全局变量,然后在 setup() 中使用 s = createShape();。在 s.beginShape() 之后使用 s.fill();;并在 s.endShape() 之后使用 shape(s);;

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);
    }
  }

}

© www.soinside.com 2019 - 2024. All rights reserved.