}//End of Node(Node, Colour[,], int[], Colour, int) //Functions public void PopulateChildren() { Colour playerTurn; if (turn == Colour.black) { playerTurn = Colour.white; } else { playerTurn = Colour.black; } Colour[,] tempBoard = CloneTokens(tokens); List <Tuple <int, int> > tokensToKill = TokensToKill(playerTurn); int fieldCheck; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (tokens[i, j] == Colour.none) { fieldCheck = CheckField(i, j, playerTurn); if (fieldCheck != 0) { children.Add(new Node(this, tempBoard, new int[2] { i, j }, playerTurn, fieldCheck)); } } } } }//End of PopulateChildren()
}//End of Node() public Node(Node parent, Colour[,] tokens, int[] move, Colour turn, int moveValue) { this.parent = parent; this.tokens = tokens; this.move[0] = move[0]; this.move[1] = move[1]; this.turn = turn; this.children = new List <Node>(); this.moveValue = moveValue; }//End of Node(Node, Colour[,], int[], Colour, int)
public Renderer(Vector3 _cameraLocation, int _screenWidth, int _screenHeight, int _fov, Scene _scene) { cameraLocation = _cameraLocation; screenWidth = _screenWidth; screenHeight = _screenHeight; fov = (float)Math.Tan((_fov * 3.14 / 180) / 2); imageAspectRatio = (float)screenWidth / (float)screenHeight; pixelArray = new Colour[_screenWidth, _screenHeight]; scene = _scene; scene.cameraLocation = cameraLocation; }
}//End of PopulateChildren() public Colour[,] CloneTokens(Colour[,] other) { Colour[,] newTokens = new Colour[8, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { newTokens[i, j] = other[i, j]; } } return(newTokens); }//End of CloneTokens()
public void Render(Colour[,] arr) { SDL.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL.SDL_RenderClear(renderer); for (int x = 0; x < 500; x++) { for (int y = 0; y < 500; y++) { SDL.SDL_SetRenderDrawColor(renderer, Convert.ToByte(arr[x, y].r), Convert.ToByte(arr[x, y].g), Convert.ToByte(arr[x, y].b), 255); SDL.SDL_RenderDrawPoint(renderer, 499 - x, 499 - y); } } SDL.SDL_RenderPresent(renderer); }
private void read() { m = Convert.ToInt32(Console.ReadLine()); n = Convert.ToInt32(Console.ReadLine()); k = Convert.ToInt32(Console.ReadLine()); field = new Colour[n, m]; neededFields = new int[n]; for (int i = 0; i < n; ++i) { neededFields[i] = m; } random = new Random(k); curSeq = new bool[n, m]; }
/* ------------------------------------------------------------------- * CONSTRUCTOR * * Creates a new quadtree from given image stored in 2D array. * ------------------------------------------------------------------- */ public Quadtree(Colour[,] img) { if (img.Length < 1) // original image is empty { root = new Node(); return; } if (img.Length == 1) // original image is 1x1 { root = new Node(img[0, 0], null, 1); return; } // else, recursively construct the tree root = Construct(img, Colour.GRAY, null); }
public void SetPixels(Colour[,] pixels) { if (pixels.Length != PixelCount) { throw new Exception("Pixel array length must match bitmap pixel array length."); } if (pixels.GetLength(0) != Width || pixels.GetLength(1) != Height) { throw new Exception("Pixel array dimensions must match bitmap dimensions."); } Colour[] _pixels = new Colour[Width * Height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { _pixels[Width * y + x] = pixels[x, y]; } } this.pixels = _pixels; }
/* ------------------------------------------------------------------- * FUNCTION: Compare * * Compares an image (stored in 2d matrix) to the quadtree. * RETURNS: true if both images are identical, false otherwise. * * Time Complexity: O(n), n = number of entries in matrix * ------------------------------------------------------------------- */ public bool Compare(Colour[,] img) { if ((int)Math.Sqrt(img.Length) != root.size) { return(false); // images are different sizes } bool result = true; int s = root.size; char[,] M = new char[s, s]; if (s > 0) { Traverse(M, 0, 0, root); } for (int i = 0; i < s; ++i) { for (int j = 0; j < s; ++j) { switch (img[i, j]) { case Colour.WHITE: if (M[i, j] != 'W') { result = false; } break; default: if (M[i, j] != 'B') { result = false; } break; } } } return(result); }
private List <Colour[]> listOfColourTypes; //facilitates automatic population of array public void Initialise(GameState state) { arrayOfColours = new Colour[(int)ColourType.Count, (int)ColourScheme.Count]; //add each array of Colours into the List -> NOTE: change this whenever you add, or modify, a colour. //Note: KEEP IN SAME ORDER AS ColourType enum listOfColourTypes = new List <Colour[]>() { dataGood, dataNeutral, dataBad, dataTerrible, normalText, goodText, neutralText, badText, blueText, salmonText, moccasinText, greyText, whiteText, blackText }; //loop thorugh list and auto populate array int limit; for (int i = 0; i < listOfColourTypes.Count; i++) { Colour[] tempArray = listOfColourTypes[i]; //loop limit is the smallest of tempArray or # of ColourSchemes limit = Mathf.Min((int)ColourScheme.Count, tempArray.Length); for (int j = 0; j < limit; j++) { arrayOfColours[i, j] = tempArray[j]; } } }
/// <summary> /// 根据数组设置图形网格集合(适用于单宽与双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="strs">字符串</param> /// <param name="foreColors">前景色</param> /// <param name="backColors">背景色</param> public void SetGridByArray2D(Vector2 position, string[,] strs, Colour[,] foreColors, Colour[,] backColors) { for (int i = 0; i < strs.GetLength(0); i++) { for (int j = 0; j < strs.GetLength(1); j++) { Vector2 pos = new Vector2(position.X + j, position.Y + i); string str = strs[i, j]; Colour foreColor = foreColors[i, j]; Colour backColor = backColors[i, j]; if (str.Length == 1) { SetGrid(pos, new CharInfo(str[0], foreColor, backColor)); } else if (str.Length == 2) { SetGrid(pos, new CharInfo(str[0], foreColor, backColor), new CharInfo(str[1], foreColor, backColor)); } } } }
/* ------------------------------------------------------------------- * PARAMETERS: * img - image to be built into tree * c - colour of above image * p - parent node * ------------------------------------------------------------------- */ private Node Construct(Colour[,] img, Colour c, Node p) { int s = (int)Math.Sqrt(img.Length); Node n = new Node(c, p, s); if (c != Colour.GRAY) // if all one colour, no need to split { return(n); } // else, split into four Colour[,] temp = new Colour[s / 2, s / 2]; // NW quad c = img[0, 0]; for (int i = 0; i < s / 2; ++i) { for (int j = 0; j < s / 2; ++j) { temp[i, j] = img[i, j]; if (img[i, j] != c) { c = Colour.GRAY; } } } n.nw = Construct(temp, c, n); // NE quad c = img[0, s / 2]; for (int i = 0; i < s / 2; ++i) { for (int j = s / 2; j < s; ++j) { temp[i, j - (s / 2)] = img[i, j]; if (img[i, j] != c) { c = Colour.GRAY; } } } n.ne = Construct(temp, c, n); // SW quad c = img[s / 2, 0]; for (int i = s / 2; i < s; ++i) { for (int j = 0; j < s / 2; ++j) { temp[i - (s / 2), j] = img[i, j]; if (img[i, j] != c) { c = Colour.GRAY; } } } n.sw = Construct(temp, c, n); // SE quad c = img[s / 2, s / 2]; for (int i = s / 2; i < s; ++i) { for (int j = s / 2; j < s; ++j) { temp[i - (s / 2), j - (s / 2)] = img[i, j]; if (img[i, j] != c) { c = Colour.GRAY; } } } n.se = Construct(temp, c, n); Compress(n.nw); // compress starting from any child return(n); }
/// <summary> /// Create a new sampler /// </summary> /// <param name="colours">colours to sample in row,column format</param> public MatrixColourSampler(Colour[,] colours) { this.colours = colours; }
/// <summary> /// Create a colour sampler for a 2d array of colours /// </summary> /// <param name="colours">the colour array</param> /// <returns>colour sampler for this array</returns> public static IColourSampler GetSampler(this Colour[,] colours) { return(new MatrixColourSampler(colours)); }
public void SetImage(Colour[,] img) { image = img; }
public Exporter(int w, int h) { width = w; height = h; image = new Colour[w, h]; }
public static void Main(string[] args) { Colour[,] img = new Colour[8, 8] { // rows x columns { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.BLACK, Colour.BLACK, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.BLACK, Colour.BLACK, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.BLACK, Colour.BLACK, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.BLACK, Colour.BLACK }, { Colour.BLACK, Colour.BLACK, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.BLACK, Colour.WHITE }, }; Colour[,] img1 = new Colour[1, 1] { { Colour.WHITE } }; Colour[,] img2 = new Colour[2, 2] { { Colour.WHITE, Colour.BLACK }, { Colour.BLACK, Colour.WHITE } }; Colour[,] img7 = new Colour[2, 2] { { Colour.BLACK, Colour.BLACK }, { Colour.WHITE, Colour.BLACK } }; Colour[,] img3 = new Colour[4, 4] { { Colour.BLACK, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.BLACK, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.BLACK } }; Colour[,] img4 = new Colour[4, 4] { { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE }, { Colour.WHITE, Colour.WHITE, Colour.WHITE, Colour.WHITE } }; Colour[,] img5 = new Colour[0, 0]; Colour[,] img6 = new Colour[1024, 1024]; for (int i = 0; i < 1024; ++i) // adds values into img6 { for (int j = 0; j < 1024; ++j) { if (i % 2 == 0 && j % 2 == 0) { img6[i, j] = Colour.BLACK; } else { img6[i, j] = Colour.WHITE; } } } Colour[,] test = img6; // change this to test different images // (NOTE: not used for union test) Quadtree T = new Quadtree(test); /* ---------------------------------------------------------------- * CONSTRUCTOR & PRINT TEST * ---------------------------------------------------------------- */ Console.WriteLine("\nOriginal Image:\n"); int s = (int)Math.Sqrt(test.Length); if (s < 17) // print original image as above { for (int i = 0; i < s; ++i) { for (int j = 0; j < s; ++j) { switch (test[i, j]) { case Colour.WHITE: Console.Write("W "); break; default: Console.Write("B "); break; } } Console.Write("\n"); } } else { Console.WriteLine(s + "x" + s + " - too large to print"); } Console.WriteLine("\nQuadtree:\n"); // print quadtree if (s < 17) { T.Print(); } if (T.Compare(test)) // compare matrix to tree { Console.WriteLine("\nThe images are identical.\n"); } else { Console.WriteLine("\nThe images are different - something went wrong?\n"); } /* ---------------------------------------------------------------- * SWITCH TEST * ---------------------------------------------------------------- */ T.Switch(100, 100); Console.WriteLine("\nAfter Switch:\n"); if (s < 17) { T.Print(); } else { if (T.Compare(test)) { Console.WriteLine("\nSwitch was unsuccessful :(\n"); } else { Console.WriteLine("\nLooks good so far - images are different\n"); if (test[100, 100] == Colour.BLACK) { test[100, 100] = Colour.WHITE; } else { test[100, 100] = Colour.BLACK; } if (T.Compare(test)) { Console.WriteLine("\nSwitch was successful :)\n"); } else { Console.WriteLine("\nSwitch was unsuccessful :(\n"); } } } /* ---------------------------------------------------------------- * UNION TEST * ---------------------------------------------------------------- */ Quadtree T1 = new Quadtree(img3); // Tree 1 Quadtree T2 = new Quadtree(img2); // Tree 2 Quadtree T3 = Quadtree.Union(T1, T2); // Tree 1 U 2 Console.WriteLine("\n\nUnion Test:"); Console.WriteLine("\nTree 1:"); T1.Print(); Console.WriteLine("\nTree 2:"); T2.Print(); Console.WriteLine("\nUnion:"); T3.Print(); Console.Read(); }
/// <summary> /// 根据数组创建图形网格集合(适用于单宽与双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="strs">字符串数组</param> /// <param name="foreColors">前景色数组</param> /// <param name="backColors">背景色数组</param> /// <param name="depth">深度</param> /// <returns>图形网格集合</returns> public List <GraphicGrid> CreatGridByArray2D(Vector2 position, string[,] strs, Colour[,] foreColors, Colour[,] backColors, uint depth = 0) { List <GraphicGrid> graphicGrids = new List <GraphicGrid>(); for (int i = 0; i < strs.GetLength(0); i++) { for (int j = 0; j < strs.GetLength(1); j++) { GraphicGrid graphicGrid = null; Vector2 pos = new Vector2(position.X + j, position.Y + i); string str = strs[i, j]; Colour foreColor = foreColors[i, j]; Colour backColor = backColors[i, j]; if (str.Length == 1) { graphicGrid = CreatGrid(pos, new CharInfo(str[0], foreColor, backColor), depth); } else if (str.Length == 2) { graphicGrid = CreatGrid ( pos, new CharInfo(str[0], foreColor, backColor), new CharInfo(str[1], foreColor, backColor), depth ); } graphicGrids.Add(graphicGrid); } } return(graphicGrids); }
public Bitmap(Colour[,] pixels) : this(pixels.GetLength(0), pixels.GetLength(1)) { SetPixels(pixels); }
public Image(int width, int height, Colour fillcol) { _image = new Colour[width, height]; this.Fill(fillcol); }