private static Color GetPixelColor(IntPoint ptEnd, Bitmap bm)
        {

            System.Drawing.Imaging.BitmapData bpData =
                bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
                bm.PixelFormat);

            byte[] rgbValues = new byte[4]; //just need to store a single pixel (r,g,b)

            //int thisPixel = ptEnd.x * 3 + ptEnd.y * bpData.Stride;

            IntPtr px = bpData.Scan0;

            System.Runtime.InteropServices.Marshal.Copy(px, rgbValues, 0, 4);// + (int)bmpData.Scan0.ToInt64();
                                                                                    //returns the position of the R byte of the
                                                                                    //pixel corresponding to ptEnd
            byte R = rgbValues[1];

            byte G = rgbValues[2];

            byte B = rgbValues[3];

            //System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, px, 3);

            //System.Runtime.InteropServices.Marshal.Release(px);

            rgbValues = null;

            px = IntPtr.Zero;

            bm.UnlockBits(bpData);

            bpData = null;

            return Color.FromArgb(R, G, B);
        }
        private static void DrawToBitmap(IntPoint ptEnd, Color endColor, Bitmap bm)
        {

            System.Drawing.Imaging.BitmapData bpData =
                bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
                bm.PixelFormat);

            byte[] rgbValues = new byte[4]; //just need to store a single pixel (r,g,b)

            int thisPixel = ptEnd.x  + ptEnd.y ;

            IntPtr px = bpData.Scan0 + thisPixel;

            System.Runtime.InteropServices.Marshal.Copy(px, rgbValues, 0, 4);

            if( rgbValues[0] != (byte)1 )
            {
            rgbValues[0] = (byte)1;
            
            rgbValues[1] = (byte)endColor.R;

            rgbValues[2] = (byte)endColor.G;

            rgbValues[3] = (byte)endColor.B;
            }

            System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, px, 4);

            bm.UnlockBits(bpData);

            bpData = null;

        }
        private static IntPoint GetNextPoint(IntPoint ptStart, Random rnd, int width, int height)
        {
            //MUST HANDLE CASE WHERE X OFFSET GOES TO ANOTHER LINE OR TO TOP OR BOTTOM OF BITMAP

            int X = ptStart.x;

            int Y = ptStart.y;

            X = X + rnd.Next(-1, 2);

            Y = Y + rnd.Next(-1, 2);

            while (X < 0 | X > width)
            {
                X = X < 0 ? X + 1 : X - 1; ;
            }

            while (Y < 0 | Y > height)
            {
                Y = Y < 0 ? Y + 1: Y - 1;
            }

            return new IntPoint(X, Y);
        }
        static void Main()
        {

            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 = 1000000; //in bytes

            int x = (int)Math.Truncate(Math.Sqrt(FileSize / 36));

            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();

            //for (int g = 1; g < 20; g++)
            //{

                Color overlayColor = new Color();
                
                overlayColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));

                int redCenter = randomR.Next(0, 255);

                int greenCenter = randomR.Next(0, 255);

                int blueCenter = randomR.Next(0, 255);

                int redTop = 0, redBottom = 0, greenTop = 0, greenBottom = 0, blueTop = 0, blueBottom = 0;

                // pick a color to emphasize

                int picker = 2;// pick.Next(0, 3);

                switch (picker)
                {

                    case 1:
                        {
                            greenCenter = (greenCenter - greenCenter / 5);

                            blueCenter = (blueCenter - blueCenter / 5);

                            redTop = redCenter + ((255 - redCenter) / 5);

                            greenTop = greenCenter + ((255 - greenCenter) / 5);

                            blueTop = blueCenter + ((255 - blueCenter) / 5);

                            redBottom = (redCenter - redCenter / 5);

                            greenBottom = (greenCenter - greenCenter / 5);

                            blueBottom = (blueCenter - blueCenter / 5);
                            break;
                        }
                    case 2:
                        {
                            redCenter = (redCenter - redCenter / 5);

                            blueCenter = (blueCenter - blueCenter / 5);

                            redTop = redCenter + ((255 - redCenter) / 5);

                            greenTop = greenCenter + ((255 - greenCenter) / 5);

                            blueTop = blueCenter + ((255 - blueCenter) / 5);

                            redBottom = (redCenter - redCenter / 5);

                            greenBottom = (greenCenter - greenCenter / 5);

                            blueBottom = (blueCenter - blueCenter / 5);

                            break;
                        }
                    case 3:
                        {
                            redCenter = (redCenter - redCenter / 5);

                            greenCenter = (greenCenter - greenCenter / 5);

                            redTop = redCenter + ((255 - redCenter) / 5);

                            greenTop = greenCenter + ((255 - greenCenter) / 5);

                            blueTop = blueCenter + ((255 - blueCenter) / 5);

                            redBottom = (redCenter - redCenter / 5);

                            greenBottom = (greenCenter - greenCenter / 5);

                            blueBottom = (blueCenter - blueCenter / 5);
                            break;
                        }

                }


                //do
                //{
                //    bottom = rRange.Next(0, 255);

                //    top = rRange.Next(0, 255);

                //} while (bottom > top);


                double dR, dG, dB;

                Bitmap bm = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                //DO NOT DELETE THE FOLLOWING COMMENTED SECTION IT ALLOWS FOR INDIVIDUALLY SETTING PIXELS IN THE BITMAP
            System.Drawing.Imaging.BitmapData bmpData =
            	bm.LockBits(new Rectangle(0,0,bm.Width,bm.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
                bm.PixelFormat);
            
            IntPtr ln1 = bmpData.Scan0;
            
            int bytes  = Math.Abs(bmpData.Stride) * bm.Height;
            	
	        byte[] rgbValues = new byte[bytes];
            
	        System.Runtime.InteropServices.Marshal.Copy( ln1, rgbValues, 0, bytes );

            //int ColorScale = 100;

            dR = randomR.Next(0, 255);

            dG = randomG.Next(0, 255);

            dB = randomB.Next(0, 255);
	        
	        int colorR = (int)Math.Truncate(dR);
	        
	        int colorG = (int)Math.Truncate(dG);
	        
	        int colorB = (int)Math.Truncate(dB);
	        
	        for( int thisPixel = 0;thisPixel<rgbValues.Length-2; thisPixel++ )
	        {
	        	
                //rgbValues[thisPixel-1] = (byte)0;

                //rgbValues[thisPixel ] = (byte)colorR;

                //rgbValues[thisPixel + 1] = (byte)colorG;

                //rgbValues[thisPixel + 2] = (byte)colorB;

                rgbValues[thisPixel] = (byte)255;

                //if (thisPixel % 4 == 0)
                //    rgbValues[thisPixel] = (byte)255;

                //if (thisPixel % 4 == 1 && !(thisPixel % 4 == 0))
                //    rgbValues[thisPixel] = (byte)255;

                //if (thisPixel % 4 == 2 && !(thisPixel % 4 == 0) && !(thisPixel % 2 == 0) && !(thisPixel % 1 == 0))
                //    rgbValues[thisPixel] = (byte)255;

                //if (!(thisPixel % 4 == 3) && !(thisPixel % 3 == 0) && !(thisPixel % 2 == 0) && !(thisPixel % 1 == 0))
                //    rgbValues[thisPixel] = (byte)255;

                //dR = randomR.Next(0, 255);

                //dG = randomR.Next(0, 255);

                //dB = randomR.Next(0, 255);

                //colorR = (int)Math.Truncate(dR);

                //colorG = (int)Math.Truncate(dG);

                //colorB = (int)Math.Truncate(dB);
	        }

	        System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ln1, bytes);
	        
            bm.UnlockBits(bmpData);    		
    		
    	


                //  int Height = 1300;

                //            int Width = 2000;        

                //Form MainForm = new Form();

                ///MainForm.AutoSize = true;

                //MainForm.MinimumSize = new Size(Width, Height);

                //MainForm.Activate();

                //MainForm.Show();

                //PictureBox pb = new PictureBox();

                //MainForm.Controls.Add(pb);

                //MainForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;

                //pb.Size = new Size(Width, Height);

                //pb.Show();


                //int seventeen = myRandom.Next(1, 2);

                //            switch ( seventeen ) 
                //            
                //            {
                //            	
                //            	case 1 :
                //            		pb.BackColor = System.Drawing.Color.White;
                //            			break;
                //            	case 2 :
                //pb.BackColor = System.Drawing.Color.Black;
                //            			break;
                //            		
                //            }

                int i;


                int randomNumber; randomNumber = random.Next(0, 255);

                for (int g = 1; g < 10; g++)
                {
                IntPoint ptStart = new IntPoint(random.Next(Width), random.Next(Height));

                //   Bitmap bm = new Bitmap(@"C:\Users\Kyland\Desktop\Test Projects\Random Bitmaps\Blank.bmp");


                double rnd;

                rnd = pc.Next(0, 8);

                //pb.BackgroundImage = bm;

                //System.Drawing.Graphics Drawer = System.Drawing.Graphics.FromImage(bm);

                //Drawer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

                //Drawer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                //int PenCase = (int)Math.Truncate(rnd);

                int PenCase = 4;

                Color startColor = Color.FromArgb(0,0,0);
                
                //float blendC1R, blendC1G, blendC1B, blendC2R, blendC2G, blendC2B = new float();

                IntPoint ptEnd = new IntPoint(0,0);

                //System.Drawing.Imaging.BitmapData bpData =
                //bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
                //bm.PixelFormat);

                for (i = 1; i < 100000; i++)
                //do
                {

                    IntPoint[] pts = new IntPoint[2];

                    int c;

                    Random randomC = new Random();

                    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), random.Next(0,255));

                                    //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);
                                break;
                            }
                        case 4:
                            { //all colors, thinnest line width


                                ptEnd = GetNextPoint(ptStart, random, bm.Width, bm.Height);

                                //endColor = Blend(overlayColor, GetPixelColor(ptEnd, bm));

                                endColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));

                                pts[0] = ptStart;

                                pts[1] = ptEnd;

                                DrawToBitmap(ptEnd, endColor, bm);

                                //Drawer.DrawLine(pn, ptStart, ptEnd);

                                ptStart = ptEnd;

                                //pn.Color = endColor;

                                //pn.Width = 1;

                                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

                    //while (ptEnd.X == pb.ClientRectangle.X | ptEnd.Y == pb.ClientRectangle.Y
                    //        | ptEnd.X == pb.ClientRectangle.Right | ptEnd.Y == pb.ClientRectangle.Bottom)
                    //{
                    //    if (ptEnd.X == pb.ClientRectangle.X)
                    //        ptEnd.X = ptEnd.X + 1;

                    //    if (ptEnd.Y == pb.ClientRectangle.Y)
                    //        ptEnd.Y = ptEnd.Y + 1;

                    //    if (ptEnd.X == pb.ClientRectangle.Right)
                    //        ptEnd.X = ptEnd.X - 1;

                    //    if (ptEnd.Y == pb.ClientRectangle.Bottom)
                    //        ptEnd.Y = ptEnd.Y - 1;
                    //}




                    //if (ptStart.IsEmpty)

                        // ptStart = new Point(random.Next(0, Width), random.Next(0, Height));

                        //pb.Refresh();
                        //                
                        //Application.DoEvents();


                    pts = null;

                }
                //while (System.DateTime.Now.Minute != 15);

                //pn.Dispose();

                //Drawer.Dispose();

                //bm.Save(@"C:\Users\kylan_000\Desktop\Test Projects\Random Bitmaps\RandomArt.RandomWalk\WithBlending\Random Walk " + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "h" + DateTime.Now.Minute + "m" + DateTime.Now.Second + "s" + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);

                //MainForm.Dispose();
            }
                
            bm.Save(@"C:\Users\kylan_000\Desktop\Test Projects\Random Bitmaps\RandomArt.RandomWalk\WithBlending\Random Walk " + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "h" + DateTime.Now.Minute + "m" + DateTime.Now.Second + "s" + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);

        }