#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Very basic question about pixels

edited December 2017

How do you find the center pixel?

Say I have the width set at an even number of pixels, 8.

Pixels going across pizel 0, pixel 1... to pixel 7.

I would think initially that to get to the centre, you'd say (8-1)/2 but this would be 3.5, and there's no pixel 3.5, so how would processing resolve this? Round up to pixel 4? And settle for an off-centre pixel?

Or should I say 8/4, instead of minusing 1 for the zero that gets counted?

Tagged:

• edited December 2017 Answer ✓
• There's no exact center for an even quantity, only for odd. ^#(^
• Let's say width is 800, so you've got a 0-799 range.
• Centered pixel coordinate would be 800/2 = 400. But 399 would be valid too.
• That is, both 399th & 400th would both be the centered pixels for an even width.
• Now w/ width = 801, which is a 0-800 range, the 400th pixel coordinate is the exact center.
• Left range is 0-399, right range is 401-800, and center is 400th. :-B
• Thanks so much for responding to what I was starting to think was just me being ocd pedantic.

So it's like the two center pixels become a double sized Center Pixel? If you coloured it with stroke(0), and then zoomed it to see the individual pixels with grid lines, there would be two coloured pixels?

• edited December 2017 Answer ✓

So it's like the two center pixels become a double sized Center Pixel?

• Not like that. It just means that for an even quantity of pixels, they're evenly split in half.
• For example, let's say you've got resolution 800x600: `size(800, 600);`
• So you've got width = 800 (0-799 range) & height = 600 (0-599 range).
• For width, its left side got 400 pixels (0-399). Right side got 400 pixels too (400-799).
• For height, its top side got 300 pixels (0-299). Bottom side got 300 pixels too (300-599).
• Therefore both the 399th & 400th pixels are in the middle width of the canvas.
• Same for height: both the 299th & 300th pixels. :-B
• Follow up question in the same vein:

Working with that pixel coordinate x=400 as the centre pixel coordinate in an even split, pixel399 on the left and pixel400 on the right, how does it work if I want to use this point as centre if I do something like rectMode (CENTER) with a width of 3 pixels. Which side gets the extra pixel?

• Dunno the algorithm they use for rect() rendering when rectMode() is set to CENTER. :-??

• Thanks. I thought I was missing something. Going through Learning Processing, but I wanted to figure this out before I moved on because I thought it might be important #:-S