当前位置: 首页>>代码示例>>C#>>正文


C# Color.GetUpperBound方法代码示例

本文整理汇总了C#中Color.GetUpperBound方法的典型用法代码示例。如果您正苦于以下问题:C# Color.GetUpperBound方法的具体用法?C# Color.GetUpperBound怎么用?C# Color.GetUpperBound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Color的用法示例。


在下文中一共展示了Color.GetUpperBound方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawHorizontalLine

        /// <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++;
            }
        }
开发者ID:disks86,项目名称:MonoGameUI,代码行数:23,代码来源:DrawingUtilities.cs

示例2: DownShift

        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.
        }
开发者ID:NAIT-CNT,项目名称:CMPE1300.Public,代码行数:16,代码来源:Program.cs

示例3: CompareWithToleranceAt

 /// <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;
 }
开发者ID:kbinani,项目名称:fez-trade-bot,代码行数:30,代码来源:ImageComparator.cs

示例4: CompareAt

 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;
 }
开发者ID:kbinani,项目名称:fez-trade-bot,代码行数:18,代码来源:ImageComparator.cs

示例5: CreateEllipseTexture


//.........这里部分代码省略.........
                    // 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;
        }
开发者ID:rpwjanzen,项目名称:2HourGame,代码行数:101,代码来源:DrawingHelper.cs

示例6: InitializeTextureColors

 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];
             }
         }
     }
 }
开发者ID:jamesgecko,项目名称:rom-terraria,代码行数:40,代码来源:MapComponent.cs

示例7: Update

        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))
                //{
//.........这里部分代码省略.........
开发者ID:jamesgecko,项目名称:rom-terraria,代码行数:101,代码来源:MapComponent.cs

示例8: getFrames

        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];
        }
开发者ID:balorian,项目名称:Ludum24,代码行数:49,代码来源:SpriteTemplate.cs

示例9: Fill

 /// <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;
     }
 }
开发者ID:disks86,项目名称:MonoGameUI,代码行数:12,代码来源:DrawingUtilities.cs

示例10: PickColour

 /// <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)];
 }
开发者ID:hankmorgan,项目名称:UnderworldExporter,代码行数:9,代码来源:TileMap.cs


注:本文中的Color.GetUpperBound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。