![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Grid Formatting Demo - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26) +---- Forum: SMcNeill (https://qb64phoenix.com/forum/forumdisplay.php?fid=29) +---- Thread: Grid Formatting Demo (/showthread.php?tid=3482) Pages:
1
2
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Grid Formatting Demo - SMcNeill - 02-21-2025 Based off the topic here: https://qb64phoenix.com/forum/showthread.php?tid=3475 Code: (Select All)
I tried to break this down as simple as possible, so that one can use this to generate a series of grids in a set ratio and choose which layout would work best for their number of items. I *think* this basically follows the same spirit of what @madscijr was trying to do with his code. One difference here though -- I removed the inverse values as they're always going to be the same result, just turned sideways! a 4 x 6 grid holds 24 items. a 6 x 4 grid holds the same 24 items. Seems like a waste to list them both. If one really wants that, then just swap your X and Y numbers. It won't change how many items the grid would hold. 4 x 6 is the same as 6 x 4. ![]() Try it out. See if this does what you were trying to do, and see if it's a little bit simpler and easier to understand. ![]() RE: Grid Formatting Demo - Pete - 02-21-2025 Input 400 and you will see a % sign in front of the 1096 'empty' cell. %1096 Pete RE: Grid Formatting Demo - SMcNeill - 02-21-2025 That's cause I just didn't leave enough digits for such big values. Change that format$ to add a few ## symbols. RE: Grid Formatting Demo - madscijr - 02-21-2025 (Yesterday, 06:54 PM)SMcNeill Wrote: That's cause I just didn't leave enough digits for such big values. Change that format$ to add a few ## symbols.Impressive how you boiled it down to be so simple. However I'm not sure one of them is working... Entering 555 for the # of items, here's a side-by-side comparison for the 2 programs...
Also I'm not really sure what the scale is for. Did I mention I'm terrible at math? ![]() Thoughts? RE: Grid Formatting Demo - Pete - 02-21-2025 Ah yes, pre-stoneage PRINT USING. ![]() I'm so used to displaying everything in a string routine, I totally forgot how PU acts. Anyway, added a couple more # marks and works perfectly. +1 Pete RE: Grid Formatting Demo - SMcNeill - 02-21-2025 (Yesterday, 07:09 PM)madscijr Wrote:(Yesterday, 06:54 PM)SMcNeill Wrote: That's cause I just didn't leave enough digits for such big values. Change that format$ to add a few ## symbols.Impressive how you boiled it down to be so simple. 33:17 isn't the same ratio as 16:9, so yours is failing to match the grid somewhere. 16:9 is a 1.77777 ratio. 33:17 is a 1.9411 ratio. Those aren't the same at all. As for the letter size, that's because I swapped it to an integer ratio and not anything fractional. (17 x 22 instead of 8.5 x 11) I figure it's hard to break your items into half-grids like that, so I wanted to go with an integer ratio. And again, the ratio for yours isn't holding true to that 17x22 ratio. In fact, I'm not even certain how yours can call that a solution. 20 rows, 20 columns = 400 items for your grid. How are you going to put your 555 items into the grid, and still have 5 empty spaces left over? Something is wrong with the math on yours, somewhere along the way. ![]() RE: Grid Formatting Demo - SMcNeill - 02-21-2025 As for the scaler, it's by how much we increase our grid. For a 1:1 ratio, you have: 1x1 == one square box (original scale) 2x2 == four square box (scale x 2) 3x3 == nine square boxes (scale x 3) 1:1 says that you want the results to go in a square. If each item is the same size, the scaler tells you how big a square you need to put those items in. Same way with a 2x3 grid 2x3 = 6 item grid (original scale) 4x6 = 24 item grid (scale x 2) 6x9 = 54 item grid (scale x 2) Anything besides these values are going to skew your ratio, so they wouldn't be valid numbers and be able to maintain the ratio you set at the same time. It's like with your letterbox results above. 20 rows and 20 columns are going to create a square -- not a sheet of paper. The values don't match the ratio you've established for yourself. RE: Grid Formatting Demo - madscijr - 02-21-2025 (Yesterday, 07:29 PM)SMcNeill Wrote: 33:17 isn't the same ratio as 16:9, so yours is failing to match the grid somewhere. If I enter 20 for the number of items, I get
Maybe I'm misunderstanding the numbers, I'll double check, but for 20 items, you shouldn't have so many rows/columns, or the large empty counts: * 4:3 = 8x6, 28 empty * 4:5 = 8x10, 60 empty * 16:9 = 16x9, 124 empty * 11:14 = 11x14, 134 empty * 17:22 = 17x22, 354 empty RE: Grid Formatting Demo - SMcNeill - 02-21-2025 Again, you're not maintaining your set ratios. Yes, a 7x3 grid is going to hold 21 items, but it's not going to be able to match your 16:9 ratio. 7x3 is going to scale to a 21:9 ratio, which doesn't match what you started with originally at all. If that ratio is something that doesn't have to be maintained, then why's it even there to start with? What's the point for it? 1x1 is square. 1x2 is... not square. 2x1 is... not square. If I have 2 items, I can put them in a 1x2 grid, or a 2x1 grid, but those grids aren't going to be SQUARE -- which was the whole initial requirement for things. It's only at: 1x1 that we have a square. 2x2 that we have a square. 3x3 that we have a square. 4x4 that we have a square. Your description sets the ratio that you want to find a solution for, but then the solutions you are finding doesn't match that ratio. Let's say you want to sort out how large a SQUARE grid you need to hold 12 items. 3x3 IS square, but it can only hold 9 items. 4x3 isn't square, but it can hold 12 items. 4x4 IS square, but it holds 16 items. You have 4 empty spaces left over on your grid. Is the 4x3 a better answer? Sure, it might be -- but it's NOT a SQUARE grid like the ratio demanded it to be. If you don't need to maintain the ratio, all you need to do is simple math and look for values that multiply to the closest number for you. The best answer would always just be a simple 1xnumber grid. It'd never have any spaces left over. RE: Grid Formatting Demo - Pete - 02-21-2025 4:3 = 8x6 so 48 cells available, only 20 used would be 28 empty. The math is certainly correct, so the question would be will it work in practice. Maybe the problem is you are wanting more of a collage effect for uneven distribution like fitting jigsaw pieces together. This cell approach, using mixed photo sizes, is a grid, meaning smaller photos get placed in the center of the grid sized to the largest photo. Pete |