Need help in stroke and shape

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 53
Reputation: TheBuzzer is an unknown quantity at this point 
Solved Threads: 0
TheBuzzer TheBuzzer is offline Offline
Junior Poster in Training

Need help in stroke and shape

 
0
  #1
Jul 14th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 4
Reputation: yzg1236 is an unknown quantity at this point 
Solved Threads: 1
yzg1236 yzg1236 is offline Offline
Newbie Poster

Re: Need help in stroke and shape

 
0
  #2
Jul 14th, 2008
I am not very clear about your question.
Would you like to tell more about what are confusing you ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 413
Reputation: sciwizeh is on a distinguished road 
Solved Threads: 22
sciwizeh's Avatar
sciwizeh sciwizeh is offline Offline
Posting Pro in Training

Re: Need help in stroke and shape

 
0
  #3
Jul 14th, 2008
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
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "
-Albert Einstein
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 53
Reputation: TheBuzzer is an unknown quantity at this point 
Solved Threads: 0
TheBuzzer TheBuzzer is offline Offline
Junior Poster in Training

Re: Need help in stroke and shape

 
0
  #4
Jul 14th, 2008
Originally Posted by sciwizeh View Post
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 413
Reputation: sciwizeh is on a distinguished road 
Solved Threads: 22
sciwizeh's Avatar
sciwizeh sciwizeh is offline Offline
Posting Pro in Training

Re: Need help in stroke and shape

 
0
  #5
Jul 14th, 2008
like this?:Click image for larger version

Name:	703051.JPG
Views:	1
Size:	107.8 KB
ID:	6611

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
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "
-Albert Einstein
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 413
Reputation: sciwizeh is on a distinguished road 
Solved Threads: 22
sciwizeh's Avatar
sciwizeh sciwizeh is offline Offline
Posting Pro in Training

Re: Need help in stroke and shape

 
1
  #6
Jul 14th, 2008
ok:Click image for larger version

Name:	string.jpg
Views:	4
Size:	5.6 KB
ID:	6612
it's not perfect, and doesn't take into account orientation, but it illustrates my idea:
  1. public void paint(Graphics g){
  2. Graphics2D g2 = (Graphics2D) g;
  3. g2.setStroke(new BasicStroke(4,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
  4. for(int i=0;i<=80;i+=8){
  5. g2.setColor(new Color(0,0,0));
  6. g2.draw(makeSin(10+i,10,40+i,40));
  7. g2.setColor(new Color(128,128,128));
  8. g2.draw(makeSin(14+i,10,44+i,40));
  9. }
  10. }
  11. public CubicCurve2D.Double makeSin(double x,double y,double x2,double y2){
  12. return new CubicCurve2D.Double(x,y,(x+x2)/2,y,(x+x2)/2,y2,x2,y2);
  13. }

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)
Last edited by sciwizeh; Jul 14th, 2008 at 11:55 pm.
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "
-Albert Einstein
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 53
Reputation: TheBuzzer is an unknown quantity at this point 
Solved Threads: 0
TheBuzzer TheBuzzer is offline Offline
Junior Poster in Training

Re: Need help in stroke and shape

 
0
  #7
Jul 15th, 2008
Originally Posted by sciwizeh View Post
ok:Attachment 6612
it's not perfect, and doesn't take into account orientation, but it illustrates my idea:
  1. public void paint(Graphics g){
  2. Graphics2D g2 = (Graphics2D) g;
  3. g2.setStroke(new BasicStroke(4,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
  4. for(int i=0;i<=80;i+=8){
  5. g2.setColor(new Color(0,0,0));
  6. g2.draw(makeSin(10+i,10,40+i,40));
  7. g2.setColor(new Color(128,128,128));
  8. g2.draw(makeSin(14+i,10,44+i,40));
  9. }
  10. }
  11. public CubicCurve2D.Double makeSin(double x,double y,double x2,double y2){
  12. return new CubicCurve2D.Double(x,y,(x+x2)/2,y,(x+x2)/2,y2,x2,y2);
  13. }

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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 53
Reputation: TheBuzzer is an unknown quantity at this point 
Solved Threads: 0
TheBuzzer TheBuzzer is offline Offline
Junior Poster in Training

Re: Need help in stroke and shape

 
0
  #8
Jul 15th, 2008
Originally Posted by sciwizeh View Post
like this?:Attachment 6611

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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 413
Reputation: sciwizeh is on a distinguished road 
Solved Threads: 22
sciwizeh's Avatar
sciwizeh sciwizeh is offline Offline
Posting Pro in Training

Re: Need help in stroke and shape

 
0
  #9
Jul 15th, 2008
Originally Posted by TheBuzzer View Post
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.
Originally Posted by TheBuzzer View Post
Just the coding is more complex and you go in steps along the line.
got an example?
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "
-Albert Einstein
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 53
Reputation: TheBuzzer is an unknown quantity at this point 
Solved Threads: 0
TheBuzzer TheBuzzer is offline Offline
Junior Poster in Training

Re: Need help in stroke and shape

 
0
  #10
Jul 15th, 2008
Originally Posted by sciwizeh View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC