Hi I have tried to make a hexagon by using vectors however when I try to put the shape into a class (so I later can make a grid where I can detect in which one my mouse is in) but the problem is I can’t display my shape. Down below is my code and if you can find the mistake… please tell me where it is. It would be of great help. THANK YOU
form hexagon;
void setup(){
hexagon=new form();
size(800,800);
}
void draw(){
background(255);
line(width/2,0,width/2,height);
line(0,height/2,width,height/2);
hexagon.display();
}
class form{
PVector center;
PVector b;
float angle;
float a;
int npoints;
int r=15;
form(){
npoints=6;
angle=TWO_PI/npoints;
//PVector center=new PVector(width/2,height/2);
}
void display(){
PVector center=new PVector(width/2,height/2);
line(0,0,center.x,center.y);
beginShape();
for (a=0; a<TWO_PI; a+=angle){
b=center.add(center.x+ cos(a)*r,center.y+ sin(a)*r);
vertex(b.x,b.y);
}
endShape(CLOSE);
}
}