# Best way to draw a grid mesh like chess field

Hey there,

I am bit stuck about how I draw a simple grid like a chess field best way.
My approach so far is the following, but somehow the indices are wrongly connected.

``````int height = 500;
int width = 500;
int distance = 10;
for (int y = 0; y < height; y = y + distance){
for (int x = 0; x<width; x = x + distance){
mesh.addVertex(ofPoint(x,y,0)); // make a new vertex
}
}

int heightIndex = height / distance-1;
int widthIndex = width / distance-1;

for (int y = 0; y<heightIndex; y++){
for (int x=0; x<widthIndex; x++){

}
}
``````

Is there a better way for that? any ideas what exactly is going wrong. I can not wrap my head around that. solved i tlike this. only a small * was wrong ``````int height = 500;
int width = 500;
int distance = 125;
for (int y = 0; y < height; y = y + distance){
for (int x = 0; x<width; x = x + distance){
mesh.addVertex(ofPoint(x,y,0)); // make a new vertex
}
}
// now it's important to make sure that each vertex is correctly connected with the
// other vertices around it. This is done using indices, which you can set up like so:

int heightIndex = height / distance-1;
int widthIndex = width / distance-1;
int widthIndexPlus = widthIndex+1;
for (int y2 = 0; y2<heightIndex; y2++){
for (int x2=0; x2<widthIndex; x2++){