private void BtnRandomize_Click(object sender, EventArgs e) { if (null == m_board) { MessageBox.Show("Board is not initialized"); return; } Cursor = Cursors.WaitCursor; m_board.reset(); if (null == m_rndm) { m_rndm = new Random(); } int n_white_black_ratio = (int)(NudWhiteBlackRatio.Value); int n_white = Color.White.ToArgb(); int n_black = Color.Black.ToArgb(); // int n_seed = (int)((DateTime.Now - DateTime.Today).TotalMilliseconds); // Parallel.For(0, m_board.height, // (j) => // { // Random _rndm = new Random(n_seed + j); // for ( int i = 0; i < m_board.width; i++ ) // { // if ( 0 == _rndm.Next(n_white_black_ratio+1) ) // m_board.set_pixel_color(i, j, n_black); // else // m_board.set_pixel_color(i, j, n_white); // } // } ); for (int i = 0; i < m_board.width * m_board.height; i++) { if (0 == m_rndm.Next(n_white_black_ratio + 1)) { m_board.set_pixel_color(i, n_black); } else { m_board.set_pixel_color(i, n_white); } } draw_board(); Cursor = Cursors.Default; }
} // paint_isle() /* --------------------------------------------------------------------------------- *\ * Description: * * Parameters: * int x: * int y: * int n_pixel_ind: * Color _color: * int n_color: * Stack<CPathNode> _path: \* --------------------------------------------------------------------------------- */ private static void paint_n_push(int x, int y, int n_pixel_ind, int n_color, CBoard _board, Stack <CPathNode> _path) { _board.set_pixel_color(n_pixel_ind, n_color); _path.Push(new CPathNode(x, y)); }