Jump to content

Rectangle tiles resize algorithm


JeffreyR

Recommended Posts

Hello everyone,


I am making a webpage and. In photoshop i made a website layout. This is just a big rectangle image. Then i sliced it into a lot of smaller rectangles.

This is the website layout: 2z7fwk6.jpg


So I have s lot of images that are rectangles or squares and together they form a complete rectangle image.

As you can see in the image below:

4v2usg.jpg


I need an algorithm.

The idea is that i can adjust the big rectangle width to any value i want and the small tiles rearange themselves.

I have searched google, but i don't know where to start.

I don't know what this type of algorithm is called in mathematical terms of if it even exists.

Does anyone know something about this kind of algoritm?


Thank you very much in advance,

Jeffrey
Link to comment
Share on other sites

Well if you know the width, height, and starting coordinate of each rectangle then you can find the resized values as follows:

 

Say these are your variables

--------------------------------

totalWidth = (width of entire rectangle)

totalHeight = (height of entire rectangle)

totalWidthNew = (width to resize entire rectangle to)

totalHeightNew = (height to resize entire rectangle to)

width = (initial width of the Nth small rectangle)

height = (initial height of the Nth small rectangle)

x = (initial x coordinate of Nth small rectangle)

y = (initial y coordinate of Nth small rectangle)

 

Then you just recalculate width, height, x, and y by doing:

newWidth = (width / totalWidth) * totalWidthNew

newHeight = (height / totalHeight) * totalHeightNew

newX = (x / totalWidth) * totalWidthNew

newY = (y / totalHeight) * totalHeightNew

 

Just reassign width, height, x, and y for each of the current values of each small rectangle, and recalculate their newWidth, newHeight, newX, and newY values like above.

 

Please ask if anything is unclear.

 

NOTE: I just came up with all of this off the top of my head so I haven't tested it, but I am pretty confident it will work like you want.

Edited by Staysys
Link to comment
Share on other sites

  • 2 weeks later...

Its a ratio...

 

Event(){

for every rect {

ratio = old rect / new rect

new rect = old rect * ratio

repaint()

}

}

 

 

Actuality is more complex but in essence the new rect sizes are ratio's of the old

 

If you store each rect in an array or such you can increment through each in a loop, the ratio should be the same.

 

side note in this form the rects will overlap if you make them bigger, you'd need co-ords for each rect also....

Edited by DevilSolution
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.