我有这段代码,我应该对其进行修改以执行2件事:
lights()
和唯一的fill()
)以实心模式绘制表面,并且fill()
调用这是我的第一个代码,问题是我不希望在应用颜色后显示网格。
// Drawing a 3D function
float rotX = 0.0, rotY = 0.0;
int lastX, lastY;
float distX = 0.0, distY = 0.0;
// Function steps
int steps = 50;
// z scale
float scaleZ = 200.0;
// z zoom
float zoomZ = -300.0;
// Graphic size
float gX = 500.0, gY = 500.0;
void setup()
{
size(500, 500, P3D);
noFill();
strokeWeight(0.005);
}
float function(float x, float y)
{
return x*x*x + y*y*y;
}
void draw() {
lights();
background(0);
// We center the results on window
translate(gX/2, gY/2, zoomZ);
// Rotation
rotateY(rotY + distX);
rotateX(rotX + distY);
// Centering around (0, 0);
translate(-gX/2, -gY/2);
// Function covers
// 400 x 400 x scaleZ
scale(gX, gY, scaleZ);
// Drawing the function
fill(167);
drawFunction();
// Drawing axes
stroke(255, 0, 0);
line(0,0,0,2000,0,0);
stroke(0,255,0);
line(0,0,0,0,2000,0);
stroke(0,0,255);
line(0,0,0,0,0,2000);
}
void drawFunction()
{
float x, y, z;
int i = 0, j = 0;
float in_steps = 1.0 / steps;
float[][] matrix = new float[steps+1][steps+1];
for (y = 0.0, j = 0; y <= 1.0; y+=in_steps, j++)
for (x = 0.0, i = 0; x <= 1.0; x+=in_steps, i++)
matrix[i][j] = function(x, y);
stroke(167);
for (j = 0, y = 0.0; j < steps; j++, y+=in_steps) {
beginShape(QUAD_STRIP);
for (i = 0, x = 0.0; i <= steps; i++, x+=in_steps) {
vertex(x, y, matrix[i][j]);
vertex(x, y + in_steps, matrix[i][j+1]);
}
endShape();
}
}
void mousePressed()
{
lastX = mouseX;
lastY = mouseY;
}
void mouseDragged()
{
distX = radians(mouseX - lastX);
distY = radians(lastY - mouseY);
}
void mouseReleased()
{
rotX += distY;
rotY += distX;
distX = distY = 0.0;
}
答案 0 :(得分:0)
lights()
已在您的代码中正确设置。
使用noStroke()
删除行。 noStroke
禁用图形轮廓。
可以通过将RGB(红色,绿色和蓝色)值传递到fill()
来设置填充区域的颜色。
这些值是整数值,范围为[0,255]。红色的RGB vlaue是(255,0,0),黄色的RGB值是(255,255,0)。
可以实现从红色到黄色的渐变颜色
fill(255, z*255, 0);
其中z在[0.0,1.0]中。如果z = 0.0
的结果为红色(255、0、0),如果z = 1.0
的结果为黄色(255、255、0)。 z的所有值都在0.0到1.0之间,会导致读取和黄色之间线性插值。
例如
for (j = 0, y = 0.0; j < steps; j++, y+=in_steps) {
beginShape(QUAD_STRIP);
noStroke(); // no lines
for (i = 0, x = 0.0; i <= steps; i++, x+=in_steps) {
fill(255, matrix[i][j] * 255, 0); // interpolate between red and yellow
vertex(x, y, matrix[i][j]);
fill(255, matrix[i][j+1] * 255, 0); // interpolate between red and yellow
vertex(x, y + in_steps, matrix[i][j+1]);
}
endShape();
}