///

///Split(string, int) - takes a string and returns an IEnumerable of strings that has been broken up into <int> length

///Random() - returns a random byte

///

///The goal of this is to take a string of hex characters and color a 100x100 canvas/bitmap. If the hex string is not long enough, it

///selects random colors to fill in the rest of it.

///It works, but is very messy

///

private void button5_Click ( object sender, EventArgs e )

{

bool bb = true ;

canvas . Clear ( Color . White ) ;

string [ ] s = Split ( richTextBox3 . Text , 6 ) . ToArray ( ) ;

if ( s . Length >= 10000 )

MessageBox . Show ( "Hex string too long for 100x100 grid. Please shorten it" ) ;

else {

//prepend '#' to the front of every string

for ( int t = 0 ; t < s . Length ; t ++ )

s [ t ] = "#" + s [ t ] ;

int y = 0 ;

int x = 0 ;

for ( int z = 0 ; z < s . Length ; z ++ ) {

SolidBrush brush = new SolidBrush ( ColorTranslator . FromHtml ( s [ z ] ) ) ;

canvas . FillRectangle ( brush, x, y, 1 , 1 ) ;

using ( Graphics g = Graphics . FromImage ( bmp ) ) {

g . FillRectangle ( brush, x, y, 1 , 1 ) ;

}

x ++;

if ( x == 100 ) {

x = 0 ;

y ++;

}

if ( y == 100 )

break ;

//This is where I test if the canvas is filled yet or not. If not, it enters a new loop and fills the rest of the

//canvas with random colors.

if ( z + 1 >= s . Length ) {

for ( int yy = 0 ; yy < 100 ; yy ++ ) {

for ( int xx = 0 ; xx < 100 ; xx ++ ) {

//sets the start position of where it should start filling colors

if ( bb == true ) {

bb = false ;

yy = y ;

xx = x ;

}

SolidBrush brush2 = new SolidBrush ( Color . FromArgb ( 255 , Random ( ) , Random ( ) , Random ( ) ) ) ;

canvas . FillRectangle ( brush2, xx, yy, 1 , 1 ) ;

using ( Graphics g = Graphics . FromImage ( bmp ) ) {

g . FillRectangle ( brush2, xx, yy, 1 , 1 ) ;

}

}

}

}

}

}