Ejemplo n.º 1
0
        void CreateCube()
        {
            // Fill a 3D array with random colors and place it on the scene
            Color[,,] myModel = new Color[modelSize, modelSize, modelSize];

            int maxY = myModel.GetUpperBound(0);
            int maxZ = myModel.GetUpperBound(1);
            int maxX = myModel.GetUpperBound(2);

            for (int y = 0; y <= maxY; y++)
            {
                for (int z = 0; z <= maxZ; z++)
                {
                    for (int x = 0; x <= maxX; x++)
                    {
                        Color r = new Color(Random.value, Random.value, Random.value);
                        myModel[y, z, x] = r;
                    }
                }
            }
            env.ModelPlace(Vector3.zero, myModel);
            SetupNavigation();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws a horizontal line to an array of pixel starting at the provided point and continuing horizontally for the number of pixels provided in the length argument.
        /// </summary>
        /// <param name="texture">The texture that will be updated with the pixel array.</param>
        /// <param name="pixels">The pixel array that will be updated.</param>
        /// <param name="c">The color to be used for the drawn line.</param>
        /// <param name="p1">The point to start the line.</param>
        /// <param name="length">The length of the line in pixels.</param>
        public static void DrawHorizontalLine(Texture2D texture, Color[] pixels, Color c, Point p1, int length)
        {
            int count = 0;
            for (int i = p1.X * texture.Width + (p1.Y); i <= pixels.GetUpperBound(0); i++)
            {
                if (count > length)
                {
                    break;
                }

                pixels[i] = c;

                count++;
            }
        }
Ejemplo n.º 3
0
        static Color[,] DownShift(Color[,] orig)
        {
            //Shift all the colors to the right, with wrapping (rightmost becomes leftmost)
            //Returns a new array...no affect on old array.
            Color[,] repl = new Color[orig.GetLength(0), orig.GetLength(1)];
            //(1) Copy rightmost column of org to leftmost of repl
            for (int col = 0; col < orig.GetLength(1); col++)
                repl[0, col] = orig[repl.GetUpperBound(0), col];

            //(2) Copy remaining columns, one to left
            for (int row = 0; row < orig.GetLength(0) - 1; row++)
                for (int col = 0; col < orig.GetLength(1); col++)
                    repl[row + 1, col] = orig[row, col];

            return repl; //Return new one.
        }
Ejemplo n.º 4
0
        public static Texture2D CreateEllipseTexture(GraphicsDevice graphicsDevice, int xRadius, int yRadius, int borderWidth,
                                                     int borderInnerTransitionWidth, int borderOuterTransitionWidth,
                                                     Color color, Color borderColor)
        {
            //Is it a circle?
            if (xRadius == yRadius)
            {
                return(CreateCircleTexture(graphicsDevice, xRadius, borderWidth,
                                           borderInnerTransitionWidth, borderOuterTransitionWidth, color, borderColor));
            }

            int width  = xRadius * 2;
            int height = yRadius * 2;

            //Initialize values
            int     diameterX = (width + 8);
            int     diameterY = (height + 8);
            Vector2 center    = new Vector2((diameterX - 4) / 2f, (diameterY - 4) / 2f);

            Texture2D ellipse = new Texture2D(graphicsDevice, diameterX, diameterY, 1, TextureUsage.None,
                                              SurfaceFormat.Color);

            //Just calculate the upper left quarter of the ellipse
            //(it's axis-symmetric)
            Color[,] ulColors = new Color[diameterX / 2 + 1, diameterY / 2 + 1];

            //Create a description of the ellipse boundary

            //How accurate must it be?
            int accuracy = 360;

            if (Math.Max(width, height) > 1024)
            {
                accuracy = 1440;
            }
            else if (Math.Max(width, height) > 512)
            {
                accuracy = 1080;
            }
            else if (Math.Max(width, height) > 256)
            {
                accuracy = 720;
            }
            Vector2[] ellipseBoundary = CalculateEllipseBoundary(width, height, center, accuracy);

            //Calculate color for every pixel
            for (int y = 0; y < ulColors.GetLength(1); y++)
            {
                for (int x = 0; x < ulColors.GetLength(0); x++)
                {
                    Vector2 curPoint = new Vector2(x, y);

                    // find the closest normal of the ellipse intersecting the current point

                    // approximate the point on the ellipse closest to the current point.
                    // this point is where the normal strikes the ellipse
                    Vector2 pointOnEllipse = ApproximateClosestPointOnEllipse(curPoint, ellipseBoundary);

                    // the following lines calculate the shortest distance
                    // from the current point to the ellipse boundary

                    // calculate this point's distance to the current point.
                    // this is what we need
                    float distanceFromCurToBoundary = (pointOnEllipse - curPoint).Length();


                    //NOTE: hack to find out whether the current point is inside the ellipse

                    // calculate angle of a straight line intersecting the center of the ellipse and the current point
                    Vector2 lineFromCurPointToCenter = curPoint - center;
                    float   gradient = lineFromCurPointToCenter.Y / lineFromCurPointToCenter.X;
                    float   angle    = (float)Math.Atan(gradient * width / height);

                    // find out where the line intersecting the center of the ellipse and the current point
                    // intersects the ellipse
                    Vector2 intersectionPoint = center + new Vector2(xRadius * (float)Math.Cos(angle),
                                                                     yRadius * (float)Math.Sin(angle));
                    // calculate squared distance from intersection point to center
                    float distanceFromIntersectionPointToCenter = (intersectionPoint - center).LengthSquared();
                    // calculate squared distance from current point to center of ellipse
                    float distanceFromCurPointToCenter = lineFromCurPointToCenter.LengthSquared();

                    // when boundary intersection is further from the center than the current point,
                    // the current point should be inside of the ellipse.
                    // positive values for mean outside of the ellipse, negative values mean inside
                    if (distanceFromIntersectionPointToCenter >= distanceFromCurPointToCenter)
                    {
                        distanceFromCurToBoundary = -distanceFromCurToBoundary;
                    }


                    // use calculated distanceFromCurToBoundary to
                    // choose the color for thecurrent pixel

                    if (distanceFromCurToBoundary > 0)
                    {
                        // outside of ellipse
                        ulColors[x, y] = Color.TransparentBlack;
                    }
                    else if (distanceFromCurToBoundary > -borderOuterTransitionWidth)
                    {
                        // outside of border, where the border color fades to transparent
                        float transitionAmount = (-distanceFromCurToBoundary) / borderOuterTransitionWidth;
                        transitionAmount = 255 * transitionAmount;
                        ulColors[x, y]   = new Color(borderColor.R, borderColor.G, borderColor.B, (byte)transitionAmount);
                    }
                    else if (distanceFromCurToBoundary > -(borderWidth + borderOuterTransitionWidth))
                    {
                        // on border
                        ulColors[x, y] = borderColor;
                    }
                    else if (distanceFromCurToBoundary >= -(borderWidth + borderOuterTransitionWidth + borderInnerTransitionWidth))
                    {
                        // inside of border, where the border color fades to the fill color
                        float transitionAmount = (-distanceFromCurToBoundary - (borderWidth + borderOuterTransitionWidth)) / (borderInnerTransitionWidth + 1);
                        transitionAmount = 1 - transitionAmount;
                        ulColors[x, y]   = new Color((byte)MathHelper.Lerp(color.R, borderColor.R, transitionAmount),
                                                     (byte)MathHelper.Lerp(color.G, borderColor.G, transitionAmount),
                                                     (byte)MathHelper.Lerp(color.B, borderColor.B, transitionAmount));
                    }
                    else
                    {
                        // inside of ellipse
                        ulColors[x, y] = color;

                        // because we are just drawing a quarter of the ellipse,
                        // once we are inside of it we can fill in the rest
                        // of the current line with the fill color
                        if (x < ulColors.GetUpperBound(0))
                        {
                            for (int ix = x + 1; ix < ulColors.GetLength(0); ix++)
                            {
                                ulColors[ix, y] = color;
                            }
                        }

                        // we're done with this line
                        break;
                    }
                }
            }

            // copy the upper left quarter of the ellipse into the final texture
            // and mirror it accordingly
            int ulWidth  = ulColors.GetLength(0);
            int ulHeight = ulColors.GetLength(1);

            Color[] finalcolors = new Color[diameterX * diameterY];
            for (int y = 0; y < diameterY; y++)
            {
                for (int x = 0; x < diameterX; x++)
                {
                    int curIndex = y * diameterX + x;

                    if (y < ulHeight)
                    {
                        if (x < ulWidth)
                        {
                            // upper left sector of final texture
                            finalcolors[curIndex] = ulColors[x, y];
                        }
                        else
                        {
                            // upper right sector of final texture - mirror around y-axis
                            finalcolors[curIndex] = ulColors[ulColors.GetUpperBound(0) - x % ulWidth, y];
                        }
                    }
                    else
                    {
                        if (x < ulWidth)
                        {
                            // lower left sector - mirror around x-axis
                            finalcolors[curIndex] = ulColors[x, ulColors.GetUpperBound(1) - y % ulHeight];
                        }
                        else
                        {
                            // lower right sector - mirror around both axes
                            finalcolors[curIndex] = ulColors[ulColors.GetUpperBound(0) - x % ulWidth,
                                                             ulColors.GetUpperBound(1) - y % ulHeight];
                        }
                    }
                }
            }

            ellipse.SetData(finalcolors);

            return(ellipse);
        }
        protected Bitmap _GetIndexedTextureAsBitmap(int index, int mipMapNumber)
        {
            Color[]      tempPalette = new Color[256];
            Color[]      palette     = new Color[256];
            FileStream   iStream     = new FileStream(_FilePath, FileMode.Open, FileAccess.Read);
            BinaryReader iReader     = new BinaryReader(iStream);

            iStream.Seek(_TextureDefinitions[index].Palette.Offset + _SubTextureHeaderLength, SeekOrigin.Begin);
            for (int i = 0; i <= tempPalette.GetUpperBound(0); i++)
            {
                int alpha = 0;
                int red   = 0;
                int green = 0;
                int blue  = 0;
                switch (_TextureDefinitions[index].Palette.BPP)
                {
                case 16:
                    ushort cData = iReader.ReadUInt16();
                    alpha = cData;
                    red   = cData;
                    green = cData;
                    blue  = cData;

                    //alpha = ((alpha & 0x8000) >> 15) << 7;
                    alpha = 255;
                    red   = ((red & 0x1F)) << 3;
                    green = ((green & 0x3E0) >> 5) << 3;
                    blue  = ((blue & 0x7C00) >> 10) << 3;
                    break;

                case 32:
                    red   = iReader.ReadByte();
                    green = iReader.ReadByte();
                    blue  = iReader.ReadByte();
                    alpha = iReader.ReadByte();
                    if (alpha != 0)
                    {
                        alpha = 255;
                    }
                    break;
                }
                tempPalette[i] = Color.FromArgb(alpha, red, green, blue);
            }

            int[] clutMap = BLPS2.PS2ImageData.BuildIDTex8ClutIndex();

            for (int i = 0; i <= palette.GetUpperBound(0); i++)
            {
                palette[i] = tempPalette[clutMap[i]];
            }

            int width  = _TextureDefinitions[index].SubTextures[mipMapNumber].Width;
            int height = _TextureDefinitions[index].SubTextures[mipMapNumber].Height;

            Bitmap image = new Bitmap(width, height);

            iStream.Seek(_TextureDefinitions[index].SubTextures[mipMapNumber].Offset + _SubTextureHeaderLength, SeekOrigin.Begin);
            byte[] rawData = iReader.ReadBytes((int)(_TextureDefinitions[index].SubTextures[mipMapNumber].Length -
                                                     _SubTextureHeaderLength));
            iReader.Close();
            iStream.Close();

            byte[] unSwizzled = rawData;
            if (_IsNTSCDemo == false && width >= 16)
            {
                unSwizzled = BLPS2.PS2ImageData.PS2DefianceUnSwizzle(rawData, width, height, 8);
            }

            int byteNum = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    image.SetPixel(x, y, palette[unSwizzled[byteNum]]);
                    byteNum++;
                }
            }

            return(image);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// screenの(offsetX, offsetY)の位置に、画像maskがあるかどうかを調べる。ただし、ピクセルのRGB値の差がtolerance以下であれば、そのピクセルは同じとみなす
 /// </summary>
 /// <param name="screen"></param>
 /// <param name="offsetX"></param>
 /// <param name="offsetY"></param>
 /// <param name="mask"></param>
 /// <param name="tolerance"></param>
 /// <param name="maskTransparentColor"></param>
 /// <returns></returns>
 private static bool CompareWithToleranceAt( Color[,] screen, int offsetX, int offsetY, Color[,] mask, int tolerance, Color maskTransparentColor )
 {
     int maskWidth = mask.GetUpperBound( 0 ) + 1;
     int maskHeight = mask.GetUpperBound( 1 ) + 1;
     for( int y = 0; y < maskHeight; y++ ) {
         for( int x = 0; x < maskWidth; x++ ) {
             var maskColor = mask[x, y];
             if( maskColor == maskTransparentColor ) {
                 continue;
             }
             var screenColor = screen[x + offsetX, y + offsetY];
             if( Math.Abs( maskColor.R - screenColor.R ) > tolerance ||
                 Math.Abs( maskColor.G - screenColor.G ) > tolerance ||
                 Math.Abs( maskColor.B - screenColor.B ) > tolerance ) {
                 return false;
             }
         }
     }
     return true;
 }
Ejemplo n.º 7
0
 private static bool CompareAt( Color[,] screen, int offsetX, int offsetY, Color[,] mask, Color maskTransparentColor )
 {
     int maskWidth = mask.GetUpperBound( 0 ) + 1;
     int maskHeight = mask.GetUpperBound( 1 ) + 1;
     for( int y = 0; y < maskHeight; y++ ) {
         for( int x = 0; x < maskWidth; x++ ) {
             var maskColor = mask[x, y];
             if( maskColor == maskTransparentColor ) {
                 continue;
             }
             var screenColor = screen[x + offsetX, y + offsetY];
             if( maskColor != screenColor ) {
                 return false;
             }
         }
     }
     return true;
 }
Ejemplo n.º 8
0
        public static Texture2D CreateEllipseTexture(GraphicsDevice graphicsDevice, int xRadius, int yRadius, int borderWidth,
                                                    int borderInnerTransitionWidth, int borderOuterTransitionWidth,
                                                    Color color, Color borderColor)
        {
            //Is it a circle?
            if (xRadius == yRadius)
                return CreateCircleTexture(graphicsDevice, xRadius, borderWidth,
                                           borderInnerTransitionWidth, borderOuterTransitionWidth, color, borderColor);

            int width = xRadius * 2;
            int height = yRadius * 2;

            //Initialize values
            int diameterX = (width + 8);
            int diameterY = (height + 8);
            Vector2 center = new Vector2((diameterX - 4) / 2f, (diameterY - 4) / 2f);

            Texture2D ellipse = new Texture2D(graphicsDevice, diameterX, diameterY, 1, TextureUsage.None,
                                              SurfaceFormat.Color);

            //Just calculate the upper left quarter of the ellipse
            //(it's axis-symmetric)
            Color[,] ulColors = new Color[diameterX / 2 + 1, diameterY / 2 + 1];

            //Create a description of the ellipse boundary

            //How accurate must it be?
            int accuracy = 360;
            if (Math.Max(width, height) > 1024)
                accuracy = 1440;
            else if (Math.Max(width, height) > 512)
                accuracy = 1080;
            else if (Math.Max(width, height) > 256)
                accuracy = 720;
            Vector2[] ellipseBoundary = CalculateEllipseBoundary(width, height, center, accuracy);

            //Calculate color for every pixel
            for (int y = 0; y < ulColors.GetLength(1); y++)
            {
                for (int x = 0; x < ulColors.GetLength(0); x++)
                {
                    Vector2 curPoint = new Vector2(x, y);

                    // find the closest normal of the ellipse intersecting the current point

                    // approximate the point on the ellipse closest to the current point.
                    // this point is where the normal strikes the ellipse
                    Vector2 pointOnEllipse = ApproximateClosestPointOnEllipse(curPoint, ellipseBoundary);

                    // the following lines calculate the shortest distance
                    // from the current point to the ellipse boundary

                    // calculate this point's distance to the current point.
                    // this is what we need
                    float distanceFromCurToBoundary = (pointOnEllipse - curPoint).Length();

                    //NOTE: hack to find out whether the current point is inside the ellipse

                    // calculate angle of a straight line intersecting the center of the ellipse and the current point
                    Vector2 lineFromCurPointToCenter = curPoint - center;
                    float gradient = lineFromCurPointToCenter.Y / lineFromCurPointToCenter.X;
                    float angle = (float)Math.Atan(gradient * width / height);

                    // find out where the line intersecting the center of the ellipse and the current point
                    // intersects the ellipse
                    Vector2 intersectionPoint = center + new Vector2(xRadius * (float)Math.Cos(angle),
                                                                     yRadius * (float)Math.Sin(angle));
                    // calculate squared distance from intersection point to center
                    float distanceFromIntersectionPointToCenter = (intersectionPoint - center).LengthSquared();
                    // calculate squared distance from current point to center of ellipse
                    float distanceFromCurPointToCenter = lineFromCurPointToCenter.LengthSquared();

                    // when boundary intersection is further from the center than the current point,
                    // the current point should be inside of the ellipse.
                    // positive values for mean outside of the ellipse, negative values mean inside
                    if (distanceFromIntersectionPointToCenter >= distanceFromCurPointToCenter)
                        distanceFromCurToBoundary = -distanceFromCurToBoundary;

                    // use calculated distanceFromCurToBoundary to
                    // choose the color for thecurrent pixel

                    if (distanceFromCurToBoundary > 0)
                    {
                        // outside of ellipse
                        ulColors[x, y] = Color.TransparentBlack;
                    }
                    else if (distanceFromCurToBoundary > -borderOuterTransitionWidth)
                    {
                        // outside of border, where the border color fades to transparent
                        float transitionAmount = (-distanceFromCurToBoundary) / borderOuterTransitionWidth;
                        transitionAmount = 255 * transitionAmount;
                        ulColors[x, y] = new Color(borderColor.R, borderColor.G, borderColor.B, (byte)transitionAmount);
                    }
                    else if (distanceFromCurToBoundary > -(borderWidth + borderOuterTransitionWidth))
                    {
                        // on border
                        ulColors[x, y] = borderColor;
                    }
                    else if (distanceFromCurToBoundary >= -(borderWidth + borderOuterTransitionWidth + borderInnerTransitionWidth))
                    {
                        // inside of border, where the border color fades to the fill color
                        float transitionAmount = (-distanceFromCurToBoundary - (borderWidth + borderOuterTransitionWidth)) / (borderInnerTransitionWidth + 1);
                        transitionAmount = 1 - transitionAmount;
                        ulColors[x, y] = new Color((byte)MathHelper.Lerp(color.R, borderColor.R, transitionAmount),
                                                   (byte)MathHelper.Lerp(color.G, borderColor.G, transitionAmount),
                                                   (byte)MathHelper.Lerp(color.B, borderColor.B, transitionAmount));
                    }
                    else
                    {
                        // inside of ellipse
                        ulColors[x, y] = color;

                        // because we are just drawing a quarter of the ellipse,
                        // once we are inside of it we can fill in the rest
                        // of the current line with the fill color
                        if (x < ulColors.GetUpperBound(0))
                            for (int ix = x + 1; ix < ulColors.GetLength(0); ix++)
                                ulColors[ix, y] = color;

                        // we're done with this line
                        break;
                    }
                }
            }

            // copy the upper left quarter of the ellipse into the final texture
            // and mirror it accordingly
            int ulWidth = ulColors.GetLength(0);
            int ulHeight = ulColors.GetLength(1);

            Color[] finalcolors = new Color[diameterX * diameterY];
            for (int y = 0; y < diameterY; y++)
            {
                for (int x = 0; x < diameterX; x++)
                {
                    int curIndex = y * diameterX + x;

                    if (y < ulHeight)
                    {
                        if (x < ulWidth)
                            // upper left sector of final texture
                            finalcolors[curIndex] = ulColors[x, y];
                        else
                            // upper right sector of final texture - mirror around y-axis
                            finalcolors[curIndex] = ulColors[ulColors.GetUpperBound(0) - x % ulWidth, y];
                    }
                    else
                    {
                        if (x < ulWidth)
                            // lower left sector - mirror around x-axis
                            finalcolors[curIndex] = ulColors[x, ulColors.GetUpperBound(1) - y % ulHeight];
                        else
                            // lower right sector - mirror around both axes
                            finalcolors[curIndex] = ulColors[ulColors.GetUpperBound(0) - x % ulWidth,
                                                             ulColors.GetUpperBound(1) - y % ulHeight];
                    }
                }
            }

            ellipse.SetData(finalcolors);

            return ellipse;
        }
Ejemplo n.º 9
0
 private void InitializeTextureColors()
 {
     if (textureColorsInitialized) return;
     textureColorsInitialized = true;
     textureColors = new Color[Terraria.Main.tileTexture.Length];
     int texelCount = 0;
     for (int i = 0; i < Terraria.Main.tileTexture.Length; i++)
     {
         if (Terraria.Main.tileTexture[i] == null)
         {
             textureColors[i] = Color.Transparent;
         }
         else
         {
             Color[] retrievedColor = new Color[Terraria.Main.tileTexture[i].Width * Terraria.Main.tileTexture[i].Height];
             Terraria.Main.tileTexture[i].GetData<Color>(0,
                 new Rectangle(0, 0, Terraria.Main.tileTexture[i].Width, Terraria.Main.tileTexture[i].Height),
                 retrievedColor, 0, Terraria.Main.tileTexture[i].Width * Terraria.Main.tileTexture[i].Height);
             //Terraria.Main.tileTexture[i].GetData<Color>(0, new Rectangle(4, 4, 1, 1), retrievedColor, 0, 1);
             Vector4 v = Vector4.Zero;
             texelCount = 0;
             for (int j = 0; j <= retrievedColor.GetUpperBound(0); j++)
             {
                 // TODO: Finish making this a "significant color" extractor
                 var vecToAdd = retrievedColor[j].ToVector4();
                 v += vecToAdd;
                 texelCount++;
             }
             if (texelCount == 0)
             {
                 textureColors[i] = Color.Black;
             }
             else
             {
                 v = v / texelCount;
                 textureColors[i] = new Color(v); // retrievedColor[0];
             }
         }
     }
 }
Ejemplo n.º 10
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            elapsedTime += gameTime.ElapsedGameTime;
            realtimeElapsedTime += gameTime.ElapsedGameTime;
            if (Terraria.Main.gameMenu) return; // If we're in the menu, we shouldn't update
            if (!textureColorsInitialized) return; // Nothing to draw yet to texture

            // Working on a real-time smaller map section
            if (settings.LocalMinimap && realtimeUpdateTime < realtimeElapsedTime)
            {
                realtimeUpdateTime = TimeSpan.FromMilliseconds(500);
                realtimeElapsedTime = TimeSpan.Zero;

                var p = Terraria.Main.player[Terraria.Main.myPlayer];
                int mapHeight = (int)(height * ((float)Terraria.Main.maxTilesY / Terraria.Main.maxTilesX));

                int px = (int)(p.position.X / 16.0);
                int py = (int)(p.position.Y / 16.0);

                int left = Math.Max(px - surroundingAreaWidth / 2, 0);
                int top = Math.Max(py - surroundingAreaHeight / 2, 0);
                for (int i = 0; i < surroundingAreaTexture.GetUpperBound(0); i++)
                    surroundingAreaTexture[i] = Color.Transparent;
                for (int y = top, yofs = 0; yofs < surroundingAreaHeight && y < Terraria.Main.maxTilesY; y++, yofs++)
                {
                    for (int x = left, xofs = 0; xofs < surroundingAreaWidth && x < Terraria.Main.maxTilesX; x++, xofs++)
                    {
                        float lightLevel = 0.5f; // 0.25f + (Terraria.Lighting.Brightness(w, h) * 0.75f);
                        if (x < 0 || y < 0)
                        {
                            surroundingAreaTexture[xofs + (yofs * surroundingAreaWidth)] = Color.Transparent;
                        }
                        else
                        {
                            Terraria.Tile t = Terraria.Main.tile[x, y];
                            surroundingAreaTexture[xofs + (yofs * surroundingAreaWidth)] = (t != null) ?
                                (t.lava ? Color.Red : t.liquid > 0 ? Color.Blue : t.active ?
                                    Color.FromNonPremultiplied(
                                        new Vector4(textureColors[t.type].R * lightLevel / 256,
                                                    textureColors[t.type].G * lightLevel / 256,
                                                    textureColors[t.type].B * lightLevel / 256, 1.0f))
                                    : Color.Transparent) :
                                Color.Transparent;
                        }
                    }
                }

                surroundingAreaTexture[surroundingAreaWidth * (py - top) + (px - left)] = Color.Magenta;
                try
                {
                    SurroundingAreaMapNextTexture.SetData<Color>(surroundingAreaTexture, 0, surroundingAreaWidth * surroundingAreaHeight);
                    Texture2D temp2 = SurroundingAreaMap;
                    SurroundingAreaMap = SurroundingAreaMapNextTexture;
                    SurroundingAreaMapNextTexture = temp2;
                }
                catch (InvalidOperationException)
                { } // Ignore...means FPS is too low
            }

            if (settings.GlobalMinimap && updateTime < elapsedTime)
            {
                updateTime = TimeSpan.FromMinutes(1); //Terraria.Main.netMode == 0 ? 5 : 1); // Update every five minutes in single player, one in multiplayer
                elapsedTime = TimeSpan.Zero;

                int worldwidth = Terraria.Main.maxTilesX;
                int worldheight = Terraria.Main.maxTilesY;
                int widthstep = (int)((float)worldwidth / width);
                int heightstep = (int)((float)worldheight / height);
                Color[] newTexture = new Color[width * height];
                for (int i = 0; i < newTexture.GetUpperBound(0); i++)
                    newTexture[i] = Color.Transparent;
                for (int h = 0, hofs = 0; h < worldheight && hofs < height; h += heightstep, hofs++)
                {
                    for (int w = 0, wofs = 0; w < worldwidth && wofs < width; w += widthstep, wofs++)
                    {
                        // Terraria.Lighting.Brightness is calculated only for the current screen.  D'oh.
                        float lightLevel = 0.5f; // 0.25f + (Terraria.Lighting.Brightness(w, h) * 0.75f);
                        Terraria.Tile t = Terraria.Main.tile[w, h];
                        newTexture[wofs + (hofs * width)] = (t != null) ?
                            (t.lava ? Color.Red : t.liquid > 0 ? Color.Blue : t.active ?
                                Color.FromNonPremultiplied(
                                    new Vector4(textureColors[t.type].R * lightLevel / 256,
                                                textureColors[t.type].G * lightLevel / 256,
                                                textureColors[t.type].B * lightLevel / 256, 1.0f))
                                : Color.Transparent) :
                            Color.Transparent;
                    }
                }
                try
                {
                    OverworldMapNextTexture.SetData<Color>(newTexture, 0, width * height);
                    Texture2D temp = OverworldMap;
                    OverworldMap = OverworldMapNextTexture;
                    OverworldMapNextTexture = temp;
                }
                catch (InvalidOperationException) { } // Ignore...means FPS is too low
                // Was only using this to test the overlay creation piece.  You will quickly get an exception if you enable this.
                //using (var fs = new System.IO.FileStream("overlay.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                //{
                //    Overlay.SaveAsJpeg(fs, width, height);
                //}
            }
        }
Ejemplo n.º 11
0
        private void getFrames(Color background)
        {
            Rectangle bounds = Sprite.SpriteSheets[sheet].Bounds;
            List<Frame> gatheredFrames = new List<Frame>();

            Color[] Colors1D = new Color[bounds.Width * bounds.Height];
            Sprite.SpriteSheets[sheet].GetData<Color>(Colors1D);
            Color[,] rawSheet = new Color[bounds.Width, bounds.Height];

            for (int i = 0; i < Colors1D.Length; i++)
                rawSheet[i % bounds.Width, i / bounds.Width] = Colors1D[i];

            for (int y = 0; y < rawSheet.GetUpperBound(1); y++)
            {
                for (int x = 0; x < rawSheet.GetUpperBound(0); x++)
                {
                    if (!rawSheet[x, y].Equals(background))
                    {
                        if (x == 0)
                        {
                            if (y == 0)
                                gatheredFrames.Add(new Frame(getSourceRectangle(background, rawSheet, new Point(x, y))));
                            else if (rawSheet[x, y - 1].Equals(background))
                                gatheredFrames.Add(new Frame(getSourceRectangle(background, rawSheet, new Point(x, y))));
                        }
                        else if (y == 0)
                        {
                            if (rawSheet[x - 1, y].Equals(background))
                                gatheredFrames.Add(new Frame(getSourceRectangle(background, rawSheet, new Point(x, y))));
                        }
                        else if (rawSheet[x, y - 1].Equals(background) && rawSheet[x - 1, y].Equals(background))
                        {
                            gatheredFrames.Add(new Frame(getSourceRectangle(background, rawSheet, new Point(x, y))));
                        }

                    }
                }
            }

            if (Size.Width == 0 && gatheredFrames.Count > 0)
                Size.Width = gatheredFrames[0].sourceRectangle.Width;
            if (Size.Height == 0 && gatheredFrames.Count > 0)
                Size.Height = gatheredFrames[0].sourceRectangle.Height;

            Frames = new Frame[gatheredFrames.Count];

            for (int i = 0; i < Frames.Length; i++)
                Frames[i] = gatheredFrames[i];
        }
Ejemplo n.º 12
0
        private void ProcessICRFields_Click(object sender, EventArgs e)
        {
            Int16 index;
            int   pLeft = 0, pTop = 0, pWidth = 0, pHeight = 0;

            Color[] mColor = new Color[] { Color.Red, Color.Green, Color.Blue };

            int mColorIndex = 0;

            PicImagXpress1.ColorDepth(24, PegasusImaging.WinForms.ImagXpress7.enumPalette.IPAL_Optimized, PegasusImaging.WinForms.ImagXpress7.enumDithered.DI_None);
            PicImagXpress1.DrawWidth = 8;

            Picssxicr1.StartFormProcessing();
            //Picssxicr1.AddFieldPreprocessImageAction(-1,pePreprocessImageAction.PP_DESPECKLE ,  "1,1");
            //Picssxicr1.AddFieldPreprocessImageAction(-1, pePreprocessImageAction.PP_FILL_LINE_HORIZ_WHITE, "2");
            //Picssxicr1.AddFieldPreprocessImageAction(-1, pePreprocessImageAction.PP_FILL_LINE_VERT_WHITE, "2");
            //Picssxicr1.PreprocessImage();

            //Picssxicr1.AddFieldPreprocessImageAction(-1, pePreprocessImageAction.PP_FILL_LINE_HORIZ_WHITE, "2");
            //Picssxicr1.FormFieldRetainImage

            for (index = 1; index != Picssxicr1.GetFormNumFields() + 1; index++)
            {
                Picssxicr1.SelectFormFieldIndex(index);
                Picssxicr1.GetFieldBounds(ref pLeft, ref pTop, ref pWidth, ref pHeight);

                //draw where the fields are on the image, for illustration purposes only
                PicImagXpress1.DrawRoundRect(pLeft, pTop, pLeft + pWidth, pTop + pHeight, 0, 0, mColor[mColorIndex]);

                mColorIndex = mColorIndex + 1;
                if (mColorIndex > mColor.GetUpperBound(0))
                {
                    mColorIndex = 0;
                }

                if (Picssxicr1.FieldError != 0)
                {
                    // if error on this field display error in list

                    /* resultsList.Items.Add(New ListViewItem( new String() {index.ToString(),
                     *                  Picssxicr1.GetFieldName(),
                     *                  Picssxicr1.FieldErrorString,
                     *                  ""})); */
                }
                else
                {
                    // demonstrates reading each character of result
                    MessageBox.Show(Picssxicr1.FieldResultStr);

                    /* charResult = "";
                     * for (charIndex = 1;  Picssxicr1.FieldResultChars != charIndex; charIndex++)
                     * {
                     *   Picssxicr1.FieldResultLineChar = charIndex;
                     *   charResult = charResult + Picssxicr1.FieldResultChar(1);
                     *
                     * }*/

                    /* resultsList.Items.Add(New ListViewItem(
                     *   New String() {index.ToString(),
                     *                   Picssxicr1.GetFieldName(),
                     *                   Picssxicr1.FieldResultStr,
                     *                   charResult}));*/
                }
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Fills an array of pixel with the provided color.
 /// </summary>
 /// <param name="pixels"></param>
 /// <param name="c"></param>
 public static void Fill(Color[] pixels,Color c)
 {
     for (int i = 0; i < pixels.GetUpperBound(0); i++)
     {
         pixels[i] = c;
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Picks a random colour from the array of colours
 /// </summary>
 /// <returns>The colour selected</returns>
 /// <param name="Selection">Selection.</param>
 public Color PickColour(Color[] Selection)
 {
     return Selection[Random.Range(0,Selection.GetUpperBound(0)+1)];
 }