private void MandelbrotCubes() { int result; double interval = 0.01; var plane = GameObject.CreatePrimitive(PrimitiveType.Plane); plane.transform.position = new Vector3(0, -0.1F, 0); plane.transform.localScale = new Vector3(1, 0.1F, 1); for (double x = -2; x < 2; x += interval) { for (double y = -2; y < 2; y += interval) { if (Math.Sqrt(x * x + y * y) <= 2) { result = MandelbrotGen.Iterate(x, y); if (result != 0) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = new Vector3((float)x, 0, (float)y); cube.transform.localScale = new Vector3((float)interval, (float)(0.01 + result / 100), (float)interval); } } } } }
public void GenerateMesh() { for (int i = 0; i < vertices.Length; i++) { int x = i % width; int y = (int)(i / width); double pltX = -2 + (i % width) * interval; double pltY = -2 + (int)(i / width) * interval; int z = -3; if (Math.Sqrt(pltX * pltX + pltY * pltY) <= 2) { z = 2 - MandelbrotGen.Iterate(pltX, pltY); } vertices[i] = new Vector3((float)(pltX - 1), z / 10, (float)(pltY - 1)); if (x < width - 1 && y < height - 1) { addTriangle(i, (i + width), (i + width + 1)); addTriangle(i, (i + width + 1), (i + 1)); } } Mesh mesh = new Mesh(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); meshFilter.sharedMesh = mesh; }
void Start() { mandelbrot = FindObjectOfType <MandelbrotGen>(); applyShader = FindObjectOfType <ApplyShader>(); }