Well - clearly you can't create the array before you know how long it's going to be, but you do at least need to declare its existence:
Code:class Fl {
float w;
float angle;
int fl_corners;
PVector [] vertices;
Fl (int fl_corners_, float w_) {
fl_corners = fl_corners_;
vertices = new PVector[fl_corners];
w = w_;
angle = 360/fl_corners;
for (int i=0; i<fl_corners; i++)
{
vertices[i] = new PVector((w/2)*cos(radians(angle)), (w/2)*sin(radians(angle)));
}
}
void create()
{
beginShape();
for (int i=0; i<fl_corners; i++)
{
vertex(vertices[i].x, vertices[i].y);
}
endShape();
}
}
A couple of minor points on coding style:
1. What's an 'Fl'? If you're going to create a class you need to give it a meaningful name so people know what they're going to use it for
2. I find all those underscores in the argument names really ugly and actually a little difficult to read. It's a matter of taste, but you can use the same name as the variable for the argument in a constructor and precede the Object variable with 'this' - e.g.:
Code:class myPolygonClass {
float w;
float angle;
int corners;
PVector [] vertices;
myPolygonClass (int corners, float w) {
this.corners = corners;
this.vertices = new PVector[corners];
this.w = w;
this.angle = 360/corners;
for (int i=0; i<corners; i++) {
vertices[i] = new PVector((w/2)*cos(radians(angle)), (w/2)*sin(radians(angle)));
println(vertices[i].x + " " + vertices[i].y);
}
}
Note that I've added a println to highlight a slight problem - you might want to use the value of i to adjust those vertex coordinates. I'd also be tempted to add parameters to the create method so you can choose where to place your rendered polygon...