Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class TheEnd : MonoBehaviour
- {
- public Dictionary<int, Dictionary<int, List<string>>> theend = new Dictionary<int, Dictionary<int, List<string>>>();
- // Use this for initialization
- void Start()
- {
- // Change these values for different resolutions
- // i_max = resolution
- // x, y values define the viewing window (too low = cut off edges)
- int i_max = 128;
- int x_min = -512;
- int x_max = 512;
- int y_min = 0;
- int y_max = 1024;
- int set_size = 12;
- CreateTheEnd(i_max, x_min, y_min, x_max, y_max);
- Output(i_max, x_min, y_min, x_max, y_max, set_size);
- }
- // Update is called once per frame
- void Update()
- {
- }
- void CreateTheEnd(int i_max = 64, int x_min = -64, int y_min = 0, int x_max = 64, int y_max = 64)
- {
- theend.Clear();
- for (int i = 0; i < i_max; i++)
- {
- for (int j = 0; j < i; j++)
- {
- int a = i - j;
- int b = i + j;
- int c = a * b;
- bool odd = c % 2 == 1;
- int d = (int)Math.Sqrt(c);
- int e = c - (d * d);
- int f = e - ((2 * d) + 1);
- int n = i - d;
- int x = d - a;
- if (!theend.ContainsKey(e)) theend[e] = new Dictionary<int, List<string>>();
- if (!theend[e].ContainsKey(n))
- {
- theend[e][n] = new List<string>();
- }
- if (!theend.ContainsKey(f)) theend[f] = new Dictionary<int, List<string>>();
- if (!theend[f].ContainsKey(n - 1)) theend[f][n - 1] = new List<string>();
- string text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", e, n, d, x, a, b) + "}";
- theend[e][n].Add(text);
- text = "{" + string.Format("{0}:{1}:{2}:{3}:{4}:{5}", f, n - 1, d + 1, x + 1, a, b) + "}";
- theend[f][n - 1].Add(text);
- }
- }
- }
- 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)
- {
- for (int y = 0; y < y_max; y++)
- {
- for (int z = 0; z < set_size; z++)
- {
- for (int x = x_min; x < x_max; x++)
- {
- if (theend.ContainsKey(x) && theend[x].ContainsKey(y) && theend[x][y].Count > z)
- {
- String[] values = theend[x][y][z].Split(':');
- int e = Int32.Parse(values[0].Split('{')[1]);
- int n = Int32.Parse(values[1]);
- int d = Int32.Parse(values[2]);
- int xx = Int32.Parse(values[3]);
- int a = Int32.Parse(values[4]);
- int b = Int32.Parse(values[5].Split('}')[0]);
- int c = a * b;
- float red = (float)xx / (i_max / 2);
- float green = (float)a / i_max;
- float blue = (float)b / (i_max * 2);
- int ypos = e % 2 == 0 ? n : -n;
- //int zpos = e % 2 == 0 ? d : -d;
- GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
- cube.transform.position = new Vector3(e, ypos, d);
- cube.GetComponent<Renderer>().material.color = new Color(red, green, blue);
- cube.GetComponent<MeshRenderer>().receiveShadows = false;
- cube.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement