Created
September 28, 2013 04:07
-
-
Save GigsD4X/6738271 to your computer and use it in GitHub Desktop.
Returns a table with a given number of frames positioned on a scale from 0 to 1 along a given dimension in a way where they all fit with equal spacing in between them, aligned to a given end of the dimension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getInterequidistantlyScaledFrames( count, padding, dimension, alignment ) | |
-- Returns a table containing `count` Frame objects with `padding` | |
-- percent of the frame size (on a scale from 0 to 1) of spacing in | |
-- between each frame in the "x" or "y" `dimension`, aligned to the | |
-- "left", "center", or "right" (or, along the y-axis, "top", | |
-- "center", or "bottom") | |
local frames = {}; | |
-- Calculate the size of each frame considering the padding in | |
-- between each one (so that all the frames fit) | |
local frame_size = 1 / ( count + ( padding * count ) ); | |
for frame_number = 1, count do | |
-- Calculate the position of each frame | |
local frame_position = 1 / count * ( frame_number - 1 ); | |
local last_frame_position = 1 / count * ( frame_number - 2 ); | |
if alignment == "center" then | |
frame_position = frame_position + ( ( frame_position - ( last_frame_position + frame_size ) ) / 2 ); | |
elseif alignment == "right" or alignment == "bottom" then | |
frame_position = frame_position + ( frame_position - ( last_frame_position + frame_size ) ); | |
end; | |
-- Create frame `frame_number` | |
local Frame = Instance.new( "Frame" ); | |
Frame.Size = UDim2.new( dimension == "x" and frame_size or 0, 0, dimension == "y" and frame_size or 0, 0 ); | |
Frame.Position = UDim2.new( dimension == "x" and frame_position or 0, 0, dimension == "y" and frame_position or 0 ); | |
-- Place frame `frame_number` in its appropriate position in the table | |
frames[frame_number] = Frame; | |
end; | |
-- Return the table of frames | |
return frames; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few examples of the kind of stuff that this is useful for: