试图为三个顶点着色

时间:2014-09-11 22:54:18

标签: colors vertex

我试图绘制三条线,改变第二和第三条的重量,并为第二条和第三条着色。我想我正在做所有正确的事情,但事情并没有奏效。 而不是线我使用顶点,但代码不正常 - 没有颜色。 谢谢您的帮助。我确信它是 dumb 我缺少的东西。

//write the code to draw  3 lines 
//
//set the area size
size(100,200);
//
smooth();  //not needed for lines but there for comment

background(#FCFDFF);  //go white
//line(x1,y1,x2,y2);
//but doesn't work to for fill color. Use vertex
//vertex(x, y)
//x   float: x-coordinate of the vertex
//y   float: y-coordinate of the vertex
//z   float: z-coordinate of the vertex
//
//set stroke using strokeWeight
//draw first line with a stroke weight of 3
beginShape(LINES);
background(#FFFFFF);
strokeWeight(3);
vertex(20, 30);
vertex(20, 90);
//
//draw second line with stroke weight of 5 and color it RED
//second line
strokeWeight(5);
fill(255,0,0);
vertex(40, 30);
vertex(40, 90);
//
//draw third line with rounded ends and stroke weight
//of 7 and PURPLE
//
strokeWeight(7);
strokeJoin(ROUND);
fill(#C811F2);
vertex(60, 30);
vertex(60, 90);
endShape();

//end of program

//NEW code I wrote - 
size(100,200);
background(#FCFDFF);  //go white
//draw 3 lines
//line(x1,y1,x2,y2);
//but doesn't work to fill color. Use vertex and stroke();
//vertex(x, y)
//x   float: x-coordinate of the vertex
//y   float: y-coordinate of the vertex
//z   float: z-coordinate of the vertex
//set stroke using strokeWeight
//draw first line with a stroke weight of 3
//noStroke();
beginShape(LINES);
background(#FFFFFF);
//
strokeWeight(3);
vertex(20, 30);  //top
vertex(20, 90);  //bottom
//
//draw second line with stroke weight of 5 and RED
//
stroke(255,0,0);
strokeWeight(5);
vertex(40, 30);  //top
vertex(40, 90);  //bottom
//
//draw third line with rounded ends and stroke weight
//of 7 and PURPLE
//
stroke(#C40FD8);
strokeWeight(7);
strokeJoin(ROUND);
vertex(60, 30);  //top
vertex(60, 90);  //bottom
endShape();
//end of program

2 个答案:

答案 0 :(得分:0)

一种简单的方法是绘制线条,然后在顶点绘制圆圈。

//write the code to draw  3 lines 
//
//set the area size
size(100,200);
//
smooth();  //not needed for lines but there for comment

background(#FCFDFF);  //go white
//line(x1,y1,x2,y2);
//but doesn't work to for fill color. Use vertex
//vertex(x, y)
//x   float: x-coordinate of the vertex
//y   float: y-coordinate of the vertex
//z   float: z-coordinate of the vertex
//
//set stroke using strokeWeight
//draw first line with a stroke weight of 3
beginShape(LINES);
background(#FFFFFF);
strokeWeight(3);
vertex(20, 30);
vertex(20, 90);
ellipse(20, 30, 10, 10);
ellipse(20, 90, 10, 10);
//
//draw second line with stroke weight of 5 and color it RED
//second line
strokeWeight(5);
fill(255,0,0);
vertex(40, 30);
vertex(40, 90);
ellipse(40, 30, 10, 10);
ellipse(40, 90, 10, 10);
//
//draw third line with rounded ends and stroke weight
//of 7 and PURPLE
//
strokeWeight(7);
strokeJoin(ROUND);
fill(#C811F2);
vertex(60, 30);
vertex(60, 90);
ellipse(60, 30, 10, 10);
ellipse(60, 90, 10, 10);
endShape();

可能无法完全按照您的意愿工作,但如果您稍微调整它,它应该可以正常工作。如果这不是您想要的样子,请告诉我。

答案 1 :(得分:0)

咄....
忘了不使用fill();使用stroke();