protected sealed override GameObject[,] CreatePixels(PixelDescription[,] pixelsDescription) { var pixels = new GameObject[(int)PixelsCount.X, (int)PixelsCount.Y]; for (int x = 0; x < PixelsCount.X; x++) { for (int y = 0; y < PixelsCount.Y; y++) { var pixelDescribtion = pixelsDescription[x, y]; if (pixelDescribtion == null) { continue; } var pixelIndex = new Vector2(x, y); CollisionPixel pixel; pixels[x, y] = pixel = new CollisionPixel(Level, _world, PixelMath.PixelToGamePosition(pixelIndex, PixelsCount), PixelOptions.PixelSize); PixelCreated(pixel); // Change pixels color according to description. pixel.ColorChanger.ResetColor(pixelDescribtion.Color); ConnectNeighbours(pixels, pixel, x, y); SetNeighbourBorders(pixel, x, y); } } return(pixels); }
public static Vector2 GetMiddlePosition(Vector2 leftTopIndexPosition, Vector2 basicSize, Vector2 pixelsCountInMap) { var result = PixelMath.PixelToGamePosition(leftTopIndexPosition, pixelsCountInMap) + basicSize / 2f - PixelOptions.PixelSize; return(result); }
protected override GameObject[,] CreatePixels(PixelDescription[,] pixelsDescription) { SimplePixel[,] pixels = new SimplePixel[(int)PixelsCount.X, (int)PixelsCount.Y]; for (int x = 0; x < PixelsCount.X; x++) { for (int y = 0; y < PixelsCount.Y; y++) { PixelDescription pixelDescribtion = pixelsDescription[x, y]; if (pixelDescribtion == null) { continue; } //if ((x % 2 == 0 && y % 2 == 0) || (x % 2 == 1 && y % 2 == 1)) pixelDescribtion = new PixelDescribtion(Color.Aqua); Vector2 pixelIndex = new Vector2(x, y); SimplePixel pixel = pixels[x, y] = new SimplePixel(Level, PixelMath.PixelToGamePosition(pixelIndex, PixelsCount), PixelOptions.PixelSize); // Change pixels color according to description. pixel.ColorChanger.ResetColor(pixelDescribtion.Color); } } return(pixels); }
private void Init() { PMath = new PixelMath(TB_Function.Text); XNADevices.graphicsdevice = new GraphicsDevice( GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, new PresentationParameters() { BackBufferHeight = PN_Graph.Height, BackBufferWidth = PN_Graph.Width, IsFullScreen = false, DeviceWindowHandle = PN_Graph.Handle } ); Batch = new SpriteBatch(XNADevices.graphicsdevice); }
public static Color[] Rough(int w, int h, Color color) { var pixels = None(w, h, color); WhiteNoise.SetFrequency(0.25f); WhiteNoise.SetFractalOctaves(2); WhiteNoise.SetFractalType(FractalType.Billow); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { var val = WhiteNoise.GetSimplexFractal(x, y); var multi = PixelMath.Map(val, -1, 1, 0, 1); pixels[(y * w) + x].A = (byte)(pixels[(y * w) + x].A * multi); } } return(pixels); }
private CvImage DrawCannyEdges(Bitmap sobel_x, Bitmap sobel_y) { CvImage image = new CvImage(); int[,] edge_direction = new int[sobel_x.Width, sobel_x.Height]; int[,] edge_mag = new int[sobel_x.Width, sobel_x.Height]; int[,] non_max = new int[sobel_x.Width, sobel_x.Height]; int kernWid = GAUSSIAN_FILTER.MATRIX.GetLength(1); int kernHei = GAUSSIAN_FILTER.MATRIX.GetLength(0); int kernOffset = (kernWid - 1) / 2; for (int wid_ic = kernOffset; wid_ic < sobel_x.Width - kernOffset; wid_ic++) { for (int hei_ic = kernOffset; hei_ic < sobel_x.Height - kernOffset; hei_ic++) { var pixel_y = sobel_y.GetPixel(wid_ic, hei_ic); var pixel_x = sobel_x.GetPixel(wid_ic, hei_ic); var mag_y = PixelMath.pixelMag(pixel_y); var mag_x = PixelMath.pixelMag(pixel_y); var edge_strength = mag_y + mag_x; edge_mag[wid_ic, hei_ic] = (int)edge_strength; non_max[wid_ic, hei_ic] = (int)edge_strength; } } for (int wid_ic = kernWid; wid_ic < sobel_x.Width - kernWid; wid_ic++) { for (int hei_ic = kernHei; hei_ic < sobel_x.Height - kernHei; hei_ic++) { var pixel_y = sobel_y.GetPixel(wid_ic, hei_ic); var pixel_x = sobel_x.GetPixel(wid_ic, hei_ic); var mag_y = PixelMath.pixelMag(pixel_y); var mag_x = PixelMath.pixelMag(pixel_y); var current_mag = edge_mag[wid_ic, hei_ic]; double theta = current_mag != 0 ? Math.Atan2(mag_y, mag_x) : 90; //CHO_ACTIVE: clean this up //near horizontal if ((theta > -22.5 && theta <= 22.5) || (theta > 157.5) || (theta < -157.5)) { if ((current_mag < edge_mag[wid_ic, hei_ic + 1]) || (current_mag < edge_mag[wid_ic, hei_ic - 1])) { non_max[wid_ic, hei_ic] = 0; } } // +45 degree else if ((theta > 22.5 && theta <= 67.5) || (theta <= -67.5 && theta > -22.5)) { if ((current_mag < edge_mag[wid_ic + 1, hei_ic + 1]) || (current_mag < edge_mag[wid_ic - 1, hei_ic - 1])) { non_max[wid_ic, hei_ic] = 0; } } //vertical else if ((theta > 67.5 && theta <= 112.5) || (theta <= -67.5 && theta > -112.5)) { if ((current_mag < edge_mag[wid_ic + 1, hei_ic]) || (current_mag < edge_mag[wid_ic - 1, hei_ic])) { non_max[wid_ic, hei_ic] = 0; } } // +135 degree else { if ((current_mag < edge_mag[wid_ic + 1, hei_ic - 1]) || (current_mag < edge_mag[wid_ic - 1, hei_ic + 1])) { non_max[wid_ic, hei_ic] = 0; } } edge_direction[wid_ic, hei_ic] = (int)theta; } } image.bitmap = TraceCannyEdge(non_max); return(image); }
public static Vector2 GetLeftTopIndexPosition(Vector2 basicPosition, Vector2 basicSize) { return(PixelMath.GameToPixelPosition(basicPosition - basicSize / 2f + PixelOptions.PixelSize / 2, MenuScreenManager.GetScreen <ScreenLevelCreator>().MapSize)); }
public void SetMathAlgo(String xAlgo, String yAlgo) { PMathX = new PixelMath(xAlgo); PMathY = new PixelMath(yAlgo); }
private void BTN_MathLoad_Click(object sender, EventArgs e) { PMath = new PixelMath(TB_Function.Text); }
protected override Vector2 DragValueModify(Vector2 value) { return(PixelMath.GameToStrictPixelVector(value) * PixelOptions.PixelSize); }