Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // find optimal (largest) tile size
- private function FinOptimalVideoSize(nbvideo:int):void{
- var desiredAspectRatio:Number = 1.33;
- // used to hold the new size of the children after resizing
- var newSize:Object = new Object();
- // holds the original size of the children
- var rectangleSize:Object = new Object();
- rectangleSize.Width = desiredAspectRatio;
- rectangleSize.Height = 1;
- var numColumns:Number = Math.sqrt((nbvideo * rectangleSize.Height * this.width) / (this.height * rectangleSize.Width));
- var lowBoundColumns:Number = Math.floor(numColumns);
- var highBoundColumns:Number = Math.ceil(numColumns);
- var lowNumRows:Number = Math.ceil(nbvideo / lowBoundColumns);
- var highNumRows:Number = Math.ceil(nbvideo / highBoundColumns);
- var VerticalScale:Number = this.height / lowNumRows * rectangleSize.Height;
- var HorizontalScale:Number = this.width / (highBoundColumns * rectangleSize.Width);
- var MaxHorizontalArea:Number = (HorizontalScale * rectangleSize.Width) * ((HorizontalScale * rectangleSize.Width) / desiredAspectRatio);
- var MaxVerticalArea:Number = (VerticalScale * rectangleSize.Height) * ((VerticalScale * rectangleSize.Height) * desiredAspectRatio);
- var rowsMaximized:Boolean;
- // the horizontal area is greater than
- // the max area then we maximize by columns
- if (MaxHorizontalArea >= MaxVerticalArea)
- {
- newSize.Width = this.width / highBoundColumns;
- newSize.Height = newSize.Width / desiredAspectRatio; // A = w/h or h= w/A
- rowsMaximized = false;//used for testing
- if (newSize.Height * Math.ceil(nbvideo /
- highBoundColumns) > this.height)
- {
- //in this case the best solution is usually to maximize by rows instead
- var newHeight:Number = this.height / highNumRows;
- var newWidth:Number = newHeight * desiredAspectRatio;
- rowsMaximized = true;
- if (newWidth * nbvideo < this.width)
- {
- newWidth = this.width / Math.ceil(numColumns++);
- newHeight = newWidth / desiredAspectRatio;
- rowsMaximized = false;
- while (newWidth * nbvideo > this.width)
- {
- newWidth = this.width / Math.ceil(numColumns++);
- newHeight = newWidth / desiredAspectRatio;
- }
- if (newHeight > this.height)
- {
- newHeight = this.height;
- newWidth = newHeight * desiredAspectRatio;
- rowsMaximized = true;
- }
- }
- var currentCols:Number = Math.floor(this.width / newWidth);
- var currentRows:Number = Math.ceil(nbvideo / currentCols);
- if ((newWidth * currentCols) < this.width &&
- (newHeight * Math.ceil(nbvideo /
- currentCols)) < this.height)
- {
- newWidth = this.width / currentCols;
- newHeight = newSize.Width / desiredAspectRatio;
- rowsMaximized = false;
- if (newHeight * Math.ceil(nbvideo /
- currentCols) > this.height)
- {
- newHeight = this.height / currentRows;
- newWidth = newHeight * desiredAspectRatio;
- rowsMaximized = true;
- }
- }
- newSize.Height = newHeight;
- newSize.Width = newWidth;
- }
- }
- else
- {
- newSize.Height = this.height / lowNumRows;
- newSize.Width = newSize.Height * desiredAspectRatio;
- rowsMaximized = true;
- }
- trace("Alrorith 1 thinks Width: " + newSize.Width + " Height: " + newSize.Height)
- tileWidth = newSize.Width;
- tileHeight = newSize.Height;
- }
Add Comment
Please, Sign In to add comment