SA-MP Forums Archive
Split Square Into Smaller Squares - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Split Square Into Smaller Squares (/showthread.php?tid=649104)



Split Square Into Smaller Squares - Redirect Left - 02.02.2018

Hi

I'm looking for some code to basically split a square into lots of equal sized squares, rectangles would also work.
I need this so I can quickly and rapidly make a set of gangzones.

If I can figure out how to make a function, input the max x & y, and minimum x & y, and it out puts a bunch of co-ords for the max x & y and min x & y of smaller squares, for the gangzones.

Anyone any idea how I would achieve this sort of math in Pawn?

- Cheers


Re: Split Square Into Smaller Squares - NaS - 02.02.2018

You basically just have to split the rectangle/square into X parts, take that length and multiply it by X + the base coords to get the Xth square coordinates.

eg.

To split a 100.0, 100.0 sqaure into 10 squares you need to divide the coords by 10, which results in 10.0, 10.0.
To get the 5th square on the X axis you would do 5x 10.0 to get the minX value, add 10.0 to get maxX for that square.

That would result in the coords 50.0, 0.0, 60.0, 10.0 (minX, maxX, minY, maxY).

Код:
splitsquares(Float:sizeX = 100.0, Float:sizeY = 100.0, num = 5)
{
new Float:offsetX = sizeX / num, Float:offsetY = sizeY / num;

for(new x = 0; x < num; x ++) for(new y = 0; y < num; y ++)
{
new Float:minX = x * offsetX, Float:maxX = minX + sizeX;
new Float:minY = y * offsetY, Float:maxY = minY + sizeY;

// Do stuff with minX, maxX, minY, maxY...
}
}



Re: Split Square Into Smaller Squares - Marricio - 03.02.2018

Quote:
Originally Posted by NaS
Посмотреть сообщение
Код:
splitsquares(Float:sizeX = 100.0, Float:sizeY = 100.0, num = 5)
{
new Float:offsetX = sizeX / num, Float:offsetY = sizeY / num;

for(new x = 0; x < num; x ++) for(new y = 0; y < num; y ++)
{
new Float:minX = x * offsetX, Float:maxX = minX + sizeX;
new Float:minY = y * offsetY, Float:maxY = minY + sizeY;

// Do stuff with minX, maxX, minY, maxY...
}
}
Correct me if wrong, but isn't that code going to generate 25 squares?

EDIT: I mean, I don't think that would work with a strict amount of squares.


Re: Split Square Into Smaller Squares - NaS - 03.02.2018

Quote:
Originally Posted by Marricio
Посмотреть сообщение
Correct me if wrong, but isn't that code going to generate 25 squares?
Yes, because 5x5 is 25 (which is correct for 5x5 zones).


Re: Split Square Into Smaller Squares - Marricio - 03.02.2018

Quote:
Originally Posted by NaS
Посмотреть сообщение
Yes, because 5x5 is 25.
Welp, I'm assuming the "n" argument in your function is actually the square amount.


Re: Split Square Into Smaller Squares - NaS - 03.02.2018

Quote:
Originally Posted by Marricio
Посмотреть сообщение
Welp, I'm assuming the "n" argument in your function is actually the square amount.
Oh yea it's the amount of squares on the axes, if it should be for different amount of rectangles per axis it just requires a second num variable, one for X and one for Y.


Re: Split Square Into Smaller Squares - Redirect Left - 03.02.2018

Would be nice if I could also specify the amount of squares to create - which would in turn also control how big each square is. IE 100 squares will be a lot smaller than 50 squares.

I'm all a little confused, algebra is not fortй at all
Really grateful for your replies so far.


Re: Split Square Into Smaller Squares - NaS - 03.02.2018

Quote:
Originally Posted by Redirect Left
Посмотреть сообщение
Would be nice if I could also specify the amount of squares to create - which would in turn also control how big each square is. IE 100 squares will be a lot smaller than 50 squares.

I'm all a little confused, algebra is not fortй at all
Really grateful for your replies so far.
If you want 5 from an equation 5*5, you must get the square root. So, to get the number 5 like in my example, you have to calculate the square root of 25.

If you want 64 squares, it's 8 since 8*8 = 64, etc.