void draw_cubes() { foreach (GameObject _cube in cubes) { Rect _r1 = RectangleCollisionChecker.BoundsToScreenRect(_cube.GetComponent <Renderer> ().bounds); Rect _r1_tex = new Rect(_r1.x, _r1.y, _r1.width, _r1.height); TextureDraw.DrawRectangle(tex, _r1_tex, Color.green); //TextureDraw.DrawLine(tex, (int)(_r1.x), (int)(_r1.y), (int)(_r1.xMax), (int)(_r1.y), Color.cyan); //Rect _r2 = RectangleCollisionChecker.BoundsToScreenRect(_cube.GetComponent<Renderer>().bounds); //TextureDraw.DrawLine(tex, (int)(_r1.x), (int)(_r1.y), (int)(_r1.xMax), (int)(_r1.yMax), Color.cyan); } //tex.Apply(); }
// Use this for initialization void Start() { cubes = new List <GameObject>(); tex = new Texture2D(Screen.width, Screen.height); TextureDraw.ClearTexture(tex); resetColorArray = tex.GetPixels32(); init_cube_templates(); init_terrain_data(); //draw_marched_squares(); //create a bunch of cubes int spawn_width = 5; for (int i = 0; i < 25; i++) { float _x = 2.5f - (0.2f * i); float _y = 3f + (5 * (i % spawn_width)); float _z = 5f; cubes.Add((GameObject)(Instantiate(cube_prefab, new Vector3(_x, _y, _z), Quaternion.identity))); } /* * * for(int i = 0; i < Screen.width; i++) * { * for(int _x = 10; _x < 20; _x++) * { * tex.SetPixel(i, _x, Color.cyan); * } * } * tex.SetPixel(2, 2, Color.cyan); * tex.SetPixel(3, 2, Color.cyan); * tex.SetPixel(4, 2, Color.cyan); * tex.SetPixel(2, 3, Color.cyan); * tex.SetPixel(3, 3, Color.cyan); * tex.SetPixel(4, 3, Color.cyan); */ //TextureDraw.DrawLine(tex, 10, 10, 30, 30, Color.yellow); tex.Apply(); }
/// <summary> /// Setting up initial systems /// </summary> private void Start() { Application.runInBackground = true; //Run application in background SetCameraLocation(); //Sets camera location to panel if (ErrorCheck() == false) { //Make sure all parameters given are valid draw = GetComponent <TextureDraw>(); draw.AddManager(this); Time.timeScale = 1f; //Time scale set to 1x timeScale = Time.timeScale; testCounter = 0; finished = new Semaphore(1, 1); //initialize a binary semaphore and set it to unlocked operations = new DatabaseOperation(); //initialize database oepration colors = new float[populationSize, 3]; GenerateSpeciesColor(); //Create random color for each species lineGraph.GetComponent <DataDrawer>().CalibrateGraph(200f, 50f, 0.5f, 0.04f, 0.15f, 0.15f); //Calibrate line graph } }
// ############################################ // TODO: dimezzare tutti i radius dei cerchi? # // ############################################ void Generate(int id) { CiaccoRandom randomer = new CiaccoRandom(); randomer.setSeed(id); //int ncol = 60;// min_color 0 //int xcol = 250;// max_color 255 // draw the hexagon: // hexagon's center coordinates and radius float hex_x = size / 2; float hex_y = size / 2; float radius = ((size / 2f) * 3f / 4f); TextureDraw.drawCircle(texture, size / 2, size / 2, (int)radius, color, thickness); int lati = randomer.getRand(4, 8); TextureDraw.drawPolygon(texture, lati, (int)radius, 0, size, color, thickness); int l; float ang; for (l = 0; l < lati; l++) { ang = Mathf.Deg2Rad * ((360 / (lati))) * l; TextureDraw.drawLine(texture, (size / 2), (size / 2), (int)((size / 2) + radius * Mathf.Cos(ang)), (int)((size / 2) + radius * Mathf.Sin(ang)), color, thickness); } int latis; if (lati % 2 == 0) { latis = randomer.getRand(2, 6); while (latis % 2 != 0) { latis = randomer.getRand(3, 6); } TextureDraw.drawFilledPolygon(texture, latis, (int)radius, 180, size, color, backgroundColor, thickness); for (l = 0; l < latis; l++) { ang = Mathf.Deg2Rad * ((360 / latis)) * l; TextureDraw.drawLine(texture, (size / 2), (size / 2), (int)((size / 2) + radius * Mathf.Cos(ang)), (int)((size / 2) + radius * Mathf.Sin(ang)), color, thickness); } } else { latis = randomer.getRand(2, 6); while (latis % 2 == 0) { latis = randomer.getRand(3, 6); } TextureDraw.drawFilledPolygon(texture, latis, (int)radius, 180, size, color, backgroundColor, thickness); } if (randomer.getRand(0, 1) % 2 == 0) { int ronad = randomer.getRand(0, 4); if (ronad % 2 == 1) { for (l = 0; l < lati + 4; l++) { ang = Mathf.Deg2Rad * ((360 / (lati + 4))) * l; TextureDraw.drawLine(texture, (size / 2), (size / 2), (int)((size / 2) + (((radius / 8) * 5) + 2) * Mathf.Cos(ang)), (int)((size / 2) + (((radius / 8) * 5) + 2) * Mathf.Sin(ang)), color, thickness); } TextureDraw.drawFilledPolygon(texture, lati + 4, (int)(radius / 2), 0, size, color, backgroundColor, thickness); } else if (ronad % 2 == 0) { for (l = 0; l < lati - 2; l++) { ang = Mathf.Deg2Rad * ((360 / (lati - 2))) * l; TextureDraw.drawLine(texture, (size / 2), (size / 2), (int)((size / 2) + (((radius / 8) * 5) + 2) * Mathf.Cos(ang)), (int)((size / 2) + (((radius / 8) * 5) + 2) * Mathf.Sin(ang)), color, thickness); } TextureDraw.drawFilledPolygon(texture, lati - 2, (int)(radius / 4), 0, size, color, backgroundColor, thickness); } } if (randomer.getRand(0, 4) % 2 == 0) { TextureDraw.drawCircle(texture, size / 2, size / 2, (int)((radius / 16f) * 11f), color, thickness); if (lati % 2 == 0) { latis = randomer.getRand(2, 8); while (latis % 2 != 0) { latis = randomer.getRand(3, 8); } TextureDraw.drawPolygon(texture, latis, (int)((radius / 3) * 2), 180, size, color, thickness); } else { latis = randomer.getRand(2, 8); while (latis % 2 == 0) { latis = randomer.getRand(3, 8); } TextureDraw.drawPolygon(texture, latis, (int)((radius / 3) * 2), 180, size, color, thickness); } } int caso = randomer.getRand(0, 3); float angdiff, posax, posay; if (caso == 0) { for (int i = 0; i < latis; i++) { angdiff = (Mathf.Deg2Rad * (360 / (latis))); posax = (((radius / 18) * 11) * Mathf.Cos(i * angdiff)); posay = (((radius / 18) * 11) * Mathf.Sin(i * angdiff)); TextureDraw.drawFilledCircle(texture, (int)(size / 2 + posax), (int)(size / 2 + posay), (int)((radius / 44) * 6), color, backgroundColor, thickness); } } else if (caso == 1) { for (int i = 0; i < latis; i++) { angdiff = (Mathf.Deg2Rad * (360 / latis)); posax = (radius * Mathf.Cos(i * angdiff)); posay = (radius * Mathf.Sin(i * angdiff)); TextureDraw.drawFilledCircle(texture, (int)(size / 2 + posax), (int)(size / 2 + posay), (int)((radius / 44) * 6), color, backgroundColor, thickness); } } else if (caso == 2) { TextureDraw.drawCircle(texture, size / 2, size / 2, (int)((radius / 18) * 6), color, thickness); TextureDraw.drawFilledCircle(texture, size / 2, size / 2, (int)((radius / 22) * 6), color, backgroundColor, thickness); } else if (caso == 3) { for (int i = 0; i < latis; i++) { ang = Mathf.Deg2Rad * ((360 / (latis))) * i; TextureDraw.drawLine(texture, (int)((size / 2) + ((radius / 3) * 2) * Mathf.Cos(ang)), (int)((size / 2) + ((radius / 3) * 2) * Mathf.Sin(ang)), (int)((size / 2) + radius * Mathf.Cos(ang)), (int)((size / 2) + radius * Mathf.Sin(ang)), color, thickness); } if (latis == lati) { } else { TextureDraw.drawFilledCircle(texture, size / 2, size / 2, (int)((radius / 3) * 2), color, backgroundColor, thickness); lati = randomer.getRand(3, 6); TextureDraw.drawPolygon(texture, lati, (int)((radius / 4) * 5), 0, size, color, thickness); TextureDraw.drawPolygon(texture, lati, (int)((radius / 3) * 2), 180, size, color, thickness); } } }
void draw_marched_squares() { int _voxel_width = Screen.width / (resolution); int _voxel_height = Screen.height / (resolution); int half_voxel_width = _voxel_width / 2; int half_voxel_height = _voxel_height / 2; string status_str = ""; QuadTreeNode quad_tree = quadtree_for_this_update; //first, carve up the region and parition them into areas with stuff //given an XxY array //now traverse the quad tree and only do checks for areas that have hits in them List <Rect> _rects_to_search = quad_tree.pluck_leaves(); foreach (Rect _rect in _rects_to_search) { status_str = ""; //TextureDraw.DrawRectangle(tex, _rect, Color.yellow); //int start_x = 0;//(int)_rect.x/_voxel_width; int start_x_voxel_index = (int)_rect.x / _voxel_width; if (start_x_voxel_index > 1) { start_x_voxel_index -= 1; } float rect_far_horizontal_side = _rect.x + _rect.width; float rect_far_vertical_side = _rect.y + _rect.height; int next_horizontal_voxel_index = Mathf.CeilToInt(rect_far_horizontal_side / _voxel_width); int next_vertical_voxel_index = Mathf.CeilToInt(rect_far_vertical_side / _voxel_height); for (int i = start_x_voxel_index; i < next_horizontal_voxel_index && i < resolution - 1; i++) { /* * status_str = "(_rect.x +_rect.width)/_voxel_width) " + ((_rect.x + _rect.width) / _voxel_width).ToString(); * status_str += " CeilToInt " + Mathf.CeilToInt((_rect.x + _rect.width) / _voxel_width).ToString(); * status_str += " i " + i.ToString() + " "; * status_str += " _voxel_width " + _voxel_width.ToString() + " "; * status_str += " rect.x " + _rect.x.ToString() + " "; * status_str += " _rect.width " + _rect.width.ToString() + " "; * Debug.Log(status_str); * */ int start_y_voxel_index = (int)_rect.y / _voxel_height; int current_voxel_x = (i * _voxel_width); for (int j = start_y_voxel_index; start_y_voxel_index < next_vertical_voxel_index && j < resolution - 1; j++) { int current_voxel_y = (j * _voxel_height); int index = 0; if (bool_values[i, j]) { index += 8; } if (bool_values[i + 1, j]) { index += 4; } if (bool_values[i + 1, j + 1]) { index += 2; } if (bool_values[i, j + 1]) { index += 1; } //ok we got our index, now draw it if (marching_cube_templates[index] != null) { for (int idx = 0; idx + 1 < marching_cube_templates[index].Length; idx += 2) { int line_start_left = (int)(marching_cube_templates[index][idx].x * _voxel_width); int line_finish_left = (int)(marching_cube_templates[index][idx + 1].x * _voxel_width); int line_start_bottom = (int)(marching_cube_templates[index][idx].y * _voxel_height); int line_finish_bottom = (int)(marching_cube_templates[index][idx + 1].y * _voxel_height); int x0 = line_start_left + current_voxel_x + half_voxel_height; int y0 = line_start_bottom + current_voxel_y + half_voxel_height; int x1 = line_finish_left + current_voxel_x + half_voxel_height; int y1 = line_finish_bottom + current_voxel_y + half_voxel_height; TextureDraw.DrawLine(tex, x0, y0, x1, y1, Color.cyan); } } } } } /* * //now that the values are set, lets draw them * for(int i = 0; i< resolution - 1; i++) * { * for(int j = 0; j < resolution - 1; j++) * { * int index = 0; * if(bool_values[i,j]) * index += 8; * if(bool_values[i+1,j]) * index += 4; * if(bool_values[i+1, j+1]) * index += 2; * if(bool_values[i, j+1]) * index += 1; * * * //ok we got our index, now draw it * if(marching_cube_templates[index] != null) * { * for(int idx = 0; idx + 1< marching_cube_templates[index].Length; idx += 2) * { * TextureDraw.DrawLine(tex, (int)(marching_cube_templates[index][idx].x * _voxel_width) + (i * _voxel_width) + (_voxel_width/2), (int)(marching_cube_templates[index][idx].y * _voxel_height) + (j * _voxel_height) + (_voxel_height/2), (int)(marching_cube_templates[index][idx + 1].x * _voxel_width) + (i * _voxel_width) + (_voxel_width/2), (int)(marching_cube_templates[index][idx + 1].y * _voxel_height) + (j * _voxel_height) + (_voxel_height/2), Color.cyan); * } * } * * } * }*/ }