Advertisement
Guest User

TheEnd.cs Unity - odd e mirrored

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