如何解决如何在处理中使对象不可见
| 我正在使用处理在草图板上制作矩形,但是我想使它们不可见。我怎么做?多谢您的协助。 阿姆里塔解决方法
您既不能绘制它们,也可以将四(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\");
透明绘图(仅可见笔触):
for(int i = 0 ; i < 20 ; i++) {
boolean visible = random(1) > .5;
fill(255,255,visible ? 255 : 0);
rect(random(100),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),color(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);
}
}
波纹管是可以运行的代码段:
function setup(){
createCanvas(400,400);
smooth();
noStroke();
background(255);
for(var i = 0; i < 200 ; i++){
var r = new Rect(random(width),random(1) > .5 ? 255 : 64));
r.draw();
}
}
function Rect(x,c){
this.c = c;
this.w = w;
this.h = h;
this.x = x;
this.y = y;
this.draw = function(){
fill(c);
rect(x,h);
}
}
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.4/p5.min.js\"></script>
,您可以在draw函数中放置一个var来控制它是否必须显示您想要的内容。
void draw()
{
if (showThis)
{
image(image);
}
}
,添加noStroke();并使颜色与背景颜色相同?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。