处理 3 - 使用 noFill() 后填充形状

Processing 3 - Filling a shape after using noFill()

我目前正在尝试创建一种绘图应用程序,并且我刚刚使用 createShape() 实现了折线功能。

问题是,在绘制形状时,用户很可能不希望它被填充,所以我使用了 noFill()。然而,在绘制之后,当调用 endShape 时,我想填充形状(假设满足正确的情况),不幸的是,仅使用 PShape.setFill(colour) 是行不通的。

例如

Pshape s;
s = createShape();
s.beginShape();
s.noFill();

drawShape(s);

s.endShape();
if(fill.selected) s.setFill(colour);

有什么方法可以做到这一点,还是我只需要不使用 noFill ? 感谢您的帮助,谢谢。

只要在 beginShape()/endShape() 调用中使用 fill(),就应该可以使用它。

这是一个粗略的例子:

PShape s;

boolean useFill;

void setup(){

  size(300,300);
  s = createShape();
  s.beginShape();
  s.noFill();
  s.vertex(30,30);
  s.vertex(120,30);
  s.vertex(30,120);
  s.vertex(30,30);// close shape, repeat last vertex
  s.endShape();

}

void draw(){
  background(127 + (frameCount % 127));
  shape(s);
  text("press any key to toggle fill",10,15);
}

void keyPressed(){
  useFill = !useFill;

  if(useFill){
    s.beginShape();
    s.fill(color(192,0,0));
    s.endShape();
  }else{
    s.beginShape();
    s.noFill();
    s.endShape();
  }
}