为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

牧羊人nacy 2022-09-28 10:21:20
我目前正在尝试创建一种绘图应用程序的形式,我刚刚使用 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();

  }

}




查看完整回答
反对 回复 2022-09-28
  • 1 回答
  • 0 关注
  • 153 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号