We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Question about grid algorithm
Page Index Toggle Pages: 1
Question about grid algorithm (Read 407 times)
Question about grid algorithm
Feb 4th, 2010, 4:50pm
 
I'm trying to write an algorithm that will create a grid based on a certain number of cells. There will be a variable for the number of cells in the grid, and the algorithm will determine the size of each cell and the appropriate number of columns and rows for a perfect fit based on the dimensions of the application. Any suggestions on the best way to implement this?
Re: Question about grid algorithm
Reply #1 - Feb 4th, 2010, 5:09pm
 
so you're given appet width, height and total number of grid cells?  can't be solved analytically yet.

you need to specify at least one other value, call it 'aspect', then you can solve it.  (of either the # of cols/rows in the grid, or of the resulting width/height of the cells themselves)

for example, say you need 100 cells in a 2000x500 image.  if you specify "square aspect rows/cols", then the number of rows/cols is sqrt(100)=10, and their width/height is 2000w/10c=200px x 500h/10r=50px height.

if you instead specify "square aspect width/height", then the area of each cell must be (2000x500)/100=10000, so their w/h must be sqrt(10000)=100, so # of cols/rows is 2000/100=20cols and 500/100=5rows.

(of course i picked "pretty" values that work out nicely, you'll have to deal with rounding issues, and you need not use 'square' asepct)

but you can see that 10x10@200x50 and 20x5@100x100 could BOTH be valid answers, so you need to provide more info to resolve which is the "right" solution.
Page Index Toggle Pages: 1