Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x * size <= width //x - number of columns
- y * size <= height //y - number of rows
- x * y <= N //N - number of squares
- size -> max //size - size of squares
- 1 1 1 1
- 1 1 1 1
- 1 1 0 0
- // to make things more simple I put width as bigger size
- int biggerSize = this.ClientSize.Width;
- int lowerSize = this.ClientSize.Height;
- int maxSize = int.MinValue;
- int index = 0;
- int index2 = 0;
- // find max suitable size
- for (int i = _rects.Count; i > 0; i--) {
- int size = biggerSize / i;
- int j = (int)Math.Floor((double)lowerSize / size);
- if (i * j >= _boards.Count && size > maxSize) {
- maxSize = size;
- index = (int)i;
- index2 = (int)j;
- }
- }
- int counter = 0;
- // place all rectangles
- for (int i = 0; i < index; i++) {
- for (int j = 0; j < index2; j++) {
- if (counter < _rects.Count) {
- _rects[counter].Size = new Size(maxSize, maxSize);
- _rects[counter].Location = new Point(i * maxSize, j * maxSize);
- }
- counter++;
- }
- }
Add Comment
Please, Sign In to add comment