Advertisement
defango

OLD

Apr 10th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TheEnd : MonoBehaviour {
  6.  
  7. public Dictionary<int, Dictionary<int, List<string>>> theend = new Dictionary<int, Dictionary<int, List<string>>>();
  8. static void Main(string[] args)
  9. {
  10.  
  11. TheEnd.CreateTheEnd();
  12.  
  13. TheEnd.Output();
  14.  
  15. }
  16.  
  17. // Use this for initialization
  18. void Start () {
  19. int i_max = 128;
  20. int x_min = -128;
  21. int x_max = 128;
  22. int y_min = 0;
  23. int y_max = 128;
  24. int set_size = 12;
  25.  
  26. CreateTheEnd(i_max, x_min, y_min, x_max, y_max);
  27. Output(i_max, x_min, y_min, x_max, y_max, set_size);
  28. }
  29.  
  30. // Update is called once per frame
  31. void Update () {
  32.  
  33. }
  34.  
  35. void CreateTheEnd(int i_max = 64, int x_min = -64, int y_min = 0, int x_max = 64, int y_max = 64)
  36. {
  37. theend.Clear();
  38.  
  39. for (int i = 0; i < i_max; i++)
  40. {
  41. for (int j = 0; j < i; j++)
  42. {
  43. int a = i - j;
  44. int b = i + j;
  45. int c = a * b;
  46. bool odd = c % 2 == 1;
  47. int d = (int)Math.Sqrt(c);
  48. int e = c - (d * d);
  49. int f = e - ((2 * d) + 1);
  50. int n = i - d;
  51. int x = d - a;
  52.  
  53. if (!theend.ContainsKey(e)) theend[e] = new Dictionary<int, List<string>>();
  54.  
  55. if (!theend[e].ContainsKey(n))
  56. {
  57. theend[e][n] = new List<string>();
  58. }
  59.  
  60. if (!theend.ContainsKey(f)) theend[f] = new Dictionary<int, List<string>>();
  61.  
  62. if (!theend[f].ContainsKey(n - 1)) theend[f][n - 1] = new List<string>();
  63.  
  64. string text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", e, n, d, x, a, b) + "}";
  65.  
  66. theend[e][n].Add(text);
  67.  
  68. text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", f, n - 1, d + 1, x + 1, a, b) + "}";
  69.  
  70. theend[f][n - 1].Add(text);
  71. }
  72. }
  73. }
  74.  
  75. void Output(int i_max = 64, int x_min = -64, int y_min = 0, int x_max = 64, int y_max = 64, int set_size = 12)
  76. {
  77. for (int y = 0; y < y_max; y++)
  78. {
  79. for (int z = 0; z < set_size; z++)
  80. {
  81. for (int x = x_min; x < x_max; x++)
  82. {
  83. if (theend.ContainsKey(x) && theend[x].ContainsKey(y) && theend[x][y].Count > z)
  84. {
  85. String[] values = theend[x][y][z].Split(':');
  86.  
  87. int e = Int32.Parse(values[0].Split('{')[1]);
  88. int n = Int32.Parse(values[1]);
  89. int d = Int32.Parse(values[2]);
  90. int xx = Int32.Parse(values[3]);
  91. int a = Int32.Parse(values[4]);
  92. int b = Int32.Parse(values[5].Split('}')[0]);
  93. int c = a * b;
  94.  
  95. float red = (float)xx / (i_max / 2);
  96. float green = (float)a / i_max;
  97. float blue = (float)b / (i_max * 2);
  98.  
  99. GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
  100. cube.transform.position = new Vector3(e, n, d);
  101. cube.GetComponent<Renderer>().material.color = new Color(red, green, blue);
  102. cube.GetComponent<MeshRenderer>().receiveShadows = false;
  103. cube.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
  104.  
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement