Ejemplo n.º 1
0
 public static MyColor FromArgb(int argb)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         using (BinaryWriter bw = new BinaryWriter(ms))
         {
             bw.Write(argb);
         }
         byte[] buffer = ms.ToArray();
         // A Color's value is stored in a byte array blue, green, red, and alpha
         byte blue  = buffer[0];
         byte green = buffer[1];
         byte red   = buffer[2];
         byte alpha = buffer[3];
         return(MyColor.FromArgb(alpha, red, green, blue));
     }
 }
Ejemplo n.º 2
0
        //Размыть цвет вокселей
        public void BloorVoxels()
        {
            var newColors = new MyColor[sizeX, sizeZ];

            for (int x = 0; x < sizeX; x++)
            {
                for (int z = 0; z < sizeZ; z++)
                {
                    bool    haveOther = false;
                    MyColor m         = UpColors[x, z];
                    if (m == null)
                    {
                        continue;
                    }

                    int   c = 2;
                    float r = m.R * c, g = m.G * c, b = m.B * c;

                    for (int x2 = Math.Max(0, x - 1); x2 <= x + 1 && x2 < sizeX; x2++)
                    {
                        for (int z2 = Math.Max(0, z - 1); z2 <= z + 1 && z2 < sizeZ; z2++)
                        {
                            if (x2 != x && z2 != z && Math.Abs(Land[x, z] - Land[x2, z2]) < 3)
                            {
                                c++;
                                MyColor m2 = UpColors[x2, z2];
                                r += m2.R;
                                g += m2.G;
                                b += m2.B;
                            }
                        }
                    }

                    if (haveOther)
                    {
                        newColors[x, z] = MyColor.FromArgb((byte)(r / c), (byte)(g / c), (byte)(b / c));
                    }
                    else
                    {
                        newColors[x, z] = m;
                    }
                }
            }

            UpColors = newColors;
        }
Ejemplo n.º 3
0
 public static MyColor ToMyColor(this Color unityColor)
 {
     return(MyColor.FromArgb((int)(unityColor.r * 255), (int)(unityColor.g * 255), (int)(unityColor.b * 255), (int)(unityColor.a * 255)));
 }
Ejemplo n.º 4
0
 public static MyColor FromArgb(byte alpha, MyColor baseColor)
 {
     return(MyColor.FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B));
 }
Ejemplo n.º 5
0
 public static MyColor FromArgb(byte red, byte green, byte blue)
 {
     return(MyColor.FromArgb(255, red, green, blue));
 }
Ejemplo n.º 6
0
        //Узнать цвет вершины, учитываю затемненость от соседних блоков
        public MyColor GetColor(MyColor origColor, int x, int z, int y)
        {
            //return color;
            int c = -4;

            bool[] occupiedBlocks = new bool[8];

            if (landscapeBlock.HaveBlockLocal(x, y, z))
            {
                occupiedBlocks[0] = true;
            }
            if (landscapeBlock.HaveBlockLocal(x - 1, y, z))
            {
                occupiedBlocks[1] = true;
            }
            if (landscapeBlock.HaveBlockLocal(x, y, z - 1))
            {
                occupiedBlocks[2] = true;
            }
            if (landscapeBlock.HaveBlockLocal(x - 1, y, z - 1))
            {
                occupiedBlocks[3] = true;
            }

            if (landscapeBlock.HaveBlockLocal(x, y - 1, z))
            {
                occupiedBlocks[4] = true;
            }
            if (landscapeBlock.HaveBlockLocal(x - 1, y - 1, z))
            {
                occupiedBlocks[5] = true;
            }
            if (landscapeBlock.HaveBlockLocal(x, y - 1, z - 1))
            {
                occupiedBlocks[6] = true;
            }
            if (landscapeBlock.HaveBlockLocal(x - 1, y - 1, z - 1))
            {
                occupiedBlocks[7] = true;
            }

            c += occupiedBlocks.Count(o => o);

            if (c <= 0)
            {
                return(origColor);
            }

            float H, S, V;
            var   MyUnityColor = new Color(origColor.R / 255.0f, origColor.G / 255.0f, origColor.B / 255.0f);

            Color.RGBToHSV(MyUnityColor, out H, out S, out V);

            //S = S+(1.0f - S)/(4-c);
            //S = 0.0f;
            V = V * (4 - c) / 4;

            MyUnityColor = Color.HSVToRGB(H, S, V);

            return(MyColor.FromArgb(
                       (int)(MyUnityColor.r * 255 + 0.5),
                       (int)(MyUnityColor.g * 255 + 0.5),
                       (int)(MyUnityColor.b * 255 + 0.5)
                       ));
        }