Bitmap generateImage() { Bitmap bitmap = new Bitmap(initialSize.Width, initialSize.Height); for (int i = 0; i < initialSize.Width; i++) { for (int j = 0; j < initialSize.Height; j++) { RGB currentPixel = ColorConversions.toRGB(lines[i].Colors[j]); bitmap.SetPixel(i, j, System.Drawing.Color.FromArgb(255, currentPixel.R, currentPixel.G, currentPixel.B)); } } return(bitmap); }
void initialize(InitType init) { for (int i = 0; i < initialSize.Width; i++) { lines[i] = new ColorLine(initialSize.Height, rand, init); for (int j = 0; j < initialSize.Height; j++) { RGB currentPixel = ColorConversions.toRGB(lines[i].Colors[j]); colorImage.SetPixel(i, j, System.Drawing.Color.FromArgb(255, currentPixel.R, currentPixel.G, currentPixel.B)); } } gfx.InterpolationMode = InterpolationMode.NearestNeighbor; gfx.DrawImage(colorImage, new Rectangle(Point.Empty, pictureBox1.Size)); pictureBox1.Image = canvas; }
void updateLineSwap() { if (sorted) { return; } for (int i = 0; i < initialSize.Width; i++) { RGB pixelA = ColorConversions.toRGB(lines[i].Colors[bubbleHeight]); RGB pixelB = ColorConversions.toRGB(lines[i].Colors[bubbleHeight - 1]); colorImage.SetPixel(i, bubbleHeight, System.Drawing.Color.FromArgb(255, pixelA.R, pixelA.G, pixelA.B)); colorImage.SetPixel(i, bubbleHeight - 1, System.Drawing.Color.FromArgb(255, pixelB.R, pixelB.G, pixelB.B)); } }
public Form1() { InitializeComponent(); sorts = new Func <bool>[] { bubbleSort, quickSort, () => { return(false); } }; currentSort = Sorts.NONE; sorted = false; //sort variables bubbleHeight = 1; bubbleWidth = 0; makeSwap = false; swaps = new Queue <int[]>(); rand = new Random(); canvas = new Bitmap(pictureBox1.Width, pictureBox1.Height); gfx = Graphics.FromImage(canvas); initialSize = new Size(128, 64); colorImage = new Bitmap(initialSize.Width, initialSize.Height); lines = new ColorLine[initialSize.Width]; gfx.InterpolationMode = InterpolationMode.NearestNeighbor; gfx.PixelOffsetMode = PixelOffsetMode.Half; for (int i = 0; i < initialSize.Width; i++) { lines[i] = new ColorLine(initialSize.Height, rand, InitType.UNLIMITED); for (int j = 0; j < initialSize.Height; j++) { RGB currentPixel = ColorConversions.toRGB(lines[i].Colors[j]); colorImage.SetPixel(i, j, System.Drawing.Color.FromArgb(255, currentPixel.R, currentPixel.G, currentPixel.B)); } } gfx.DrawImage(colorImage, new Rectangle(Point.Empty, pictureBox1.Size)); pictureBox1.Image = canvas; }