Regular polygons procedure for canvas (can be adapted for maps)

A polygon is a closed area. It can be irregular, where the points are anywhere, or they can be regular, which means they are equiangular and equilateral like in this picture.

image

Kodular included a DrawPolygon method recently but for now it clears the canvas everytime is used, deleting anything in it except for sprites. Until that is fixed, this procedure might be of help if you need to keep your previous canvas content when drawing a polygon.

App Inventor and Kodular both has a method to draw irregular polygons, both in the canvas and in the maps.

Using that method, this procedure will let you draw a REGULAR POLYGON almost the same way you use the circle method, by specifying the center and the radius. But you also need the number of sides, the starting angle (which is a rotation so you can change the “orientation” or “heading” of the polygon) and a boolean entry to have the polygon filled (true) or just the outline (false).

Capture

I hope you can find this procedure useful in your apps.


DrawRegularPolygon_procedure.aia (3.1 KB)

(For using in maps, replace the Canvas.DrawShape procedure for the map one).

9 Likes

Thank you for sharing !

2 Likes

Hi

Can I use this procedure on the Google Maps?

Do I need to specify lat and lng instead of x and y?

Honestly I never used it with maps but yes, you will have to adapt it. The procedure generates a list of x,y coordinates in the canvas x,y system. You will have to convert those somehow to latitude and longitude, based on the center point.

Do you know if it is possible to put the fill of the polygon semitransparent, not solid color?

Put fill to false i think