Hi, I am trying to make stroke and shape make a path like two sin curves.


so a path from x,y to x2,y2 first is like ------------------------- will become
/\/\/\/\/\/\/\/\
\/\/\/\/\/\/\/\/

if you understand what i mean.

I am very confused am I suppose to be changing the shape or the stroke to make a line from xy to x2x2 with a sign curve shape.

I am not very clear about your question.
Would you like to tell more about what are confusing you ?

if you have to use a Shape i would go with a CubicCurve2D
the sun tutorial that covers these is here

to get one period of a sin or cos wave you need two of these

if not explain what you need to do in more detail

if you have to use a Shape i would go with a CubicCurve2D
the sun tutorial that covers these is here

to get one period of a sin or cos wave you need two of these

if not explain what you need to do in more detail

well i want to be able to draw a line that looks like a thread.

so i think it have to do with stroke.

threads are like a group of strings wrapped together kind of similer to wires.

would be cool if i pass x1,y1,x2,y2, and a color and it will have shades of the color wrapping around

like this?:


if so, then plainly stroke won't do it, i don't think, i would still use CubicCurve2D, ill write a bit of sample code, but it may take a moment

ok:

it's not perfect, and doesn't take into account orientation, but it illustrates my idea:

public void paint(Graphics g){
        Graphics2D g2 = (Graphics2D) g;
        g2.setStroke(new BasicStroke(4,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
        for(int i=0;i<=80;i+=8){
            g2.setColor(new Color(0,0,0));
            g2.draw(makeSin(10+i,10,40+i,40));
            g2.setColor(new Color(128,128,128));
            g2.draw(makeSin(14+i,10,44+i,40));
        }
    }
    public CubicCurve2D.Double makeSin(double x,double y,double x2,double y2){
        return new CubicCurve2D.Double(x,y,(x+x2)/2,y,(x+x2)/2,y2,x2,y2);
    }


the setStroke() only makes it bigger and doesn't effect the look otherwise adding orientation may be difficult this way but i'll give it a shot if asked... (PS: Ask, i almost want to see if i can)

commented: Pfftt, and you said you sucked at art? =P +1

ok:[ATTACH]6612[/ATTACH]
it's not perfect, and doesn't take into account orientation, but it illustrates my idea:

public void paint(Graphics g){
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(4,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
for(int i=0;i<=80;i+=8){
g2.setColor(new Color(0,0,0));
g2.draw(makeSin(10+i,10,40+i,40));
g2.setColor(new Color(128,128,128));
g2.draw(makeSin(14+i,10,44+i,40));
}
}
public CubicCurve2D.Double makeSin(double x,double y,double x2,double y2){
return new CubicCurve2D.Double(x,y,(x+x2)/2,y,(x+x2)/2,y2,x2,y2);
}

the setStroke() only makes it bigger and doesn't effect the look otherwise adding orientation may be difficult this way but i'll give it a shot if asked... (PS: Ask, i almost want to see if i can)

interesting. This might work. thanks. mgith ask later if i got anymore question

like this?:[ATTACH]6611[/ATTACH]

if so, then plainly stroke won't do it, i don't think, i would still use CubicCurve2D, ill write a bit of sample code, but it may take a moment

I think using stroke is possible because stroke is a shape also. Just the coding is more complex and you go in steps along the line.

While without using stroke you just do a loop long the line.

I going to try to draw the same idea as a stroke still. I think it is possible and would be better to be able to ever reuse the method

I think using stroke is possible because stroke is a shape also.

what? no it isn't, stroke doesn't extend shape, and BasicStroke doesn't implement it either.

Just the coding is more complex and you go in steps along the line.

got an example?

what? no it isn't, stroke doesn't extend shape, and BasicStroke doesn't implement it either.
got an example?

http://www.jhlabs.com/java/java2d/strokes/

I was coding it using stroke method but I stopped becuase It does not do color blending when strokes overlap each other.

Also stroke was kind of weird you need to draw lines as a polygon shape for it to fill nicely


So better way was to do what u did and not use strokes.

the line coloring wasnt looking that great. I might have to use a thread image with a color mask to make it look better.

thats interesting, i didn't know that you could do some of those things with stroke.

good to help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.