This site requires JavaScript, please enable it in your browser!
Greenfoot back
vtn2@calvin.edu
vtn2@calvin.edu wrote ...

2012/5/9

How to draw lines with different thicknesses?

vtn2@calvin.edu vtn2@calvin.edu

2012/5/9

#
Does anyone have any ideas on how to draw lines with different thicknesses? (ala Scratch or processing where you can set the penWidth, and then draw a line). I don't see anyway to do it (easily) in greenfoot itself, and I don't see it in java.awt.Graphics either. Thanks.
dlanni dlanni

2012/5/9

#
Maybe you can use the fillRect--that will give you a solid line of any thickness. Yeah, it's meant for rectangles but that's what a thick line is.
tylers tylers

2012/5/9

#
this is what i did:
int thickness = 20;   // set the thickness here.

for(int i=0;i<thickness;i++){
            for(int j=0;j<thickness;j++){
                 img.drawLine(0+i,100+j,200+i,100+j);            
            }
        }
look at this http://www.greenfoot.org/topics/find/7930#post_7930 it might help.
vtn2@calvin.edu vtn2@calvin.edu

2012/5/9

#
Hmmm... using a fillRect() doesn't work if the line isn't horizontal. tylers: your solution would work (although I don't see the need for the i loop -- which just takes the line 20 pixels past the endpoint), but only work really well for horizontal lines as well. And it doesn't center the drawn line on the 1-pixel-wide line from the start point to end point... But, thanks for the ideas, anyway. Vic
danpost danpost

2012/5/9

#
How about the 'fillPolygon()' method. Take the four corner points (let us say (0, 10), (0, 15), (600, 300), and (600, 305)) and break them up, listing the x's and y's seperately
int[] xs = { 0, 0, 600, 600 };
int[] ys = { 10, 15, 300, 305 };
image.fillPolygon(xs, ys, 4);
You need to login to post a reply.