I need help with a table of dots

i want to make a chart of dots with PGraphics but the last colum and row always disapear.

i want it to be dinamic and varieate the ise of the grid depending on the size of the window
but it always seem to eat the last colum and row

any change i can do jut to make it apear? it doesnt have to be exactly the distance in that las one, just make it apear

PGraphics pg;
float origin=0;//just if i want to change the start of the grid
float dotx=origin;
float doty=origin;

//where i gues is the roblem
int col=int (width/100);    //=6 colums 7 dots 
int row=int (height/100); //=6 rows     7 dots
float dx= width/col;     //distance between point in x axis
float dy= height/row;  //distance between point in y axis



void setup() {
  size(600, 600);
  pg = createGraphics(600, 600);
  pg.beginDraw();
  pg.background(100);
  pg.stroke(255);
  pg.endDraw();
  noLoop();
  
}

void draw() {
  
  pg.beginDraw();
  pg.strokeWeight(4);
  
  
  //table creation
  for (doty=origin;doty<height;doty+=dy){
    for(dotx=origin;dotx<width;dotx+=dx){
      pg.point(dotx,doty);
    }
  }
}

PD: i guess its because the point ends outside of the window and doesnt bother to draw it

1 Like

pls format your above code posting
using the

</> code formatter

i skip your

PGraphics pg;

way, but no problem with that.

pls find the optional AUTO adjustment to any area ( or canvas size )

// smart grid of points ( or rectangles), fit to area / canvas
int x = 20, y = x, w = x, h = w, offset = 0;
int grid = 7, many = grid*grid;
boolean auto = true;

void setup() {
  size(500, 300);                                       // 
  stroke(0, 0, 200);
  fill(0, 200, 0);
  auto_scale(auto, width, height);                      // true / false / canvas or any aerea to fit in
}

void auto_scale(boolean scale, int wide, int high) {    // autoscale w h
  if ( scale ) {
//    w = (wide  - 2*x)/grid - offset;
//    h = (high  - 2*y)/grid - offset;
    w = (wide  - 2*x)/(grid-1) - offset;   // only for the DOT version
    h = (high  - 2*y)/(grid-1) - offset;
  }
  println("x "+x+" y "+y+" w "+w+" h "+h+" offset "+offset+" grid "+grid+" many "+many);
}

void draw() {
  background(200, 200, 0);
  for (int i = 0; i < many; i++)  // rect(x+(i%grid)*(w+offset), y+(floor(i/grid))*(h+offset), w, h);   // or any other shape/text on that position
//      circle(x+(i%grid)*(w+offset), y+(floor(i/grid))*(h+offset),5);
      point(x+(i%grid)*(w+offset), y+(floor(i/grid))*(h+offset));
}

SNAG-0063

1 Like