Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1.         private void SetIconPosition(IEnumerable<DesctopIcon> icons, Action<DesctopIcon, float, float> positionSetter, float l)
  2.         {
  3.             //int maxIconsInLayer = (int)(MathHelper.TwoPi * l / Math.Pow(200000,0.5));
  4.             //int n = (int)Math.Round((MathHelper.TwoPi * Math.Sqrt(files.Length + folders.Length) / Math.Sqrt(MathHelper.Pi)));
  5.             int n = files.Length + folders.Length; //общее кол-во иконок
  6.             int Layers = (int)(1 + Math.Sqrt(12 * n - 5) / 6); //кол-во слоев на пол шара
  7.             float spaceX = MathHelper.PiOver2 / Layers; //шаг угла поворота вокруг оси х
  8.  
  9.             var unsortedIcons = icons;//хуйня
  10.  
  11.             float x = MathHelper.PiOver2; //изначальный угол поворота вокруг х
  12.  
  13.             int iconCount = 1; //иконок в 1м слое
  14.            
  15.             while (unsortedIcons.Any()) //пока есть хотябы 1 иконка в списке иконок
  16.             {                          
  17.                 //int iconCount = (int)(Math.Abs(2 * maxIconsInLayer * Math.Abs(x) / MathHelper.Pi - maxIconsInLayer) + 1);
  18.                 float spaceY = MathHelper.TwoPi / iconCount; //шаг поворота вокруг оси у
  19.                
  20.                 float y = 0; //изначальный поворов вокруг оси у
  21.                 int i = 0; //счетчик
  22.                 while (i < iconCount) //пока в слое остались иконки
  23.                 {
  24.                     var icon = unsortedIcons.ElementAtOrDefault(i);
  25.                     if (icon == null)
  26.                         break;
  27.  
  28.                     positionSetter(icon, x, y); //установка иконки (полярные координаты (поворот вокруг х, поворот вокруг у, блина радиус-вектора))
  29.                     y += spaceY; //прибавляем к углу поворота его изменение
  30.                     i++; //изменяем счетчик
  31.                 }
  32.  
  33.                 unsortedIcons = unsortedIcons.Skip(iconCount); //убираем из списка расставленные иконки
  34.  
  35.                 if (x > 0) //если в верхней половинке шара
  36.                 {
  37.                     iconCount += 3; //кол-во иконок в след. слое на 3 больше
  38.                 }
  39.                 else
  40.                 {
  41.                     iconCount -= 3;
  42.                 }
  43.                 x -= spaceX; //изменяем угол поворота вокруг х
  44.                
  45.             }
  46.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement