static int DrawToBitmap(ref TBitmap bm, BitmapPoint pt, Color color) { int x = pt.x; int y = pt.y; bm.values[x + (y * (bm.Width-1))].R = (byte)color.R; bm.values[x + (y * (bm.Width-1))].G = (byte)color.G; bm.values[x + (y * (bm.Width-1))].B = (byte)color.B; bm.values[x + (y * (bm.Width-1))].A = (byte)color.A; bm.values[x + (y * (bm.Width-1))].point = pt; return 1; }
public RandomWalk(int maxFileSize, bool populateSpace = false, bool createBitmap = false, BitmapPoint? startingPoint = null, string bitmapFilePath = null) { int numberDrawn = 0; if (bitmapFilePath == null) _filePath = @"C:\Users\kylan_000\Desktop\Test Projects\Random Bitmaps\RandomArt.2013\WithPointers\"; else _filePath = bitmapFilePath; _space = new Space(); Random randomW = new Random(); //Random randomC = new Random(); Random rr = new Random(); Random rg = new Random(); Random rb = new Random(); Random random = new Random(); Random randomR = new Random(); Random randomG = new Random(); Random randomB = new Random(); Random pc = new Random(); Random myRandom = new Random(); //int LineLength = 1; //int FileSize = 10000000; //in bytes int x = (int)Math.Truncate(Math.Sqrt(maxFileSize / 36)) + 1; int Width = 4 * x; // Screen.GetBounds(new Point(5, 5)).Width; int Height = 3 * x; //Screen.GetBounds( new Point(5,5) ).Height; Random pick = new Random(); Console.WriteLine("Setting up data structure..."); if (createBitmap) { _tBitmap = new TBitmap(Width, Height); Console.WriteLine("Initializing bitmap..."); for (int k = 0; k < _tBitmap.values.Length; k++) { _tBitmap.values[k].R = (byte)0; _tBitmap.values[k].G = (byte)0; _tBitmap.values[k].B = (byte)0; _tBitmap.values[k].A = (byte)0; } } int i; int randomNumber; randomNumber = random.Next(0, 255); //for (int g = 1; g < 10; g++) //{ BitmapPoint ptStart = startingPoint == null ? new BitmapPoint(random.Next(Width), random.Next(Height)) : new BitmapPoint(((BitmapPoint)startingPoint).x,((BitmapPoint)startingPoint).y); double rnd; rnd = pc.Next(0, 8); int PenCase = 4; Color startColor = Color.FromArgb(random.Next(0,255),random.Next(0,255),random.Next(0,255)); BitmapPoint ptEnd = new BitmapPoint(0, 0); Random randomC = new Random(); int iMax = (int)Math.Truncate(Math.Pow(maxFileSize, 0.9)); Console.WriteLine("Generating random walk..."); for (i = 1; i < iMax; i++) //do { //IntPoint[] pts = new IntPoint[2]; int c; Color endColor = new Color(); switch (PenCase) { case 1: { //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); //ptEnd.Offset(random.Next(-(LineLength), LineLength + 1), random.Next(-(LineLength), LineLength + 1)); break; } case 2: { //black //pn.Width = randomW.Next(0, 5); //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 3: { //all colors, random line width between 0 and 5 px endColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 4: { //all colors, thinnest line width ptEnd = GetNextPoint(new Point(ptStart.x, ptStart.y), random, Width, Height); endColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); //endColor = Blend(startColor, GetPixelColor(ptEnd, tBm), random); if(createBitmap) numberDrawn += DrawToBitmap(ref _tBitmap, ptEnd, endColor); ptStart.x = ptEnd.x; ptStart.y = ptEnd.y; break; } case 5: { //greyscale c = randomC.Next(0, 255); //pn.Color = System.Drawing.Color.FromArgb(c, c, c); //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 6: { //white //pn.Color = System.Drawing.Color.White; //ptEnd.X = ptStart.X; //ptEnd.Y = ptStart.Y; //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 7: { //black thinnest line width //pn.Width = 1; //ptEnd.X = ptStart.X; //ptEnd.Y = ptStart.Y; //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } case 8: //all colors, wider line width { //pn.Color = System.Drawing.Color.FromArgb( rr.Next(redBottom, redTop), rr.Next(greenBottom, greenCenter), rr.Next(blueBottom, blueTop) ); //pn.Width = randomW.Next(0, 50); //ptEnd.X = ptStart.X; //ptEnd.Y = ptStart.Y; //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } default: { //ptEnd.X = ptStart.X; //ptEnd.Y = ptStart.Y; //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height); break; } } //end switch if (populateSpace) { _space.Add(new BitmapPoint(ptEnd.x, ptEnd.y)); _size++; } } //} if(createBitmap) WriteDataToStandardBitmap(ref _tBitmap); }
private static Color GetPixelColor(BitmapPoint ptEnd, TBitmap bm) { return Color.FromArgb(bm.values[ptEnd.x + ptEnd.y * bm.Height].R, bm.values[ptEnd.x + ptEnd.y * bm.Height].G, bm.values[ptEnd.x + ptEnd.y * bm.Height].B); }