Problem making the ticks fit on the grid

Regards, I have problems with ticking shoes on the grid. For example using the following code.

public void setup(){
  size(1000, 600, JAVA2D); 

   background(17,34,51);      // Color de fondo principal 
   rect(-1, 95, 1001, 355,1); // Tamaño del rectángulo blanco donde se grafican los datos
   stroke(196,196,196); // Color de la línea del cuadriculado
   fill(258,258,258);//Color del Texto 
   textSize(13); 
 
   for (int i = 0; i < 1000; i=i+7) { // Dibuja el enrejado vertical de la zona de graficación  
  line(7+i, 95,7+i, 449);
  }  
  for (int i = 0; i < 350; i=i+7) { // Dibuja el enrejado horizontal de la zona de graficación  
  line(0, 98+i, 1000, 98+i);
  }
  
  stroke(98); // Color de la línea del cuadriculado
  
     for (int i = 15; i < 999; i=i+34) { // Dibuja el enrejado vertical de la zona de graficación  
     line(20+i, 95,20+i, 450);
    }  
      for (int i = 0; i < 350; i=i+34) { // Dibuja el enrejado horizontal de la zona de graficación  
      line(0, 95+i, 1000, 95+i);
  }
  
  
}

You can create this:

But as it is possible to appreciate, in the end the grid does not fit perfectly, it is important to emphasize that I need that there are 30 large black squares in the dimensions specified in the code.

And I need that within each large black square, there are five grays inside and they don’t fit either.

I really appreciate the help.

1 Like

Hello,

Consider this:

public void setup() 
  {
  size(1000, 600, JAVA2D); 
  background(255);

  for (int i = 0; i < 1000; i=i+7) 
    {  
    if (i%5 == 0) 
      strokeWeight(2);
    else
      strokeWeight(1);
    line(7+i, 95, 7+i, 449);
    }  
  }

Make friends with the modulo operator:
https://processing.org/reference/modulo.html

1 Like

Hello thank you very much.

Hello, your answer can definitely help me achieve what I need, but how could I get 30 frames to the end of the screen? In his example there are 28 frames and if I modify the number at the end, the frames vary a lot “for (int i = 0; i <1000; i = i + 6)”, for example if I put a six, it returns 33 frames and no 30.

You are adding x offsets in loop.

Consider:

  • You want a total of 5*30 divisions; that is the upper limit on loop.
  • Increment loop by 1
  • Space the lines along the x axis by multiplying by i instead of adding in loop.

Think about this while doing it and what happens in each loop.

I used 5*i for the x-axis, try values that best suit your project:

1 Like

I do not understand how he managed to reach 30, however in his example despite the fact that there are 30, they shrunk and did not reach the end of the screen, how could he do to achieve 30 and reach the end of the screen?
It was not clear to me where I should multiply “i”, I try it in different places but I don’t have good results. :frowning:

He is me. :slight_smile:

Last tip of the day:

//Spacing You need to do the math here for correct spacing.  :)
float x = 4.3; 
line(x*i, 0, x*i, height);

Please post your progress on just the vertical lines.

1 Like

Achieved :slight_smile: !!! Thank you very much for the help.

public void setup() 
  {
  size(1000, 600, JAVA2D); 
  background(255);
  float x = 1.1;
    
    
    for (int i = -1; i < 1000; i=i+6) 
    {  
    if (i%5 == 0) 
      strokeWeight(1);
    else
      strokeWeight(0);
    line(x*i, 95, x*i, 449);
    
    }  
    
  }
2 Likes