Calculating # or Rows and Columns

前端 未结 6 878
北海茫月
北海茫月 2021-01-04 13:27

I have a # of images that I\'m stitching together into a sprite sheet, how can I calculate the number of rows and columns to fit equally in an even rectangle (no blank space

6条回答
  •  甜味超标
    2021-01-04 13:39

    Here's a very fast and easy algorithm (where N is the number of images)

    rows = floor(sqrt(N))
    while(N % rows != 0)
         rows = rows - 1
    

    And rows will be the number of rows needed. Columns can obviously be found with N / rows.

    I hope this helps!

提交回复
热议问题