fn draw(&self, ctx: &mut ggez::Context, param: graphics::DrawParam) -> ggez::GameResult<()> {
        
        // Create a new graphic mesh builder
        let mut mb = graphics::MeshBuilder::new();

        // Iterate through each cell in the grid
        for (x, y, cell) in self.grid.clone() {

            // Create the bounds of the cell
            let cellbounds = graphics::Rect::new(
                (x as f32) * self.cellsize,
                (y as f32) * self.cellsize,
                self.cellsize,
                self.cellsize,
            );

            // Add the cell fill to the mesh builder
            mb.rectangle(
                graphics::DrawMode::Fill(graphics::FillOptions::default()),
                cellbounds,
                // Set the cell color based on cell state
                match cell {
                    BinaryCell::Passive => [0.0, 0.0, 0.0, 1.0].into(),
                    BinaryCell::Active => [1.0, 1.0, 1.0, 1.0].into(),
                },
            )
            // Add the cell boundary to the mesh builder
            .rectangle(
                graphics::DrawMode::Stroke(graphics::StrokeOptions::default()),
                cellbounds,
                [1.0, 1.0, 1.0, 0.25].into(),
            );
        }

        // Check if the ant is initialized
        if let Some(ant) = &self.ant {
            // Get the position of the ant
            let (x, y, _) = ant.position;
            // Create the centroid of the ant sprite based on the position
            let centroid = na::Point2::new((x as f32 * self.cellsize) + self.cellsize/2.0, (y as f32 * self.cellsize) + self.cellsize/2.0);
            // Define a metric of distance between the ant sprite vertices
            let unitdist = self.cellsize/4.0;

            // Get the vertices of the ants sprite based on its orientation.
            // The ant sprite is a triangle pointing in the direction of its orientation
            let points = match ant.orientation {
                Direction4::North => {[
                    na::Point2::new(centroid.x, centroid.y + unitdist), 
                    na::Point2::new(centroid.x + unitdist, centroid.y - unitdist), 
                    na::Point2::new(centroid.x - unitdist, centroid.y - unitdist)
                ]},
                Direction4::East => {[
                    na::Point2::new(centroid.x + unitdist, centroid.y),
                    na::Point2::new(centroid.x - unitdist, centroid.y - unitdist),
                    na::Point2::new(centroid.x - unitdist, centroid.y + unitdist)
                ]},
                Direction4::South => {[
                    na::Point2::new(centroid.x, centroid.y - unitdist),
                    na::Point2::new(centroid.x - unitdist, centroid.y + unitdist),
                    na::Point2::new(centroid.x + unitdist, centroid.y + unitdist)
                ]},
                Direction4::West => {[
                    na::Point2::new(centroid.x - unitdist, centroid.y),
                    na::Point2::new(centroid.x + unitdist, centroid.y + unitdist),
                    na::Point2::new(centroid.x + unitdist, centroid.y - unitdist)
                ]},
            };

            // Set the color of the ant based on if its alive
            let color;
            if ant.active {
                // Red color if ant is alive
                color = [1.0, 0.0, 0.0, 1.0];
            } else {
                // Blue color is ant is dead
                color = [0.0, 1.0, 0.0, 1.0];
            }

            // Construct the triangle polygon from the sprite vertices
            mb.polygon(
                graphics::DrawMode::Fill(graphics::FillOptions::default()), 
                &points, 
                color.into()
            )?;
        }
        
        // Build and Draw the mesh
        mb.build(ctx)?.draw(ctx, param)?;

        // Declare a variable for the font size
        let font_size = 18.0;

        // Create the text graphics for the banner
        let mut name_text = graphics::Text::new(self.fullname());
        let mut state_text = graphics::Text::new(self.state());

        // Set the font styling for the text graphics
        state_text.set_font(graphics::Font::default(), graphics::Scale::uniform(font_size));
        name_text.set_font(graphics::Font::default(), graphics::Scale::uniform(font_size));

        // Chekc the grid dimesions
        if let Some(dimensions) = &self.grid.dimensions {
            // Calculate the spacing between banner elements.
            // Assumes 2 units of spacing above the name text and below the state text
            // and 1 unit of spacing between the name and state text.
            let spacing = (60.0 - (font_size * 2.0)) / 5.0;

            // Calculate the position of the name text
            let name_offset = dimensions.h + (spacing * 2.0);
            // Calculate the position of the state text
            let state_offset = dimensions.h + (spacing * 3.0) + font_size;

            // Draw the banner text graphics
            name_text.draw(ctx, (na::Point2::new(param.dest.x + 10.0, param.dest.y + name_offset),).into())?;
            state_text.draw(ctx, (na::Point2::new(param.dest.x + 10.0, param.dest.y + state_offset),).into())?;
        }

        // Return GameResult::Ok
        Ok(())
    }
// A method that renders the automaton grid and state and returns a GameResult
A method that renders the automaton grid and state and returns a GameResult
A method that renders the automaton grid and state and returns a GameResult
fn draw(&self, ctx: &mut ggez::Context, param: graphics::DrawParam) -> ggez::GameResult<()> {
        // Create a new graphic mesh builder
        let mut mb = graphics::MeshBuilder::new();
        // Iterate through each cell in the grid
        for (x, y, cell) in self.grid.clone() {
            // Create the bounds of the cell
            let cellbounds = graphics::Rect::new(
                (x as f32) * self.cellsize,
                (y as f32) * self.cellsize,
                self.cellsize,
                self.cellsize,
            );
            // Add the cell fill to the mesh builder
            mb.rectangle(
                graphics::DrawMode::Fill(graphics::FillOptions::default()),
                cellbounds,
                // Set the cell color based on cell state
                match cell {
                    BinaryCell::Passive => [0.0, 0.0, 0.0, 1.0].into(),
                    BinaryCell::Active => [1.0, 1.0, 1.0, 1.0].into(),
                },
            )
            // Add the cell boundary to the mesh builder
            .rectangle(
                graphics::DrawMode::Stroke(graphics::StrokeOptions::default()),
                cellbounds,
                [1.0, 1.0, 1.0, 0.25].into(),
            );
        }
        // Check if the ant is initialized
        if let Some(ant) = &self.ant {
            // Get the position of the ant
            let (x, y, _) = ant.position;
            // Create the centroid of the ant sprite based on the position
            let centroid = na::Point2::new((x as f32 * self.cellsize) + self.cellsize/2.0, (y as f32 * self.cellsize) + self.cellsize/2.0);
            // Define a metric of distance between the ant sprite vertices
            let unitdist = self.cellsize/4.0;
            // Get the vertices of the ants sprite based on its orientation.
            // The ant sprite is a triangle pointing in the direction of its orientation
            let points = match ant.orientation {
                Direction4::North => {[
                    na::Point2::new(centroid.x, centroid.y + unitdist), 
                    na::Point2::new(centroid.x + unitdist, centroid.y - unitdist), 
                    na::Point2::new(centroid.x - unitdist, centroid.y - unitdist)
                ]},
                Direction4::East => {[
                    na::Point2::new(centroid.x + unitdist, centroid.y),
                    na::Point2::new(centroid.x - unitdist, centroid.y - unitdist),
                    na::Point2::new(centroid.x - unitdist, centroid.y + unitdist)
                ]},
                Direction4::South => {[
                    na::Point2::new(centroid.x, centroid.y - unitdist),
                    na::Point2::new(centroid.x - unitdist, centroid.y + unitdist),
                    na::Point2::new(centroid.x + unitdist, centroid.y + unitdist)
                ]},
                Direction4::West => {[
                    na::Point2::new(centroid.x - unitdist, centroid.y),
                    na::Point2::new(centroid.x + unitdist, centroid.y + unitdist),
                    na::Point2::new(centroid.x + unitdist, centroid.y - unitdist)
                ]},
            };
            // Set the color of the ant based on if its alive
            let color;
            if ant.active {
                // Red color if ant is alive
                color = [1.0, 0.0, 0.0, 1.0];
            } else {
                // Blue color is ant is dead
                color = [0.0, 1.0, 0.0, 1.0];
            }
            // Construct the triangle polygon from the sprite vertices
            mb.polygon(
                graphics::DrawMode::Fill(graphics::FillOptions::default()), 
                &points, 
                color.into()
            )?;
        }
        // Build and Draw the mesh
        mb.build(ctx)?.draw(ctx, param)?;
        // Declare a variable for the font size
        let font_size = 18.0;
        // Create the text graphics for the banner
        let mut name_text = graphics::Text::new(self.fullname());
        let mut state_text = graphics::Text::new(self.state());
        // Set the font styling for the text graphics
        state_text.set_font(graphics::Font::default(), graphics::Scale::uniform(font_size));
        name_text.set_font(graphics::Font::default(), graphics::Scale::uniform(font_size));
        // Chekc the grid dimesions
        if let Some(dimensions) = &self.grid.dimensions {
            // Calculate the spacing between banner elements.
            // Assumes 2 units of spacing above the name text and below the state text
            // and 1 unit of spacing between the name and state text.
            let spacing = (60.0 - (font_size * 2.0)) / 5.0;
            // Calculate the position of the name text
            let name_offset = dimensions.h + (spacing * 2.0);
            // Calculate the position of the state text
            let state_offset = dimensions.h + (spacing * 3.0) + font_size;
            // Draw the banner text graphics
            name_text.draw(ctx, (na::Point2::new(param.dest.x + 10.0, param.dest.y + name_offset),).into())?;
            state_text.draw(ctx, (na::Point2::new(param.dest.x + 10.0, param.dest.y + state_offset),).into())?;
        }
        // Return GameResult::Ok
        Ok(())
    }
fn draw ( & self , ctx : & mut ggez :: Context , param : graphics :: DrawParam ) -> ggez :: GameResult < ( ) > { // Create a new graphic mesh builder let mut mb = graphics :: MeshBuilder :: new ( ) ; // Iterate through each cell in the grid for ( x , y , cell ) in self . grid . clone ( ) { // Create the bounds of the cell let cellbounds = graphics :: Rect :: new ( ( x as f32 ) * self . cellsize , ( y as f32 ) * self . cellsize , self . cellsize , self . cellsize , ) ; // Add the cell fill to the mesh builder mb . rectangle ( graphics :: DrawMode :: Fill ( graphics :: FillOptions :: default ( ) ) , cellbounds , // Set the cell color based on cell state match cell { BinaryCell :: Passive => [ 0.0 , 0.0 , 0.0 , 1.0 ] . into ( ) , BinaryCell :: Active => [ 1.0 , 1.0 , 1.0 , 1.0 ] . into ( ) , } , ) // Add the cell boundary to the mesh builder . rectangle ( graphics :: DrawMode :: Stroke ( graphics :: StrokeOptions :: default ( ) ) , cellbounds , [ 1.0 , 1.0 , 1.0 , 0.25 ] . into ( ) , ) ; } // Check if the ant is initialized if let Some ( ant ) = & self . ant { // Get the position of the ant let ( x , y , _ ) = ant . position ; // Create the centroid of the ant sprite based on the position let centroid = na :: Point2 :: new ( ( x as f32 * self . cellsize ) + self . cellsize / 2.0 , ( y as f32 * self . cellsize ) + self . cellsize / 2.0 ) ; // Define a metric of distance between the ant sprite vertices let unitdist = self . cellsize / 4.0 ; // Get the vertices of the ants sprite based on its orientation. // The ant sprite is a triangle pointing in the direction of its orientation let points = match ant . orientation { Direction4 :: North => { [ na :: Point2 :: new ( centroid . x , centroid . y + unitdist ) , na :: Point2 :: new ( centroid . x + unitdist , centroid . y - unitdist ) , na :: Point2 :: new ( centroid . x - unitdist , centroid . y - unitdist ) ] } , Direction4 :: East => { [ na :: Point2 :: new ( centroid . x + unitdist , centroid . y ) , na :: Point2 :: new ( centroid . x - unitdist , centroid . y - unitdist ) , na :: Point2 :: new ( centroid . x - unitdist , centroid . y + unitdist ) ] } , Direction4 :: South => { [ na :: Point2 :: new ( centroid . x , centroid . y - unitdist ) , na :: Point2 :: new ( centroid . x - unitdist , centroid . y + unitdist ) , na :: Point2 :: new ( centroid . x + unitdist , centroid . y + unitdist ) ] } , Direction4 :: West => { [ na :: Point2 :: new ( centroid . x - unitdist , centroid . y ) , na :: Point2 :: new ( centroid . x + unitdist , centroid . y + unitdist ) , na :: Point2 :: new ( centroid . x + unitdist , centroid . y - unitdist ) ] } , } ; // Set the color of the ant based on if its alive let color ; if ant . active { // Red color if ant is alive color = [ 1.0 , 0.0 , 0.0 , 1.0 ] ; } else { // Blue color is ant is dead color = [ 0.0 , 1.0 , 0.0 , 1.0 ] ; } // Construct the triangle polygon from the sprite vertices mb . polygon ( graphics :: DrawMode :: Fill ( graphics :: FillOptions :: default ( ) ) , & points , color . into ( ) ) ? ; } // Build and Draw the mesh mb . build ( ctx ) ? . draw ( ctx , param ) ? ; // Declare a variable for the font size let font_size = 18.0 ; // Create the text graphics for the banner let mut name_text = graphics :: Text :: new ( self . fullname ( ) ) ; let mut state_text = graphics :: Text :: new ( self . state ( ) ) ; // Set the font styling for the text graphics state_text . set_font ( graphics :: Font :: default ( ) , graphics :: Scale :: uniform ( font_size ) ) ; name_text . set_font ( graphics :: Font :: default ( ) , graphics :: Scale :: uniform ( font_size ) ) ; // Chekc the grid dimesions if let Some ( dimensions ) = & self . grid . dimensions { // Calculate the spacing between banner elements. // Assumes 2 units of spacing above the name text and below the state text // and 1 unit of spacing between the name and state text. let spacing = ( 60.0 - ( font_size * 2.0 ) ) / 5.0 ; // Calculate the position of the name text let name_offset = dimensions . h + ( spacing * 2.0 ) ; // Calculate the position of the state text let state_offset = dimensions . h + ( spacing * 3.0 ) + font_size ; // Draw the banner text graphics name_text . draw ( ctx , ( na :: Point2 :: new ( param . dest . x + 10.0 , param . dest . y + name_offset ) , ) . into ( ) ) ? ; state_text . draw ( ctx , ( na :: Point2 :: new ( param . dest . x + 10.0 , param . dest . y + state_offset ) , ) . into ( ) ) ? ; } // Return GameResult::Ok Ok ( ( ) ) }
A method that renders the automaton grid and state and returns a GameResult
A method that renders the automaton grid and state and returns a GameResult
&self
ctx
&mut ggez::Context
param
graphics::DrawParam
&self
ctx
&mut ggez::Context
param
graphics::DrawParam