This site requires JavaScript, please enable it in your browser!
Greenfoot back
K_O_P
K_O_P wrote ...

2012/2/5

Drawing a triangle

K_O_P K_O_P

2012/2/5

#
Hey guys! I've got a question. I know, how to fill a rectangle and an oval. But I've got no idea, how to fill a triangle... Can someone help me, plz?
danpost danpost

2012/2/5

#
Set up two arrays of integers of length three (3); one for the x-coordinates of the points of the triangle, and one for the y-coordinates (of course, one point would be the such that x = first element in first array, and y = first element in second array, etc.). Then you can use those arrays in the drawPolygon(xs, ys, 3) and fillPolygon(xs, ys, 3) methods (see the documentation in GreenfootImage). Example:
int[] xs = { 10, 50, 50 };
int[] ys = { 100, 60, 140 };
GreenfootImage img = new GreenfootImage(200, 200);
img.fillPolygon(xs, ys, 3);
img will now have a triangle on in filled with the current drawing color.
K_O_P K_O_P

2012/2/5

#
ah! Thank you very much!
You need to login to post a reply.