rectangle
rectangle([points], [x], [y], [w], [h], [radius=0], [center], [stroke], [fill], [weight])
Draw a rectangle
Syntaxe
rectangle(x=10, y=10, w=15, h=15, stroke="#000000", fill="#FFA000", weight=4)
rectangle(points=[10,10, 15,15], stroke="#388E3C", fill="transparent", weight=5)
Arguments
| Name | Required | Default | Description |
|---|---|---|---|
points | - | - | List of points [x1,y1,x2,y2] - beware: x2,y2 are not the dimension of rect! |
x | - | - | x-coordinate |
y | - | - | y-coordinate |
w | - | - | Width |
h | - | - | Height |
radius | - | 0 | Corner radius |
center | - | - | if true, x/y are the center of rectangle |
stroke | - | - | Stroke color |
fill | - | - | Fill color |
weight | - | - | Stroke weight (thickness) |
Full example
canvas(width=800, height=400);
load_text_default(16);
fill("#000");
rectangle(points=[10,10, 150,100], stroke="#388E3C", fill="transparent", weight=5);
rectangle(x=250, y=100, w=150, h=100);
rectangle(x=250, y=200, w=150, h=100, radius=25, stroke="#000000", fill="#FFA000", weight=4);
rectangle(x=250, y=300, w=150, h=100, radius=35, center=true, stroke="#000000", fill="transparent", weight=4);
text("Negative w / h + radius", 600,100);
rectangle(x=550, y=100, w=-100, h=-50, radius=25); // negative dimension
text("Point x2,y2 < to x1,y1", 520,250);
rectangle(points=[470,250, 420,150], radius=10, center=true, stroke="#383C8E", fill="transparent", weight=5);
save("rectangle.png");
