0

I am trying to draw three lines, change the weight of the 2nd and third, and color the 2nd and third. I think I am doing all the right things but things aren't working. Instead of lines I am using a vertex, but the code is not working right -- no colors. Thanks for the help. I am sure it's something dumb I am missing.

//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
Waynewal
  • 1
  • 2

2 Answers2

0

An easy way to do this would be to draw lines, and then draw circles at the vertices.

//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();

May not work exactly like you want, but it should work if you tweak it a bit. Let me know if that's not what you intended it to look like.

Ideasthete
  • 1,553
  • 13
  • 22
  • Actually this was the code I finally came up with. I my have to modify the 2nd 'line' to be squared off' on the ends. – Waynewal Sep 12 '14 at 03:54
  • Forgot to say THANK YOU for the help. My mail didnt catch this answer. Your suggestion worked quite well. Sorry for the delay. – Waynewal Nov 21 '14 at 15:53
0

Duh....
forgot not to use fill(); use stroke();

Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
Waynewal
  • 1
  • 2
  • Thanks! Will edit the end of the program above. Appreciate your time in trying to help, but need 2 vertical lines with progressively wider lines and the 2nd and 3rd in color. – Waynewal Sep 12 '14 at 03:58