有没有办法在不输入开始/结束的情况下更改 PShape 的颜色? [英] Is there a way to change the color of PShape without entering begin/end?

查看:67
本文介绍了有没有办法在不输入开始/结束的情况下更改 PShape 的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编写一个程序,它以不同的颜色重绘大量(数百个)相同的 PShape.但是,我还没有找到一种在不实际重新创建 PShape 的情况下以不同颜色重新绘制 PShape 的方法,即通过开始/结束形状重做所有顶点并简单地更改填充,然后将其分配给新的 PShape 变量.我尝试过 tint()、fill()、setFill() 之类的方法,它们似乎都需要在开始/结束形状中调用.

I've been writing a program which redraws lots of (several hundred) the same PShape in different colors. However, I haven't found a way to redraw the PShape in different colors without actually recreating the PShape, i.e. going through the begin/end shape redoing all the vertices and simply changing the fill and then assigning it to a new PShape variable. I've tried things like tint(), fill(), setFill() and they all seem to require being called in begin/end shape.

有没有办法在不完全重新定义形状并将其分配给新变量的情况下重绘不同颜色的 PShape?

非常感谢任何帮助.

(这是我尝试过的不同事物的整理)

(Here is a sort of collation of the different things I tried)

   PShape p;

    void setup()
{
  size(600,600,P2D);
  p = createShape();
  p.beginShape();
  p.vertex(0, 0);
  p.vertex(20, 0);
  p.vertex(20, 20);
  p.vertex(0, 20);
  p.endShape(CLOSE);
}

void draw()
{
  p.tint(200,100,30);
  p.fill(200,100,30);
  p.setFill(0,0);
  shape(p,100,100);
}

非常感谢任何帮助

推荐答案

是的,可以使用 PShape 的 disableStyle() 禁用它的渲染样式并使用处理的(您的草图):

Yes, you can use PShape's disableStyle() to disable it's rendering style and use Processing's (your sketches'):

PShape p;

void setup()
{
  size(600, 600, P2D);
  p = createShape();
  p.beginShape();
  p.vertex(0, 0);
  p.vertex(20, 0);
  p.vertex(20, 20);
  p.vertex(0, 20);
  p.endShape(CLOSE);
  //disable the PShape's default styles and use Processing's 
  p.disableStyle();
}

void draw()
{
  background(255);
  for(int i = 0 ; i < 30 ; i++){
      fill(i/30.0*255, 100, 30);
      shape(p, i * 20,300);
  }
}

对于这样一个简单的形状,您当然可以使用 rect(),但我认为这是更复杂的东西的占位符.其他需要探索的内容是 beginShape()createGraphics()

For such a simple shape you can of course use rect(), but I assume that's a place holder for something more complex. Other things to explore are beginShape() and maybe createGraphics()

这篇关于有没有办法在不输入开始/结束的情况下更改 PShape 的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆