我目前正在尝试创建一种绘图应用程序的形式,我刚刚使用 createShape() 实现了一个多线功能。问题是,在绘制形状时,用户很可能不希望它被填充,所以我使用了noFill()。然而,在绘制之后,当调用endShape时,我想填充形状(假设满足正确的情况),并且仅使用PShape.setFill(颜色)不幸的是不起作用。例如Pshape s;s = createShape();s.beginShape();s.noFill();drawShape(s);s.endShape();if(fill.selected) s.setFill(colour);有没有办法做到这一点,或者我只需要不使用noFill?任何帮助是值得赞赏的,谢谢。
1 回答

喵喵时光机
TA贡献1846条经验 获得超7个赞
你应该能够使用 fill(), 只要你在 / 调用中使用它.beginShape()
endShape()
下面是一个粗略的示例:
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();
}
}
添加回答
举报
0/150
提交
取消