Hello,
I am trying to figure out a formula which would give me number of (equal sized) rows and columns to be drawn on a grid based on a variable.
Python :
row,column = makeGrid(variable)
eg :
if variable = 1 i.e. only one element is to be place in complete grid so number of column and row will be 1.
if variable = 2 then we need either 2 row,1 column or 2column,1 row so that two elements can be place in two
if variable =3 : 2 rows,2columns
if variable=4 : 2 rows,2columns
Thanks !
chakmangoo
capper
2
What if the number is bigger than 4? Does it add columns or rows? Or is 4 the cutoff?
def get_grid( num ):
divisor = int( math.sqrt( num ) )
v = divisor
h = divisor
if h * v < num:
h += 1
if h * v < num:
v += 1
return h, v
Hello Crapper,
It should go beyond the limit of 4 ,Above images are just for example.-Thanks
Hello Theodox,
Awesome ! It works. - Thanks
Just curious to explore more, where to explore for grid math (or what keywords on google) ?
capper
5
Close, and as much as I’d like to be able to claim my ancestors invented the toilet, unfortunately I cannot.