void IPixel.Play(ref int score, ref bool gameover, IPixel head, ref IPixel berry) { do { Clear(); gameover |= head.XPosition == WindowWidth - 1 || head.XPosition == 0 || head.YPosition == WindowHeight - 1 || head.YPosition == 0; head.Score(ref score, head, ref berry); for (int i = 0; i < body.Count; i++) { head.DrawPixel(body[i]); gameover |= body[i].XPosition == head.XPosition && body[i].YPosition == head.YPosition; } if (gameover) { break; } head.DrawPixel(head); berry.DrawPixel(berry); const int milliseconds = 500; Stopwatch stopWatch = Stopwatch.StartNew(); while (stopWatch.ElapsedMilliseconds <= milliseconds) { currentMovement = Direction.ReadMovement(currentMovement); } body.Add(new Pixel(head.XPosition, head.YPosition, ConsoleColor.Green)); Direction.Choice(head, currentMovement); if (body.Count > score) { body.RemoveAt(0); } }while (true); }
/// <summary> /// Used to get a random enemy from the current region /// </summary> /// <param name="currentRegion">The current region, used to determine what enemy to return</param> /// <returns>An instance of a random enemy of type IPixel</returns> public static IPixel GetEnemies(Islands island, RegionType currentRegion, Rarity rarity, int x, int y) { if (island == Islands.home) { possibleEnemies = GetPossible(rarity, currentRegion, x, y); } //if (currentRegion == RegionType.forest) //{ // var pixel = forestEnemies[rand.Next(0, forestEnemies.Count - 1)]; // IPixel pix = (IPixel)Activator.CreateInstance(pixel.GetType()); // return pix; //} IPixel pixel = null; if (possibleEnemies.Count > 1) { pixel = possibleEnemies[rand.Next(0, possibleEnemies.Count)]; } else if (possibleEnemies.Count == 1) { pixel = possibleEnemies[0]; } else { return(null); } IPixel pix = (IPixel)Activator.CreateInstance(pixel.GetType()); return(pix); }
/// <summary> /// Create a 2-dimensional line of type T. /// </summary> /// <param name="Pixel1">A pixel of type T.</param> /// <param name="Pixel2">A pixel of type T.</param> public Line2D(IPixel <T> Pixel1, IPixel <T> Pixel2) { #region Initial Checks if (Pixel1 == null) { throw new ArgumentNullException("The given left-coordinate must not be null!"); } if (Pixel2 == null) { throw new ArgumentNullException("The given right-coordinate must not be null!"); } #endregion this.Math = MathsFactory <T> .Instance; this.X1 = Pixel1.X; this.Y1 = Pixel1.Y; this.X2 = Pixel2.X; this.Y2 = Pixel2.Y; this.Pixel1 = Pixel1; this.Pixel2 = Pixel2; this.Length = Pixel1.DistanceTo(Pixel2); }
public void Draw(ICanvas <TPixelData> canvas, Point start, Point end, IPixel <TPixelData> colour) { _logger.LogDebug($"[DrawRectangle] start: {start}, end: {end}, colour: {colour}"); Guard.ThrowIfNull(canvas, nameof(canvas)); Guard.ThrowIfNull(colour, nameof(colour)); canvas.ValidatePointWithinCanvas(start); canvas.ValidatePointWithinCanvas(end); var corners = new[] { start, new Point(start.X, end.Y), end, new Point(end.X, start.Y) }; DrawSide(0, 1); DrawSide(1, 2); DrawSide(2, 3); DrawSide(3, 0); void DrawSide(int cornerIndex1, int cornerIndex2) { _drawStraightLine.Draw(canvas, corners[cornerIndex1], corners[cornerIndex2], colour); } }
public virtual void SetPixel(IPixel <QuantumType> pixel) { if (pixel != null) { SetPixelUnchecked(pixel.X, pixel.Y, pixel.ToArray()); } }
public static ushort GetPixel565(IPixel value) { Rgba32 pixel = new Rgba32(); value.ToRgba32(ref pixel); return(Rgb888toRgb565(pixel.B, pixel.G, pixel.R)); }
public static void Choice(IPixel head, Direction.Movement currentMovement) { switch (currentMovement) { case Direction.Movement.Up: { head.YPosition--; break; } case Direction.Movement.Down: { head.YPosition++; break; } case Direction.Movement.Left: { head.XPosition--; break; } case Direction.Movement.Right: { head.XPosition++; break; } } }
public RGBAb(IPixel pixel) { red = (byte)pixel.Red; green = (byte)pixel.Green; blue = (byte)pixel.Blue; alpha = (byte)pixel.Alpha; }
/// <summary> /// Swaps two pixels. /// </summary> /// <param name="Pixel1">The first pixel.</param> /// <param name="Pixel2">The second pixel.</param> public static void Swap(ref IPixel <T> Pixel1, ref IPixel <T> Pixel2) { var tmp = Pixel2; Pixel2 = Pixel1; Pixel1 = tmp; }
/// <summary> /// Create a circle of type T. /// </summary> /// <param name="Center">The center of the circle.</param> /// <param name="Radius">The radius of the circle.</param> public Circle(IPixel <T> Center, T Radius) { #region Initial Checks if (Center == null) { throw new ArgumentNullException("The given center pixel must not be null!"); } if (Radius == null) { throw new ArgumentNullException("The given radius must not be null!"); } #endregion this.Math = MathsFactory <T> .Instance; #region Math Checks if (Radius.Equals(Math.Zero)) { throw new ArgumentException("The given radius must not be zero!"); } #endregion this.X = Center.X; this.Y = Center.Y; this.Center = Center; this.Radius = Radius; }
/// <summary> /// Write a pixel to the file. Assumes pixels will be written /// by the caller consecutively from upper left to bottom /// right a row at a time /// </summary> public void WritePixel(IPixel pixel) { try { if ((fileWriter == null) || (!this.open)) { throw new System.ApplicationException("Raster not open for writing"); } if (currPixel >= totalPixels) { throw new System.ApplicationException("Writing beyond end of pixel data"); } int bandCount = pixel.BandCount; for (int bandNum = 0; bandNum < bandCount; bandNum++) { IPixelBand band = pixel[bandNum]; // calc this pixelband's location in file int location = PixelBandLocation(currPixel, bandNum); this.fileWriter.Seek(location, SeekOrigin.Begin); this.fileWriter.Write(band.GetBytes()); } currPixel++; } catch (System.Exception) { Close(); throw; } }
public void Print(ICanvas Canvas) { for (int i = 0; i < Canvas.Width + 2; i++) { Output.Write("-"); } Output.WriteLine(); for (int i = 0; i < Canvas.Height; i++) { Output.Write("|"); for (int j = 0; j < Canvas.Width; j++) { IPixel pixel = Canvas.GetPixel(j, i); char color = ' '; if (pixel.Color != 0) { color = Convert.ToChar(pixel.Color); } Output.Write($"{color}"); } Output.Write("|"); Output.WriteLine(); } for (int i = 0; i < Canvas.Width + 2; i++) { Output.Write("-"); } Output.WriteLine(); Output.WriteLine(); }
/// <summary> /// Create a rectangle of type T. /// </summary> /// <param name="Pixel">A pixel of type T in the upper left corner of the rectangle.</param> /// <param name="Width">The width of the rectangle.</param> /// <param name="Height">The height of the rectangle.</param> public Rectangle(IPixel <T> Pixel, T Width, T Height) { #region Initial Checks if (Pixel == null) { throw new ArgumentNullException("The given pixel must not be null!"); } if (Width == null || Width.Equals(Math.Zero)) { throw new ArgumentNullException("The given width must not be null or zero!"); } if (Height == null || Height.Equals(Math.Zero)) { throw new ArgumentNullException("The given height must not be null or zero!"); } #endregion this.Math = MathsFactory <T> .Instance; this.Left = Pixel.X; this.Top = Pixel.Y; this.Right = Math.Add(Pixel.X, Width); this.Bottom = Math.Add(Pixel.Y, Height); this.Pixel1 = new Pixel <T>(Left, Top); this.Pixel2 = new Pixel <T>(Right, Bottom); this.Width = Math.Distance(Left, Right); this.Height = Math.Distance(Top, Bottom); this.Diameter = Pixel1.DistanceTo(Pixel2); }
/// <summary> /// Create a 2-dimensional line of type T. /// </summary> /// <param name="Pixel">A pixel of type T.</param> /// <param name="X">The x-component.</param> /// <param name="Y">The y-component.</param> public Line2D(IPixel <T> Pixel, T X, T Y) { #region Initial Checks if (Pixel == null) { throw new ArgumentNullException("The given pixel must not be null!"); } if (X == null) { throw new ArgumentNullException("The given x-component must not be null!"); } if (Y == null) { throw new ArgumentNullException("The given y-component must not be null!"); } #endregion this.Math = MathsFactory <T> .Instance; this.X1 = Pixel.X; this.Y1 = Pixel.Y; this.X2 = Math.Add(Pixel.X, X); this.Y2 = Math.Add(Pixel.Y, Y); this.Pixel1 = new Pixel <T>(X1, Y1); this.Pixel2 = new Pixel <T>(X2, Y2); this.Length = Pixel1.DistanceTo(Pixel2); }
public int CompareByIntensity(IPixel <byte> another) { if (another == null) { throw new ArgumentNullException("another"); } return(this.Intensity.CompareTo(another.Intensity)); }
public override void SetColour(IPixel <ConsolePixelData> referencePixelBase) { if (referencePixelBase == null) { throw new ArgumentNullException(nameof(referencePixelBase)); } Data.Colour = referencePixelBase.Data.Colour; }
public override bool IsColourMatch(IPixel <ConsolePixelData> referencePixelBase) { if (referencePixelBase == null) { throw new ArgumentNullException(nameof(referencePixelBase)); } return(Data.Colour == referencePixelBase.Data.Colour); }
void IPixel.DrawPixel(IPixel pixel) { SetCursorPosition(pixel.XPosition, pixel.YPosition); ForegroundColor = pixel.ScreenColor; const string Value = "■"; Write(Value); SetCursorPosition(0, 0); }
void IPixel.Score(ref int score, IPixel head, ref IPixel berry) { if (berry.XPosition != head.XPosition || berry.YPosition != head.YPosition) { return; } score++; berry = new Pixel(Randomly.Next(1, WindowWidth - 1), Randomly.Next(1, WindowHeight - 1), ConsoleColor.Cyan); }
/// <summary> /// Compares two pixels for equality. /// </summary> /// <param name="IPixel">A pixel to compare with.</param> /// <returns>True if both match; False otherwise.</returns> public Boolean Equals(IPixel <T> IPixel) { if ((Object)IPixel == null) { return(false); } return(X.Equals(IPixel.X) && Y.Equals(IPixel.Y)); }
private Color(byte r, byte g, byte b) { this.data = new Rgba64( ColorNumerics.UpscaleFrom8BitTo16Bit(r), ColorNumerics.UpscaleFrom8BitTo16Bit(g), ColorNumerics.UpscaleFrom8BitTo16Bit(b), ushort.MaxValue); this.boxedHighPrecisionPixel = null; }
public void SimpleDraw(int x, int y) { int color = (int)('x' - '0'); TestingCanvas.Draw(x, y, color); IPixel ipixel = TestingCanvas.GetPixel(x, y); Assert.Equal(x, ipixel.X); Assert.Equal(y, ipixel.Y); Assert.Equal(color, ipixel.Color); }
public bool Equals(IPixel other) { if (null != (object)other) { return(Red == other.Red && Green == other.Green && Blue == other.Blue); } else { return(false); } }
/// <summary> /// Remove a pixel from the quadtree. /// </summary> /// <param name="Pixel">A pixel of type T.</param> public void Remove(IPixel <T> Pixel) { #region Initial Checks if (Pixel == null) { throw new ArgumentNullException("The given pixel must not be null!"); } #endregion #region Remove embedded voxel EmbeddedPixels.Remove(Pixel); #endregion #region Check subtrees if (Subtree1 != null) { if (Subtree1.Contains(Pixel)) { Subtree1.Remove(Pixel); } } if (Subtree2 != null) { if (Subtree2.Contains(Pixel)) { Subtree2.Remove(Pixel); } } if (Subtree3 != null) { if (Subtree3.Contains(Pixel)) { Subtree3.Remove(Pixel); } } if (Subtree4 != null) { if (Subtree4.Contains(Pixel)) { Subtree4.Remove(Pixel); } } #endregion }
/// <summary> /// Initializes a new instance of the <see cref = "PixelMapping" /> class. /// </summary> /// <param name = "pixel"> /// The pixel. /// </param> /// <exception cref = "ArgumentNullException"> /// </exception> public PixelMapping(IPixel pixel) { if (pixel == null) { throw new ArgumentNullException("pixel"); } this.Pixel = pixel; this.ConvertToEmptyCommand = new RelayCommand(x => this.ConvertToEmpty(), x => this.CanConvertToEmpty()); this.ConvertToSingleCommand = new RelayCommand(x => this.ConvertToSingle(), x => this.CanConvertToSingle()); this.ConvertToRgbCommand = new RelayCommand(x => this.ConvertToRgb(), x => this.CanConvertToRgb()); this.ConvertToRgbwCommand = new RelayCommand(x => this.ConvertToRgbw(), x => this.CanConvertToRgbw()); }
public static byte ToColorBucket(this IPixel color) { if (color is Rgb24 rgbColor) { return(ToColorBucket(rgbColor)); } if (color is Rgba32 rgbaColor) { return(ToColorBucket(rgbaColor)); } throw new NotSupportedException($"Format {color.GetType().Name} is not supported"); }
public Canvas(int width, int height, IPixel <TPixelData> defaultPixel) { Width = width; Height = height; Area = new IPixel <TPixelData> [width, height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { Area[x, y] = defaultPixel.Clone(); } } }
public override void Draw(int x, int y, IPixel pixel = null) { if (pixel == null) { pixel = new ConsolePixel(); } var p = pixel as ConsolePixel; if (x >= 0 && x < ScreenWidth && y >= 0 && y < ScreenHeight) { bufScreen[y * ScreenWidth + x].UnicodeChar = p.PIXEL_TYPE; bufScreen[y * ScreenWidth + x].Attributes = p.COLOUR; } }
public static IPixelMap CreateInitVerifyPixelMap(int width, int height, IPixel color) { IPixelMap map = CreateVerifyPixelMap(); map.Init(height, width, color); Assert.Equal(width, map.Width); Assert.Equal(height, map.Height); Assert.Equal <IPixel>(color, map.CreateGPixelReference(width / 2).ToPixel()); var pix = map.CreateGPixelReference(width / 2); Assert.True(color.Equals(pix.ToPixel())); return(map); }
public void Update(IPixel p) { var pixelExists = Pixels.FirstOrDefault(f => f.X == p.X && f.Y == p.Y); if (pixelExists == null) { Pixels.Add(p); } else { var i = Pixels.IndexOf(pixelExists); Pixels[i] = p; } }
/// <summary> /// Checks if the given pixel is located /// within the given rectangle. /// </summary> /// <param name="Pixel">A pixel of type T.</param> /// <param name="Pixel1">The left/top pixel of the rectangle.</param> /// <param name="Pixel2">The right/bottom pixel of the rectangle.</param> /// <returns>True if the pixel is located within the given rectangle; False otherwise.</returns> public static Boolean IsInRectangle <T>(this IPixel <T> Pixel, IPixel <T> Pixel1, IPixel <T> Pixel2) where T : IEquatable <T>, IComparable <T>, IComparable { #region Initial Checks if (Pixel == null) { throw new ArgumentNullException("The given pixel must not be null!"); } #endregion return(new Rectangle <T>(Pixel1, Pixel2).Contains(Pixel)); }
/// <summary> /// Write a pixel to the file. Assumes pixels will be written /// by the caller consecutively from upper left to bottom /// right a row at a time /// </summary> public void WritePixel(IPixel pixel) { int bandCount = pixel.BandCount; for (int bandNum = 0; bandNum < bandCount; bandNum++) { IPixelBand band = pixel[bandNum]; // calc this pixelband's location in file int location = PixelBandLocation(this.pixelsWritten,bandNum); this.fileWriter.Seek(location,SeekOrigin.Begin); this.fileWriter.Write(band.GetBytes()); } this.pixelsWritten++; }
public virtual void SetPixel(int x, int y, IPixel pel) { // If the pixel types match, then PixelInformation pelInfo = new PixelInformation(pel.Layout, pel.ComponentType); if (PixRectInfo.GetPixelInformation().Equals(pelInfo)) { // Find the byte offset for the pixel IntPtr pixelPtr = GetPixelPointer(x, y); // copy the color bytes into the array Marshal.Copy(pel.GetBytes(), 0, pixelPtr, pel.GetBytes().Length); return; } // If the pixel types don't match, then we have to go through // color instead of just copying the pixel directly. SetColor(x, y, Pixel.GetColor(pelInfo, pel.GetBytes())); }
/// <summary> /// Read a pixel from the file. Assumes pixels will be read /// by the caller consecutively from upper left to bottom /// right a row at a time /// </summary> public void ReadPixel(IPixel pixel) { int bandCount = pixel.BandCount; for (int bandNum = 0; bandNum < bandCount; bandNum++) { IPixelBand band = pixel[bandNum]; // calc this pixelband's location in file int location = PixelBandLocation(pixelsRead,bandNum); // seek to correct pixel spot this.fileReader.BaseStream.Seek(location,SeekOrigin.Begin); byte[] bytes = this.fileReader.ReadBytes(this.BandSize); band.SetBytes(bytes,0); } pixelsRead++; }
/// <summary> /// Write a pixel to the file. Assumes pixels will be written /// by the caller consecutively from upper left to bottom /// right a row at a time /// </summary> public void WritePixel(IPixel pixel) { try { if ((fileWriter == null) || (!this.open)) throw new System.ApplicationException("Raster not open for writing"); if (currPixel >= totalPixels) throw new System.ApplicationException("Writing beyond end of pixel data"); int bandCount = pixel.BandCount; for (int bandNum = 0; bandNum < bandCount; bandNum++) { IPixelBand band = pixel[bandNum]; // calc this pixelband's location in file int location = PixelBandLocation(currPixel,bandNum); this.fileWriter.Seek(location,SeekOrigin.Begin); this.fileWriter.Write(band.GetBytes()); } currPixel++; } catch (System.Exception) { Close(); throw; } }
/// <summary> /// Read a pixel from the file. Assumes pixels will be read /// by the caller consecutively from upper left to bottom /// right a row at a time /// </summary> public void ReadPixel(IPixel pixel) { try { if ((fileReader == null) || (!this.open)) throw new System.ApplicationException("Raster not open for reading"); if (currPixel >= totalPixels) throw new System.ApplicationException("Reading beyond end of pixel data"); int bandCount = pixel.BandCount; for (int bandNum = 0; bandNum < bandCount; bandNum++) { IPixelBand band = pixel[bandNum]; // calc this pixelband's location in file int location = PixelBandLocation(currPixel,bandNum); // seek to correct pixel spot this.fileReader.BaseStream.Seek(location,SeekOrigin.Begin); byte[] bytes = this.fileReader.ReadBytes(bandSize); band.SetBytes(bytes,0); } currPixel++; } catch (System.Exception) { Close(); throw; } }
public override void SetPixel(int x, int y, IPixel aPixel) { Accessor.SetPixel(x, y, aPixel); }
public Pixel(IPixel pel) { Layout = pel.Layout; ComponentType = pel.ComponentType; SetColor(pel.GetColor()); }
public virtual void SetPixel(int x, int y, IPixel pixel) { throw new NotImplementedException("GDIPixmap::SetPixel"); }
/// <summary> /// The convert to rgbw. /// </summary> private void ConvertToRgbw() { this.Pixel = new RedGreenBlueWhitePixel(null, null, null, null); }
/// <summary> /// The convert to empty. /// </summary> private void ConvertToEmpty() { this.Pixel = new EmptyPixel(); }
/// <summary> /// The convert to single. /// </summary> private void ConvertToSingle() { this.Pixel = new SingleColorPixel(null, Colors.White); }
public void Visit(IPixel pixel) { charPixelCounter++; }