SA-MP Forums Split Square Into Smaller Squares
 New Account Members List Search Today's Posts Mark Forums Read

 03/02/2018, 12:51 AM #1 Redirect Left High-roller     Join Date: Mar 2007 Location: Yorkshire, England Posts: 1,024 Reputation: 371 Split Square Into Smaller Squares 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 __________________ Redirect Left, y'know? The one who started the Sumo Server craze? that's me, click here to play it! I also run Mini-Missions, again, only 9 years after my last run at it! Life is ace, aint it?!
 03/02/2018, 12:59 AM #2 NaS High-roller     Join Date: Mar 2008 Location: 🇩🇪 Posts: 1,651 Reputation: 558 Re: Split Square Into Smaller Squares 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). Code: ```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... } }```
03/02/2018, 01:17 AM   #3
Marricio
Gangsta

Join Date: Dec 2010
Posts: 719
Reputation: 96
Re: Split Square Into Smaller Squares

Quote:
 Originally Posted by NaS Code: ```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.

03/02/2018, 01:19 AM   #4
NaS
High-roller

Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,651
Reputation: 558
Re: Split Square Into Smaller Squares

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).

03/02/2018, 01:20 AM   #5
Marricio
Gangsta

Join Date: Dec 2010
Posts: 719
Reputation: 96
Re: Split Square Into Smaller Squares

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.

03/02/2018, 01:28 AM   #6
NaS
High-roller

Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,651
Reputation: 558
Re: Split Square Into Smaller Squares

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.

 03/02/2018, 05:58 PM #7 Redirect Left High-roller     Join Date: Mar 2007 Location: Yorkshire, England Posts: 1,024 Reputation: 371 Re: Split Square Into Smaller Squares 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. __________________ Redirect Left, y'know? The one who started the Sumo Server craze? that's me, click here to play it! I also run Mini-Missions, again, only 9 years after my last run at it! Life is ace, aint it?!
03/02/2018, 06:26 PM   #8
NaS
High-roller

Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,651
Reputation: 558
Re: Split Square Into Smaller Squares

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.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post [Off] Game about Squares Nekos Português/Portuguese 10 09/08/2014 07:05 AM Lorenzo* Maps 5 10/02/2013 02:33 PM Miguel Help Archive 5 24/05/2010 12:37 AM linoxtrala Help Archive 2 15/12/2009 03:48 PM

All times are GMT. The time now is 04:37 PM.

 -- (EN) English -- (RU) Русски SA-MP - Archive - Top