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

2013/5/9

How to draw a Polygon ?

Clem Clem

2013/5/9

#
Hi, first excuse my writing ( i'm French). This must be really easy but I'm not able to use the class drawPolygon because I just barely studied arrays at school, and only had 2 hours of greenfoot with the teacher. I tried to code this but it doesn't work (I filled the arrays before) : " i=0; while (i != nPoints) { Image.drawPolygon(xPoints , yPoints ,nPoints); i=i+1; } " Could anyone please give me an exemple of the method ?
danpost danpost

2013/5/9

#
Here is a method to draw the outline of a house:
private GreenfootImage drawHouse(int size)
{
    GreenfootImage image = new greenfootImage(size, size0;
    int[] xs = { size/2, 0, 0, size, size };
    int[] ys = { 0, size/3, size, size, size/3 };
    image.drawPolygon(xs, ys, 5);
    return image;
}
You may need to set the drawing color of the image before drawing the polygon.
Clem Clem

2013/5/10

#
The drawing works, thanks a lot !
You need to login to post a reply.