polygon_regular
polygon_regular(x, y, radius, side, [rotation], [draw=true], [stroke], [fill], [weight])
Draw a regular polygon
Syntaxe
polygon_regular(x=12, y=20, radius=100, side=6, rotation=PI, stroke="#000000", fill="#FFA000", weight=4);
Arguments
| Name | Required | Default | Description |
|---|---|---|---|
x | yes | - | x-coordinate of the center |
y | yes | - | y-coordinate of the center |
radius | yes | - | Radius of the polygon |
side | yes | - | number of sides |
rotation | - | - | rotation (defaut=0) |
draw | - | true | If false, return a list of points, and don't draw (stroke, fill & weight are ignored) |
stroke | - | - | Stroke color |
fill | - | - | Fill color |
weight | - | - | Stroke weight (thickness) |
Full example
var cols = 4;
var spacing = 100;
var r = 30;
var startside = 18;
canvas(width=spacing*cols+r, height=spacing*cols+r);
fill("#FFA000");
coord_translate(r*2,r*2);
for (var i = startside; i >= 3; i--) {
var col = (startside - i) % cols;
var row = floor((startside - i) / cols);
var x = col * spacing;
var y = row * spacing;
polygon_regular(x=x, y=y, radius=r, side=i, rotation=0);
}
save("polygon_regular.png");
var p = polygon_regular(x=10, y=10, radius=r, side=6, rotation=0, draw=false);
console(p); // [25, -15.9807621135, 40, 10, 25, 35.9807621135, ...]
