本文整理汇总了C#中Color.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Color.Count方法的具体用法?C# Color.Count怎么用?C# Color.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Color
的用法示例。
在下文中一共展示了Color.Count方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: makeBox
public void makeBox()
{
Globals.GraphicsDevice.Textures[0] = null;
Color[] colors = new Color[CellBorder.Width * CellBorder.Height];
CellBorder.GetData(colors);
// left side
for (int y = 0; y < CellBorder.Height; y++)
{
colors[y] = Color.Gray;
}
// right side
for (int y = colors.Count() - 1; y > colors.Count() - CellBorder.Height; y--)
{
colors[y] = Color.Gray;
}
// Top
for (int y = 0; y < colors.Count(); y = y + CellBorder.Height)
{
colors[y] = Color.Gray;
}
// Bottom
for (int y = CellBorder.Height - 1; y < colors.Count(); y = y + CellBorder.Height)
{
colors[y] = Color.Gray;
}
CellBorder.SetData(colors);
Globals.GraphicsDevice.Textures[0] = Textures.texture;
}
示例2: RenderPreview
public override void RenderPreview(Bitmap output, Action<int> progressCallback)
{
//for (int y = 0; y < height; y++) {
var pixels = new Color[Width * Height];
#if PL
Parallel.For(0, Height, y =>
#else
for (int y = 0; y < height; y++)
#endif
{
for (int x = 0; x < Width; x++)
{
IRay ray;
camera.GetRay(x, y, out ray);
var pixelColor = Trace((RayInfo) ray, 1.0f, Air, 0);
pixels[x + y * Width] = pixelColor.ToColor();
}
//Console.Write("{0}->", height / (y+1) );
}
#if PL
);
#endif
Console.WriteLine("{0} Non black pixels", pixels.Count(item => (item.R > 0 || item.G > 0 || item.B > 0)));
Console.WriteLine("{0} Triangles", scene.Vertices.Length / 3);
Console.WriteLine("{0} Intersections", Intersections);
Console.WriteLine("{0} Rays traced", RaysTraced);
Console.WriteLine("Splatting");
for (int y = 0; y < Height; y++)
for (int x = 0; x < Width; x++)
{
output.SetPixel(x, y, pixels[x + (Height - 1 - y) * Width]);
}
}
示例3: ByPointsColors
public static Display ByPointsColors([KeepReferenceAttribute]Point[] points, Color[] colors)
{
if(points == null)
{
throw new ArgumentNullException("points");
}
if (!points.Any())
{
throw new ArgumentException(Resources.NoVertexExceptionMessage, "points");
}
if (points.Count() %3 != 0)
{
throw new ArgumentException(Resources.VerticesDivisibleByThreeExceptionMessage);
}
if(colors == null)
{
throw new ArgumentNullException("colors");
}
if (!colors.Any())
{
throw new ArgumentException(Resources.NoColorsExceptionMessage, "colors");
}
if (colors.Count() != points.Count())
{
throw new ArgumentException(Resources.VertexColorCountMismatchExceptionMessage, "colors");
}
return new Display(points, colors);
}
示例4: calculateRadius
void calculateRadius()
{
radiiSquared = new float[cols * rows];
int frameNo = 0;
for (int y = 0; y < rows; ++y) {
for (int x = 0; x < cols; ++x, ++frameNo) {
radiiSquared[frameNo] = 0;
if (Texture != null) {
Rectangle dimension = this.dimension;
dimension.X = this.dimension.Width * x;
dimension.Y = this.dimension.Height * y;
Color[] colors = new Color[dimension.Width * dimension.Height];
Texture.GetData<Color>(0, dimension, colors, 0, colors.Count());
Vector2 pos = new Vector2(0, 0);
// Begin radius check loop
for (int i = 0; pos.X < dimension.Width; ++pos.X)
for (pos.Y = 0; pos.Y < dimension.Height; ++pos.Y, ++i) {
if (colors[i].A > 0)
radiiSquared[frameNo] = Math.Max(radiiSquared[frameNo], (pos - Origin).LengthSquared());
}
}
}
}
}
示例5: StampAlpha
/// <summary>
/// Stamp the alpha values from one sprite onto another sprite
/// </summary>
/// <param name="transformA">World transform of the first sprite.</param>
/// <param name="widthA">Width of the first sprite's texture.</param>
/// <param name="heightA">Height of the first sprite's texture.</param>
/// <param name="dataA">Pixel color data of the first sprite.</param>
/// <param name="transformB">World transform of the second sprite.</param>
/// <param name="widthB">Width of the second sprite's texture.</param>
/// <param name="heightB">Height of the second sprite's texture.</param>
/// <param name="dataB">Pixel color data of the second sprite.</param>
private static Color[] StampAlpha(
Matrix transformA, int widthA, int heightA, Color[] dataA,
Matrix transformB, int widthB, int heightB, Color[] dataB, bool Invert)
{
Color[] newPixels = new Color[dataA.Count()];
// Calculate a matrix which transforms from A's local space into
// world space and then into B's local space
Matrix transformAToB = transformA * Matrix.Invert(transformB);
/*
Vector3 scale;
Quaternion rotation;
Vector3 translation;
transformAToB.Decompose(out scale, out rotation, out translation);
*/
//transformAToB = Matrix.CreateScale(scale) * Matrix.CreateRotationZ(rotation.Z) * Matrix.CreateTranslation(translation);
// When a point moves in A's local space, it moves in B's local space with a
// fixed direction and distance proportional to the movement in A.
// This algorithm steps through A one pixel at a time along A's X and Y axes
// Calculate the analogous steps in B:
Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB);
Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB);
// Calculate the top left corner of A in B's local space
// This variable will be reused to keep track of the start of each row
Vector2 yPosInB = Vector2.Transform(Vector2.Zero, transformAToB);
// For each row of pixels in A
for (int yA = 0; yA < heightA; yA++)
{
// Start at the beginning of the row
Vector2 posInB = yPosInB;
// For each pixel in this row
for (int xA = 0; xA < widthA; xA++)
{
// Round to the nearest pixel
int xB = (int)Math.Round(posInB.X);
int yB = (int)Math.Round(posInB.Y);
int indexA = xA + ((heightA - yA - 1) * widthA);
Color colorA = dataA[indexA];
// If the pixel lies within the bounds of B
if (0 <= xB && xB < widthB &&
0 <= yB && yB < heightB)
{
// Get the colors of the overlapping pixels
Color colorB = dataB[xB + ((heightB - yB - 1) * widthB)];
byte alpha = colorA.A;
byte alphaB = colorB.A;
if (Invert)
{
alphaB = (byte)(0xff - alphaB);
}
alpha = (byte)(Math.Max(0, alpha - alphaB));
// newPixels[indexA] = colorB;
newPixels[indexA] = colorA *(alpha / 255f);
}
else
{
if (Invert)
{
newPixels[indexA] = Color.Transparent;
}
else
{
newPixels[indexA] = colorA;
}
}
// Move to the next pixel in the row
posInB += stepX;
}
// Move to the next row
yPosInB += stepY;
}
return newPixels;
}
示例6: LoadContent
public void LoadContent(ContentManager content, string filename, Color boundingColor, float layer)
{
#region Getting Colors
Texture2D tex = content.Load<Texture2D>(filename);
Color[] data = new Color[tex.Width * tex.Height];
tex.GetData<Color>(data);
//Get the data in 2D array form
Color[,] colors = new Color[tex.Width, tex.Height];
int z = 0;
for (int y = 0; y < tex.Height; y++)
{
for (int x = 0; x < tex.Width; x++, z++)
{
colors[x, y] = data[z];
}
}
#endregion Getting Colors
#region Getting Rectangles
int y1 = 1;
int x1 = 1;
int rectCount = 0;
int lastXBound = 0;
int nextXBound = 0;
int height = tex.Height - 2;
Rectangle[] rects = new Rectangle[41];
while (rectCount < rects.Count())
{
while (colors[x1, 1] != boundingColor)
{
x1++;
}
nextXBound = x1;
Rectangle rect = new Rectangle(lastXBound + 1, y1, nextXBound - lastXBound - 1, height);
rects[rectCount] = rect;
rectCount++;
lastXBound = nextXBound;
x1++;
}
#endregion Getting Rectangles
#region Removing Source Rectangles
for (int j = 0; j < data.Count(); j++)
{
if (data[j] == boundingColor)
{
data[j] = new Color(0, 0, 0, 0);
}
}
texture = new Texture2D(ScreenHelper.GraphicsDevice, tex.Width, tex.Height);
texture.SetData<Color>(data);
#endregion Removing Source Rectangles
#region Adding chars
int charNext = 65;
int i = 0;
while (charNext <= 90)
{
letters.Add((char)charNext++, rects[i++]);
}
charNext = 49;
while (charNext <= 57)
{
letters.Add((char)charNext++, rects[i++]);
}
letters.Add('0', rects[i++]);
letters.Add('%', rects[i++]);
letters.Add(':', rects[i++]);
letters.Add('!', rects[i++]);
letters.Add('?', rects[i++]);
letters.Add('.', rects[i]);
#endregion Adding chars
Layer = layer;
}