#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Draw a triangle with pushMatrix and popMatrix

Hello everyone,

I am trying to draw a triangle using pushMatrix(), popMatrix(), and rotate(). But it doesn't seem that the rotation works. I tried the method using line(x1, y1, x2, y2) command and the rotation works fine. I wonder what I am doing wrong with the beginShape() command.

Thank you for your help.

Below is my code.

``````color baseShade = color(108, 245, 72);
float len1 = random(40, 80);
float len2 = random(50, 60);

void setup() {
size(400, 400);
background(40);
smooth();
}

void draw() {
background(40);
drawTriangle(120, len1, len2);
}

void drawTriangle(float angle, float len1, float len2) {
pushMatrix();
translate(width/2, height/2);
//line(0, 0, len1, 0);
//line(0, 0, len2, 0);
beginShape(TRIANGLES);
vertex(0, 0);
vertex(len1, 0);

vertex(len2, 0);
endShape(CLOSE);
popMatrix();
}
``````
Tagged:

• Found the answer myself from the beginShape() reference page.

"Transformations such as translate(), rotate(), and scale() do not work within beginShape(). It is also not possible to use other shapes, such as ellipse() or rect() within beginShape(). "

It is also not possible to use other shapes, such as ellipse() or rect() within beginShape()

Well, you can, but not to construct the shape that you're using the vertices (or curveVertices) for:

``````beginShape();
for(int i = 0; i < 6; i++)
{
vertex(random(width), random(height));

ellipse(random(width), random(height), 3, 3);
}
endShape(CLOSE);
``````
• Sorry for the late of my reply. Thank you for your help, allonestring.