pub fn new(mut rows: usize, mut cols: usize) -> Universe {
        // Bit-map with (r, g, b, a) values
        let image_size = (rows * cols) * 4;
        let mut image_data: Vec<u8> = (0..image_size).map(|_| 255 as u8).collect();

        // Add padding
        cols += 2;
        rows += 2;

        let total_cells = cols * rows;
        let target: Vec<bool> = (0..total_cells).map(|_| false).collect();
        let mut source: Vec<bool> = (0..total_cells).map(|_| false).collect();

        // Random initialization
        let mut resurrected_cells = 0;
        for row in 1..(rows - 1) {
            let image_data_offset = (row - 1) * (cols - 2);
            let offset = row * cols;

            for col in 1..(cols - 1) {
                if random_bool(0.5) {
                    source[offset + col] = true;

                    // Toggle pixel
                    let image_data_index = (image_data_offset + (col - 1)) * 4;
                    image_data[image_data_index] = 0;
                    image_data[image_data_index + 1] = 0;
                    image_data[image_data_index + 2] = 0;
                    resurrected_cells += 1;
                }
            }
        }

        Universe {
            swap: false,
            survive_rules: 0b000001100,
            resurrect_rules: 0b000001000,
            killed_cells: 0,
            resurrected_cells,
            image_data,
            cols,
            rows,
            source,
            target,
        }
    }
/// Creates a new game-of-life universe
Creates a new game-of-life universe
Creates a new game - of - life universe
pub fn new(mut rows: usize, mut cols: usize) -> Universe {
        // Bit-map with (r, g, b, a) values
        let image_size = (rows * cols) * 4;
        let mut image_data: Vec<u8> = (0..image_size).map(|_| 255 as u8).collect();
        // Add padding
        cols += 2;
        rows += 2;
        let total_cells = cols * rows;
        let target: Vec<bool> = (0..total_cells).map(|_| false).collect();
        let mut source: Vec<bool> = (0..total_cells).map(|_| false).collect();
        // Random initialization
        let mut resurrected_cells = 0;
        for row in 1..(rows - 1) {
            let image_data_offset = (row - 1) * (cols - 2);
            let offset = row * cols;
            for col in 1..(cols - 1) {
                if random_bool(0.5) {
                    source[offset + col] = true;
                    // Toggle pixel
                    let image_data_index = (image_data_offset + (col - 1)) * 4;
                    image_data[image_data_index] = 0;
                    image_data[image_data_index + 1] = 0;
                    image_data[image_data_index + 2] = 0;
                    resurrected_cells += 1;
                }
            }
        }
        Universe {
            swap: false,
            survive_rules: 0b000001100,
            resurrect_rules: 0b000001000,
            killed_cells: 0,
            resurrected_cells,
            image_data,
            cols,
            rows,
            source,
            target,
        }
    }
pub fn new ( mut rows : usize , mut cols : usize ) -> Universe { // Bit-map with (r, g, b, a) values let image_size = ( rows * cols ) * 4 ; let mut image_data : Vec < u8 > = ( 0 .. image_size ) . map ( | _ | 255 as u8 ) . collect ( ) ; // Add padding cols += 2 ; rows += 2 ; let total_cells = cols * rows ; let target : Vec < bool > = ( 0 .. total_cells ) . map ( | _ | false ) . collect ( ) ; let mut source : Vec < bool > = ( 0 .. total_cells ) . map ( | _ | false ) . collect ( ) ; // Random initialization let mut resurrected_cells = 0 ; for row in 1 .. ( rows - 1 ) { let image_data_offset = ( row - 1 ) * ( cols - 2 ) ; let offset = row * cols ; for col in 1 .. ( cols - 1 ) { if random_bool ( 0.5 ) { source [ offset + col ] = true ; // Toggle pixel let image_data_index = ( image_data_offset + ( col - 1 ) ) * 4 ; image_data [ image_data_index ] = 0 ; image_data [ image_data_index + 1 ] = 0 ; image_data [ image_data_index + 2 ] = 0 ; resurrected_cells += 1 ; } } } Universe { swap : false , survive_rules : 0b000001100 , resurrect_rules : 0b000001000 , killed_cells : 0 , resurrected_cells , image_data , cols , rows , source , target , } }
Creates a new game-of-life universe
Creates a new game - of - life universe
rows
usize
cols
usize
rows
usize
cols
usize