We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
"tape" line (Read 518 times)
"tape" line
Aug 25th, 2009, 8:02am
 
Hi everybody.
I cannot find a good way to draw a "tape" i.e. a thick line (stroke(30)) composed by consecutive segments that run randomly through the screen like a chain.

I want to paint each segment in a different color and surround the whole tape by a thick black perimeter. The tape begins and ends outside the screen, so it is not important if the black perimeter is not perfect at the tape extremes.

I wrote a version using rect() instead of line() but I'm searching for something more "elegant".

Any snippet or example to study?
Thx in advance,
Apok
Re: "tape" line
Reply #1 - Aug 25th, 2009, 8:59am
 
I'm not sure I follow exactly what you're trying to achieve...  Surely a loop across the width of the screen adding rects as you go would do the trick?

Maybe you should post your code and let people know what you want to do next...
Re: "tape" line
Reply #2 - Aug 25th, 2009, 9:47am
 
maybe he wants it to look more dynamic, using rects would probably be a problem then. Maybe you can use a quadstrip. Although im not sure if you can color the segments different
Re: "tape" line
Reply #3 - Aug 25th, 2009, 10:53am
 
I'm pretty sure quadstrip can only be one colour; but you're right beginShape(TRIANGLES) and then plotting a bunch of vertices should probably do the trick, maybe using a sine wave with random offset to control the position...
Re: "tape" line
Reply #4 - Aug 25th, 2009, 11:51am
 
good idea, maybe he can just add a texture to the quadstrip.

see this for help:
http://processing.org/discourse/yabb2/?board=OpenGL%3Baction=display%3Bnum=1206567685
Re: "tape" line
Reply #5 - Aug 25th, 2009, 11:57am
 
it works...

void setup()
{
 size(200, 200);
 noStroke();
}

void draw()
{
beginShape(TRIANGLE_STRIP);
fill(255,0,0);
vertex(30, 75);
vertex(40, 20);
vertex(50, 75);
fill(255,0,255);
vertex(60, 20);
vertex(70, 75);
fill(0,0,255);
vertex(80, 20);
vertex(90, 75);
endShape();
}

Re: "tape" line
Reply #6 - Aug 25th, 2009, 2:26pm
 
Thank you for your quick reply!

I send you a snippet to show what I mean:

Code:
colorMode(HSB);
strokeCap(BEVEL);
size(170,170);
background(255);
smooth();

// tape
noStroke();
fill(0,255,255);
quad(0,50,60,50,80,30,0,30);
fill(25,255,255);
quad(60,50,80,30,130,50,110,70);
fill(50,255,255);
quad(130,50,110,70,180,140,200,120);

// border
stroke(0);
strokeWeight(6);
noFill();
beginShape();
vertex(0,50);
vertex(60,50);
vertex(110,70);
vertex(180,140);
endShape();
beginShape();
vertex(0,30);
vertex(80,30);
vertex(130,50);
vertex(200,120);
endShape();


Up to now I can draw rectangles to simulate the thick line or to use quads (the 3 zones respectively red, orange and yellow); later I draw the black border.
This is "expensive" and not so elegant.

I would prefere to find a way to draw a thick 30pt chain of lines (each segment with its own color)  on a thicker (40pt) black "shadow": this superimpose leaves the two lateral borders. This version is definitely easier to calculate  and result is more pleasant.
I tried this to change the color while drawing each segment but it doesn't work:

Code:
noFill();
beginShape();
stroke(180,255,255);
vertex(0,50);
vertex(60,50);
stroke(0,255,255);
vertex(110,70);
stroke(90,255,255);
vertex(180,140);
endShape();


Any idea?
Thx Apok
Page Index Toggle Pages: 1