改变笔划的颜色
Change color of stroke
我想更改 笔触的颜色 但我不知道 如何正确地做到这一点 我查找了教程,它向我展示了代码中的 hu 内容。它改变了 for 循环中的 hu 但它只保持一种颜色.. 在我的例子中是黄色的
void setup(){
size(500,500);
colorMode(HSB);
}
float t = 0;
float tn = 0;
void draw(){
background(0);
translate(width / 2, height / 2);
noFill();
stroke(255);
strokeWeight(2);
float hu = 0;
beginShape();
//add vertices...
for(float theta = 0; theta <= 8 * PI; theta += 0.001){
float rad = r(theta,
1, //a
1, //b
sin(tn) * 0.1 + 5, //m
cos(tn) / 2, //n1
sin(t) * 0.5 + 0.5, //n2
cos(t) * 0.5 + 0.5 //n3
);
float x = rad * cos(theta) * 50;
float y = rad * sin(theta) * 50;
stroke(hu, 255, 255);
vertex(x,y);
hu += 1;
if(hu > 255){
hu = 0;
}
}
endShape();
t += 0.1;
tn += 0.1;
}
float r(float theta, float a, float b, float m, float n1, float n2, float n3){
return pow(pow(abs(cos(m * theta / 4.0) / a), n2) +
pow(abs(sin(m * theta / 4.0) / b), n3), -1.0 / n1) ;
}
beginShape
功能请咨询the Processing reference:
The P2D and P3D renderers allow stroke() and fill() to be altered on a per-vertex basis, but the default renderer does not.
换句话说,您不能使用默认渲染器像这样更改描边颜色。您可以改用 P2D
渲染器:
size(500, 500, P2D);
如果您出于某种原因需要使用默认渲染器,那么您将不得不自己绘制线条,而不是依赖 vertex
函数。
我想更改 笔触的颜色 但我不知道 如何正确地做到这一点 我查找了教程,它向我展示了代码中的 hu 内容。它改变了 for 循环中的 hu 但它只保持一种颜色.. 在我的例子中是黄色的
void setup(){
size(500,500);
colorMode(HSB);
}
float t = 0;
float tn = 0;
void draw(){
background(0);
translate(width / 2, height / 2);
noFill();
stroke(255);
strokeWeight(2);
float hu = 0;
beginShape();
//add vertices...
for(float theta = 0; theta <= 8 * PI; theta += 0.001){
float rad = r(theta,
1, //a
1, //b
sin(tn) * 0.1 + 5, //m
cos(tn) / 2, //n1
sin(t) * 0.5 + 0.5, //n2
cos(t) * 0.5 + 0.5 //n3
);
float x = rad * cos(theta) * 50;
float y = rad * sin(theta) * 50;
stroke(hu, 255, 255);
vertex(x,y);
hu += 1;
if(hu > 255){
hu = 0;
}
}
endShape();
t += 0.1;
tn += 0.1;
}
float r(float theta, float a, float b, float m, float n1, float n2, float n3){
return pow(pow(abs(cos(m * theta / 4.0) / a), n2) +
pow(abs(sin(m * theta / 4.0) / b), n3), -1.0 / n1) ;
}
beginShape
功能请咨询the Processing reference:
The P2D and P3D renderers allow stroke() and fill() to be altered on a per-vertex basis, but the default renderer does not.
换句话说,您不能使用默认渲染器像这样更改描边颜色。您可以改用 P2D
渲染器:
size(500, 500, P2D);
如果您出于某种原因需要使用默认渲染器,那么您将不得不自己绘制线条,而不是依赖 vertex
函数。