我正在尝试制作一个围绕其中心旋转的阴阳,并且我已经弄清楚了它的所有代码。除了当我开始旋转阴阳时,我绘制的白色弧线之一在其直径上有一个非常细的弦。我将模式设置为“OPEN”,当对象不旋转时,弦不会出现。我知道这是处理渲染器的渲染错误,所以有人知道如何解决这个问题吗?
这是代码:
float rot = 0;
void setup (){
background(150);
size(800,800);
}
void draw (){
rot = rot+0.01;
translate(400,400);
rotate(rot);
background(150);
yinyang();
}
void yinyang (){
fill(255);
strokeWeight(2);
ellipse(0,0,400,400);
fill(0);
arc(0,0,400,400,-HALF_PI,HALF_PI);
ellipse(0,100,200,200);
fill(255);
arc(0,-100,200,200,-HALF_PI,HALF_PI,OPEN);
ellipse(0,100,66,66);
fill(0);
ellipse(0,-100,66,66);
}
我非常清楚许多对象都是以非常低效的方式绘制的。这是一个学校项目,我只是想完成它。问题弧是唯一一个具有 OPEN 类的弧。
我尝试使用其他对象(例如圆圈和线条)来掩盖它,但是所述对象的边界存在问题,所以我停止尝试这样做。这也感觉像是作弊,我想知道如何真正解决问题,而不是仅仅掩盖它。
有几种解决方案。
要使用您的代码,请省略第二条弧线。画第二个没有描边的白色圆圈:
float rot = 0;
void setup (){
background(150);
size(800,800);
}
void draw (){
rot = rot+0.01;
translate(400,400);
rotate(rot);
background(150);
yinyang();
}
void yinyang (){
fill(255);
strokeWeight(2);
ellipse(0,0,400,400);
fill(0);
arc(0,0,400,400,-HALF_PI,HALF_PI);
ellipse(0,100,200,200);
fill(255);
// arc(0,-100,200,200,-HALF_PI,HALF_PI,OPEN);
noStroke();
ellipse(0, -100, 200, 200); // white Circle
ellipse(0,100,66,66);
fill(0);
ellipse(0,-100,66,66);
}
替代解决方案:
float rot = 0;
void setup () {
size(800, 800);
}
void draw () {
background(150);
rot = rot+0.01;
translate(400, 400);
rotate(rot);
yinyang();
}
void yinyang () {
fill(255);
circle(0, 0, 400); // large white circle
fill(0);
arc(0, 0, 400, 400, -HALF_PI, HALF_PI);
circle(0, 100, 200); // black Circle
fill(255);
circle(0, 100, 66); // eye of black circle
fill(255);
noStroke();
circle(0, -100, 200); // white Circle
fill(0);
circle(0, -100, 66); // eye of white circle
}