Exemplo n.º 1
0
 private IntVertex2 ScanX(List <IntVertex2> vertices, IntVertex2 start, int endX)
 {
     if (start.x < endX)
     {
         for (int x = start.x; x <= endX; x++)
         {
             var vertex = vertices.Find(v => v.y == start.y && v.x == x);
             if (vertex != null)
             {
                 return(vertex);
             }
         }
     }
     else
     {
         for (int x = start.x; x >= endX; x--)
         {
             var vertex = vertices.Find(v => v.y == start.y && v.x == x);
             if (vertex != null)
             {
                 return(vertex);
             }
         }
     }
     return(null);
 }
Exemplo n.º 2
0
 private IntVertex2 ScanY(List <IntVertex2> vertices, IntVertex2 start, int endY)
 {
     if (start.y < endY)
     {
         for (int y = start.y; y <= endY; y++)
         {
             var vertex = vertices.Find(v => v.x == start.x && v.y == y);
             if (vertex != null)
             {
                 return(vertex);
             }
         }
     }
     else
     {
         for (int y = start.y; y >= endY; y--)
         {
             var vertex = vertices.Find(v => v.x == start.x && v.y == y);
             if (vertex != null)
             {
                 return(vertex);
             }
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         switch (counter)
         {
             case 0:
                 renderer.material.mainTexture = TextureE.Pixel(Color.blue);
                 counter++;
                 break;
             case 1:
                 renderer.material.mainTexture = TextureE.whitePixel;
                 counter++;
                 break;
             case 2:
                 renderer.material.mainTexture = TextureE.blackPixel;
                 counter++;
                 break;
             case 3:
                 renderer.material.mainTexture = TextureE.Gradient(Color.red, Color.green);
                 counter++;
                 break;
             case 4:
                 renderer.material.mainTexture = TextureE.checker;
                 counter++;
                 break;
             case 5:
                 renderer.material.mainTexture = new Texture2D(256, 256) {filterMode = FilterMode.Point};
                 counter = 0;
                 break;
         }
     }
     if (Input.GetMouseButtonDown(1))
     {
         if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit) && hit.transform == transform)
         {
             var texture = (Texture2D)renderer.material.mainTexture;
             var x = (int)(hit.textureCoord.x * texture.width);
             var y = (int)(hit.textureCoord.y * texture.height);
             start = new IntVertex2(x, y);
             texture.DrawCircle(start, 4, RandomE.colorHSV);
         }
     }
     if (Input.GetMouseButtonUp(1))
     {
         if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit) && hit.transform == transform)
         {
             var texture = (Texture2D)renderer.material.mainTexture;
             var x = (int)(hit.textureCoord.x * texture.width);
             var y = (int)(hit.textureCoord.y * texture.height);
             var end = new IntVertex2(x, y);
             texture.DrawLine(start, end, RandomE.colorHSV);
             texture.DrawCircle(end, 4, RandomE.colorHSV);
         }
     }
 }
Exemplo n.º 4
0
        private IEnumerator Extrude()
        {
            //while (canExtrude)
            {
                freeSegments = new List <Indexed <IntSegment2> >();

                for (int i = 1; i < rooms.Count; i++)
                {
                    var room = rooms[i];
                    //if (!room.canGrow) continue;

                    var newSegments = new List <Indexed <IntSegment2> >();

                    foreach (var wall in room.segments)
                    {
                        IntVertex2        start = null, end = null;
                        Action <int, int> getPixel = (x, y) =>
                        {
                            var color = texture.GetPixel(x, y);
                            if (color == fillColor || color == room.color)
                            {
                                debugTexture.SetPixel(x, y, RandomE.colorHSV);
                                if (start == null)
                                {
                                    start = new IntVertex2(x, y);
                                }
                                if (null == end)
                                {
                                    end = new IntVertex2(x, y);
                                }
                                else
                                {
                                    end.x = x;
                                    end.y = y;
                                }
                            }
                            else
                            {
                                if (start != null)
                                {
                                    newSegments.Add(new Indexed <IntSegment2>(new IntSegment2(start, end), i));
                                    start = null;
                                    end   = null;
                                }
                            }
                        };
                        TextureE.BresenhamLine(wall + wall.left, getPixel);
                    }
                    if (newSegments.Count == 0)
                    {
                        //room.canGrow = false;
                    }
                    else
                    {
                        freeSegments.AddRange(newSegments);
                    }
                }
                debugTexture.Apply();
                canExtrude = rooms.Any(r => r.canGrow);
                yield return(new WaitForSeconds(0.3f));
            }
        }
Exemplo n.º 5
0
        private IEnumerator Extrude()
        {
            //while (canExtrude)
            {
                freeSegments = new List<Indexed<IntSegment2>>();

                for (int i = 1; i < rooms.Count; i++)
                {
                    var room = rooms[i];
                    //if (!room.canGrow) continue;

                    var newSegments = new List<Indexed<IntSegment2>>();

                    foreach (var wall in room.segments)
                    {
                        IntVertex2 start = null, end = null;
                        Action<int, int> getPixel = (x, y) =>
                        {
                            var color = texture.GetPixel(x, y);
                            if (color == fillColor || color == room.color)
                            {
                                debugTexture.SetPixel(x, y, RandomE.colorHSV);
                                if (start == null)
                                {
                                    start = new IntVertex2(x, y);
                                }
                                if (null == end)
                                {
                                    end = new IntVertex2(x, y);
                                }
                                else
                                {
                                    end.x = x;
                                    end.y = y;
                                }
                            }
                            else
                            {
                                if (start != null)
                                {
                                    newSegments.Add(new Indexed<IntSegment2>(new IntSegment2(start, end), i));
                                    start = null;
                                    end = null;
                                }
                            }
                        };
                        TextureE.BresenhamLine(wall + wall.left, getPixel);
                    }
                    if (newSegments.Count == 0)
                    {
                        //room.canGrow = false;
                    }
                    else
                    {
                        freeSegments.AddRange(newSegments);
                    }
                }
                debugTexture.Apply();
                canExtrude = rooms.Any(r => r.canGrow);
                yield return new WaitForSeconds(0.3f);
            }
        }
Exemplo n.º 6
0
 private IntVertex2 ScanY(List<IntVertex2> vertices, IntVertex2 start, int endY)
 {
     if (start.y < endY)
     {
         for (int y = start.y; y <= endY; y++)
         {
             var vertex = vertices.Find(v => v.x == start.x && v.y == y);
             if (vertex != null)
             {
                 return vertex;
             }
         }
     }
     else
     {
         for (int y = start.y; y >= endY; y--)
         {
             var vertex = vertices.Find(v => v.x == start.x && v.y == y);
             if (vertex != null)
             {
                 return vertex;
             }
         }
     }
     return null;
 }
Exemplo n.º 7
0
 private IntVertex2 ScanX(List<IntVertex2> vertices, IntVertex2 start, int endX)
 {
     if (start.x < endX)
     {
         for (int x = start.x; x <= endX; x++)
         {
             var vertex = vertices.Find(v => v.y == start.y && v.x == x);
             if (vertex != null)
             {
                 return vertex;
             }
         }
     }
     else
     {
         for (int x = start.x; x >= endX; x--)
         {
             var vertex = vertices.Find(v => v.y == start.y && v.x == x);
             if (vertex != null)
             {
                 return vertex;
             }
         }
     }
     return null;
 }
Exemplo n.º 8
0
        private void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                switch (counter)
                {
                case 0:
                    renderer.material.mainTexture = TextureE.Pixel(Color.blue);
                    counter++;
                    break;

                case 1:
                    renderer.material.mainTexture = TextureE.whitePixel;
                    counter++;
                    break;

                case 2:
                    renderer.material.mainTexture = TextureE.blackPixel;
                    counter++;
                    break;

                case 3:
                    renderer.material.mainTexture = TextureE.Gradient(Color.red, Color.green);
                    counter++;
                    break;

                case 4:
                    renderer.material.mainTexture = TextureE.checker;
                    counter++;
                    break;

                case 5:
                    renderer.material.mainTexture = new Texture2D(256, 256)
                    {
                        filterMode = FilterMode.Point
                    };
                    counter = 0;
                    break;
                }
            }
            if (Input.GetMouseButtonDown(1))
            {
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit) && hit.transform == transform)
                {
                    var texture = (Texture2D)renderer.material.mainTexture;
                    var x       = (int)(hit.textureCoord.x * texture.width);
                    var y       = (int)(hit.textureCoord.y * texture.height);
                    start = new IntVertex2(x, y);
                    texture.DrawCircle(start, 4, RandomE.colorHSV);
                }
            }
            if (Input.GetMouseButtonUp(1))
            {
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit) && hit.transform == transform)
                {
                    var texture = (Texture2D)renderer.material.mainTexture;
                    var x       = (int)(hit.textureCoord.x * texture.width);
                    var y       = (int)(hit.textureCoord.y * texture.height);
                    var end     = new IntVertex2(x, y);
                    texture.DrawLine(start, end, RandomE.colorHSV);
                    texture.DrawCircle(end, 4, RandomE.colorHSV);
                }
            }
        }