PLAYGROUND (experimental)

triangle_right

triangle_right(cx, cy, a, b, angle, [from=true], [draw=true], [stroke=#000000], [fill=#FFFFFF], [weight=1.00])

Draw a right triangle

Syntaxe

triangle_right( cx=200, cy=200, a=100, b=100, angle=PI , from=true , stroke="#000000", fill="#FFA000", weight=4);

Arguments

NameRequiredDefaultDescription
cxyes-x-coordinate of the reference point
cyyes-y-coordinate of the reference point
ayes-length of side A (Cathetus1, adjacent to right angle)
byes-length of side B (Cathetus2, adjacent to right angle)
angleyes-rotation angle in radians
from-truetrue: ref point is right angle (by default), false: ref point is hypotenuse center,
draw-trueIf false, return a list of points, and don't draw (stroke, fill & weight are ignored)
stroke-#000000Stroke color
fill-#FFFFFFFill color
weight-1.00Stroke weight (thickness)

Full example


canvas(500, 500, "#EAEBEB");

stroke("#767676");
weight(10);
triangle_right( cx=width(), cy=height(), a=200, b=100, angle=PI , from=true , fill="#E5DECE");
triangle_right( cx=0, cy=0, a=200, b=100, angle=0 , from=true ,  fill="#E2D7A8");
triangle_right( cx=0, cy=height(), a=-200, b=-100, angle=HALF_PI , from=true ,  fill="#D2BE6C");
triangle_right( cx=width(), cy=0, a=-200, b=-100, angle=-HALF_PI , from=true , fill="#A78B5B");



coord_translate(width()/2, height()/2);

var w = 300;
var h = w;
var u = w / 4;

stroke("#000");
weight(1);

// 2 grands triangles
triangle_right(cx=0, cy=0, a=u*2*sqrt(2), b=u*2*sqrt(2), angle=PI*5/4, from=true, fill="#66BB6A");
triangle_right(cx=0, cy=0, a=u*2*sqrt(2), b=u*2*sqrt(2), angle=PI*3/4, from=true, fill="#EF5350");
// 1 triangle moyen
triangle_right(cx=u*2, cy=u*2, a=u*2, b=u*2, angle=PI, from=true, fill="#BDBDBD");
// 1 carré
polygon([u,-u, u*2,0, u,u, 0,0], fill="#FFCA28");
// 2 petits triangles
triangle_right(cx=u, cy=-u, a=u*sqrt(2), b=u*sqrt(2), angle=-PI/4, from=true, fill="#EC407A");
triangle_right(cx=0, cy=0, a=u*sqrt(2), b=u*sqrt(2), angle=PI/4, from=true, fill="#26C6DA");
// 1 parallélogramme
polygon([-u*2,u*2, 0,u*2, u,u, -u,u], fill="#7E57C2");

save(whoami() + ".png");

// var t = triangle_right( cx=200, cy=200, a=100, b=100, angle=PI , from=true , draw=false);
// console(t);