pushMatrix error
in
Programming Questions
•
9 months ago
I am currently attempting to get a star-shaped geometry to rotate around its center, but to no avail!
I am either continually met with 'pushMatrix() cannot use push more than 32 times', or, when that is removed, I end up with 'StackOverflowError:This sketch is attempting too much recursion'
I'm afraid I am very new to processing so I'm struggling to find a solution, even after many trawls through the tinter!
Any help gratefully received!
The code:
//VARIABLES
float angle;
//SETUP
void setup( )
{
size(500, 500);
background(55);
smooth();
fill(102,102,102,50);
stroke (255);
strokeWeight (2);
//DRAW STAR
star(5, 250, 250, 450, 450, -PI / 2.0, 0.50);
}
void star(int n, float cx, float cy, float w, float h,
float startAngle, float proportion)
{
{
float angle = TWO_PI/ (2 *n);
float dw;
float dh;
w = w / 2.0;
h = h / 2.0;
beginShape();
for (int i = 0; i < 2 * n; i++)
{
dw = w;
dh = h;
if (i % 2 == 1)
{
dw = w * proportion;
dh = h * proportion;
}
vertex(cx + dw * cos(startAngle + angle * i),
cy + dh * sin(startAngle + angle * i));
}
}
//ROTATE
{
pushMatrix();
endShape(CLOSE);
rectMode(CENTER);
translate(250,250);
rotate(radians (45));
star(5, 250, 250, 450, 450, -PI / 2.0, 0.50);
popMatrix();
}
}
1