Grid<E> implements a 2D grid structure in BRIDGES, and it can be used to represent 2D image like structures (more efficient than the 2D array representation for large arrays), as well as implementation of simple 2D games that operate on moderate sized grids. The setDimensions() method is used to set the grid dimensions. The ColorGrid subclass specializes this class to use Color for each grid element and is the subject of the illustrated example here. As before, <E> represents the generic class parameter. The Grid type uses a base64 representation for its contents.
Grid - Example BRIDGES Program - A checkerboard implementation using the ColorGrid)
- In this example, we will build and visualize a checkerboard in two colors using ColorGrid, which is subclassed from the Grid type (using the Color type as the generic parameter to the Grid type).
- Once we have identified the square to which a pixel belongs, its colored in one of two colors.
Here's the final code:
Java
C++
Python
Bridges Visualization
- Once all your code is in order, run your file.
- Assuming all your code is correct and it compiles correctly, a link to the Bridges website will be generated on the console.
- Copy/paste this link into your favorite browser to view a visualization of the data structure you just created.
- It should look something like this:
Well done! You’ve just created your Bridges Color Grid based Checker Board project!