123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|95|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Concept/Design -> Box Dispensing

Posted : Sunday, 15 May 2022, 00:04
therevillsgames
Algorithm Help Please I want to place items outside and around a rectangle, say if the rectangle is 10 x 5 and I have 100 items, so I place 10 across the top line, 5 across the right line, 10 across bottom and then 5 across the left... then for the rest increase the ’’size’’ of the rectangle so I can add all of the items... any ideas?
Posted : Sunday, 15 May 2022, 00:04
therevillsgames
Image to help
Posted : Sunday, 15 May 2022, 01:20
Dan
What you should have is the width/height of the boxes and the spacing in between.

When you have it, it is easy to calculate how many boxes fit in the top part.

You can do that with one side.

Then you calculate the (count of the top part*2 + the count of the sides*2)+4
(4 because of the 4 boxes at the corners)

If that number does not fit the amount of boxes. you can increase the rectangle.

In the case of the picture, the start of rectangle would be the top left white box, and the end would be the bottom right box.

Then do the calculation again.
Posted : Sunday, 15 May 2022, 01:25
Dan
To calculate the top count, you simply use, say 5 (box width) + 2 (spacing) = 7 pixel

If the rectangle is 200 pixel in width, then calculate

200/7, and you get how many squares can fit there (rounded down)


at least, this is how i would begin with.
Posted : Sunday, 15 May 2022, 01:49
therevillsgames
Sounds easy But I'm having a hard time thinking how to do it in code with dynamic values...
Posted : Sunday, 15 May 2022, 01:58
Dan
Just start with what i gave you. see the result, then you may discover how to apply dynamic values.

Because as soon as you start thinking in that way, a solution may come up.
Posted : Sunday, 15 May 2022, 02:07
Dan
The trouble, at leas for me is, that i do not know what you want to do.

see these question to understand the problem:
What happens if you have 1 box instead of 100 ?
What should be, if you have 2 boxes ? 3 ? 4?

if you have 4 boxes, shall they be on the top side ? or shall they be placed one at each side ?

If you have enough boxes to fill the top side and to place 2 boxes at the right hand side, shall the rectangle be made smaller, so that the amout of boxes are always arround the rectangle ?

...

So basically start with baby steps, then expand as needed.
Posted : Sunday, 15 May 2022, 02:27
Dan
If you have to place the boxes around the fixed size (i mean not going smaller) rectangle, then calculate if they fit.

If they do not, increase the size and do the calculation again until they fit.

arbitrary code is:


Posted : Sunday, 15 May 2022, 02:50
Pakz
I do not completely understand it. But could you take the length of all the lines of the box. And the width/height and spacing of all the tiny boxes? Then try to get this to fit?
Posted : Sunday, 15 May 2022, 03:05
therevillsgames
If the number of the tiny boxes were fixed, I could just do: no_of_boxes / 4 = x.... then x / width of rect and x / height of rect and place them okay

Basically I want to place the tiny boxes starting top left and going around the rectangle separated by the width of the tiny boxes, if there are too many then we go around again but further out.

I'll have a mess around on JSE.
Posted : Sunday, 15 May 2022, 03:24
therevillsgames
Not quite right but something like this:


Posted : Sunday, 15 May 2022, 03:24
Pakz
The first thought I had that I would code a slider. This to modify the spacing on the second pass.

I hope you figure it out!
Posted : Sunday, 15 May 2022, 04:48
Jayenkai
  --v

Couldn't work out a formula. Made a loop!

-=-=-
''Load, Next List!''
Posted : Sunday, 15 May 2022, 05:32
Dan
aaah i thought you want 1 row/column of the boxes around the square.
Posted : Monday, 16 May 2022, 03:07
therevillsgames
Thanks all and Jay - that's one way to do it

and here is the BlitzMax (Strict as the non-strict version didnt work at all ) version of Jay's code:


Posted : Friday, 20 May 2022, 23:11
therevillsgames
This is what I ended up with:




Posted : Friday, 20 May 2022, 23:59
Dan

Posted : Saturday, 21 May 2022, 01:13
rockford
Noice!!!
Posted : Saturday, 21 May 2022, 02:20
Jayenkai
\O/yeay\o/
Posted : Saturday, 21 May 2022, 03:02
therevillsgames
Thanks for the help guys!

Now I need an option name for it... "Clean Random Placement"...

or the opposite "Random Messy Placement"? both suck


Posted : Saturday, 21 May 2022, 03:33
Jayenkai
Scattered Border?
Posted : Saturday, 21 May 2022, 04:28
Dan
Or RandomizedBorder