Processing 如何在处理过程中使对象不可见

Processing 如何在处理过程中使对象不可见,processing,Processing,我正在使用“处理”在草图板上制作矩形,但我想使它们不可见。我该怎么做?谢谢你的帮助 Amrita您可以不绘制它们,或者为函数使用forth(alpha/透明度)参数 非绘图: int numVisible = 0; for(int i = 0 ; i < 20 ; i++) { boolean visible = random(1) > .5; if(visible) { rect(random(100),random(100),random(10),random

我正在使用“处理”在草图板上制作矩形,但我想使它们不可见。我该怎么做?谢谢你的帮助


Amrita

您可以不绘制它们,或者为函数使用forth(alpha/透明度)参数

非绘图:

int numVisible = 0;
for(int i = 0 ; i  < 20 ;  i++) {
  boolean visible = random(1) > .5;
  if(visible) {
    rect(random(100),random(100),random(10),random(10));
    numVisible++;
  }
}
println(numVisible+" boxes are visible");
int numVisible=0;
对于(int i=0;i<20;i++){
布尔可见=随机(1)>.5;
如果(可见){
rect(random(100)、random(100)、random(10)、random(10));
numVisible++;
}
}
println(numVisible+“框可见”);
图形透明(只有笔划可见):

for(int i=0;i<20;i++){
布尔可见=随机(1)>.5;
填充(255255,可见?255:0);
rect(random(100)、random(100)、random(10)、random(10));
}
如果有帮助,这里有一个较长的版本:

void setup(){
  size(400,400,P2D);
  smooth();
  noStroke();
  background(255);
  for(int i = 0; i < 200 ; i++){
    Rect r = new Rect(random(width),random(height),random(10,20),random(10,20),color(random(255),random(255),random(255),random(1) > .5 ? 255 : 64));
    r.draw();
  }
}
class Rect{
  color c;
  float w,h,x,y;
  Rect(float x,float y,float w,float h,color c){
    this.c = c;
    this.w = w;
    this.h = h;
    this.x = x;
    this.y = y;
  }
  void draw(){
    fill(c);
    rect(x,y,w,h);
  }
}
void setup(){
尺寸(400400,P2D);
光滑的();
仰泳();
背景(255);
对于(int i=0;i<200;i++){
Rect r=新的Rect(随机(宽度)、随机(高度)、随机(10,20)、随机(10,20)、颜色(随机(255)、随机(255)、随机(255)、随机(1)>5?255:64);
r、 draw();
}
}
类矩形{
颜色c;
浮子w,h,x,y;
矩形(浮动x、浮动y、浮动w、浮动h、颜色c){
这个.c=c;
这个.w=w;
这个,h=h;
这个.x=x;
这个。y=y;
}
作废提款(){
填充(c);
rect(x,y,w,h);
}
}
下面是您可以运行的代码段:

函数设置(){
createCanvas(400400);
光滑的();
仰泳();
背景(255);
对于(变量i=0;i<200;i++){
var r=新矩形(随机(宽度)、随机(高度)、随机(10,20)、随机(10,20)、颜色(随机(255)、随机(255)、随机(255)、随机(1)>5?255:64);
r、 draw();
}
}
函数Rect(x,y,w,h,c){
这个.c=c;
这个.w=w;
这个,h=h;
这个.x=x;
这个。y=y;
this.draw=函数(){
填充(c);
rect(x,y,w,h);
}
}

您可以不绘制它们,也可以为函数使用forth(alpha/透明度)参数

非绘图:

int numVisible = 0;
for(int i = 0 ; i  < 20 ;  i++) {
  boolean visible = random(1) > .5;
  if(visible) {
    rect(random(100),random(100),random(10),random(10));
    numVisible++;
  }
}
println(numVisible+" boxes are visible");
int numVisible=0;
对于(int i=0;i<20;i++){
布尔可见=随机(1)>.5;
如果(可见){
rect(random(100)、random(100)、random(10)、random(10));
numVisible++;
}
}
println(numVisible+“框可见”);
图形透明(只有笔划可见):

for(int i=0;i<20;i++){
布尔可见=随机(1)>.5;
填充(255255,可见?255:0);
rect(random(100)、random(100)、random(10)、random(10));
}
如果有帮助,这里有一个较长的版本:

void setup(){
  size(400,400,P2D);
  smooth();
  noStroke();
  background(255);
  for(int i = 0; i < 200 ; i++){
    Rect r = new Rect(random(width),random(height),random(10,20),random(10,20),color(random(255),random(255),random(255),random(1) > .5 ? 255 : 64));
    r.draw();
  }
}
class Rect{
  color c;
  float w,h,x,y;
  Rect(float x,float y,float w,float h,color c){
    this.c = c;
    this.w = w;
    this.h = h;
    this.x = x;
    this.y = y;
  }
  void draw(){
    fill(c);
    rect(x,y,w,h);
  }
}
void setup(){
尺寸(400400,P2D);
光滑的();
仰泳();
背景(255);
对于(int i=0;i<200;i++){
Rect r=新的Rect(随机(宽度)、随机(高度)、随机(10,20)、随机(10,20)、颜色(随机(255)、随机(255)、随机(255)、随机(1)>5?255:64);
r、 draw();
}
}
类矩形{
颜色c;
浮子w,h,x,y;
矩形(浮动x、浮动y、浮动w、浮动h、颜色c){
这个.c=c;
这个.w=w;
这个,h=h;
这个.x=x;
这个。y=y;
}
作废提款(){
填充(c);
rect(x,y,w,h);
}
}
下面是您可以运行的代码段:

函数设置(){
createCanvas(400400);
光滑的();
仰泳();
背景(255);
对于(变量i=0;i<200;i++){
var r=新矩形(随机(宽度)、随机(高度)、随机(10,20)、随机(10,20)、颜色(随机(255)、随机(255)、随机(255)、随机(1)>5?255:64);
r、 draw();
}
}
函数Rect(x,y,w,h,c){
这个.c=c;
这个.w=w;
这个,h=h;
这个.x=x;
这个。y=y;
this.draw=函数(){
填充(c);
rect(x,y,w,h);
}
}

您可以在draw函数中放入一个var来控制它是否必须显示您想要的内容

void draw()
{
  if (showThis)
  {
    image(image);
  }
}

您可以在draw函数中放入一个var来控制它是否必须显示您想要的内容

void draw()
{
  if (showThis)
  {
    image(image);
  }
}
添加noStroke();并使颜色与背景色相同?

添加noStroke();并使颜色与背景颜色相同?

不要猜测(在答案末尾添加“?”)不要猜测(在答案末尾添加“?”)