Advertisement
Guest User

Unity C# TheEnd

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