Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pick a line closest to the center on a grid?
    primarykey
    data
    text
    <p>I am drawing a simple grid, and I want the line closest to the center of the screen to be highlighted a different color.</p> <p><strong>What is the formula to determine what line was drawn that closely resembles the center of the screen?</strong></p> <p>It doesn't have to be the exact center, just one that appears to be in the middle of the screen. But it must be a line that was drawn. The user can change the size of the grid at anytime, so this line must move with it. </p> <p>I am drawing a new line on the screen using a different stroke color, but I can't determine which line to overlap. I can get close but I am always off by a few pixels.</p> <p>Take a look at this picture in Photoshop. The green line represents the true center of the image. While the pink line is the desired result (center line) because the grid isn't even to the screen size (look at the last grid on the right) The grid is 34x34 and the screen size is 320 x 480. </p> <p><img src="https://i.stack.imgur.com/71VHK.png" alt="example"></p> <p><strong>How to draw the grid:</strong></p> <pre><code>int xStart = 0, yStart = 0; int gsX = 19; //Distance between lines int gsY = 25; // draw vertical lines for(int xId=0; xId&lt;=(screenWidth/gsX); xId++) { int x = xStart + xId * gsX; [gPath moveToPoint:CGPointMake(x, yStart)]; [gPath addLineToPoint:CGPointMake(x, yStart+screenHeight)]; } // draw horizontal lines for(int yId=0; yId&lt;=(screenHeight/gsY); yId++) { int y = yStart + yId * gsY; [gPath moveToPoint:CGPointMake(xStart, y)]; [gPath addLineToPoint:CGPointMake(xStart+screenWidth, y)]; } </code></pre> <p><strong>My centerline code:</strong> This moves the line based upon the grid spacing value, but it isn't drawn over one of the lines near the center.</p> <pre><code>int x = (screenWidth/gsX) /2; NSLog(@"New X: %i gsX: %i",x, gsX); //Veritical [centerLines moveToPoint:CGPointMake(x, 0)]; [centerLines addLineToPoint:CGPointMake(x, screenHeight)]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload