The Board class contained in Board.py is the primary render object used for displaying states in a wide variety of possible games. Fundamentally a Board object is a collection of Polygon objects (see below) each with their own render settings (e.g. bevel size, tint shade, and so on). The advantage of such a system is that it allows for creation of a wide variety of board games, from the square grids of chess to the hexagonal tilings of Catan. It is even possible to mix the types of polygons used in an endless variety of combinations for a even wider range of gameplay options (as of hint of future projects).
Note: The animation of the chess board shown here is the output of Board_tests.py from the board_games folder of the unit_tests repository. For this particular animation the virtual light source illuminating the board is rotating 360 degrees around the board while oscillating between attitudes of 35 and 50 degrees.
The fundamental object for the board game project is the Polygon. The idea is that one simply provides vertex locations (x1,y1) through (xn,yn) and the methods of the class render a beveled polygon under the given lighting conditions. Of course, not all possible vertex locations will lead to a valid polygon; there are a few conditions that must be met in order for the choice of vertices to be acceptable:
All of the provided vertex locations are distinct, i.e. i ≠ j implies xi ≠ xj or yi ≠ yj
The line segments defining the perimeter of the polygon only intersect trivially, i.e. if two line segments intersect then they only intersect at a single point and that point is one of the provided vertex locations
The vertices defining the polygon's perimeter must traverse a counter clockwise path around the interior of the polygon (although in practice if they are provided as going clockwise then the vertex ordering is simply reversed by the Polygon class)
Once the Polygon object has been initialized, one must call the preprocessBevelInfo and preprocessSunInfo methods to apply settings relevant to the rendering of a uniform-width bevel along the perimeter of the polygon. Beyond this, the user can provide an RGB object as an argument in the render method in order to apply a tint to the overall color of the polygon image. The images in the following examples show off the various render configuration options in more detail:
There are a variety of pre-defined shapes in Polygon.py: squares, triangles and hexagons
It is easy to define any custom polygon shape you want!
The size of the polygon's bevel faces can be easily controlled by a single parameter
A related "bevel attitude" parameter allows for adjusting the contrast between the center and bevel faces of the polygon
The position of a virtual light source allows for illuminating a given side of the polygon more than other sides
Relative brightness is physically accurate based normal vectors of the polygon's faces
Changing the height of the virtual light source allows for controlling the overall brightness and contrast of the various faces
Any desired tint shade can be specified using the RGB class from color_helper.py
For the sake of efficiency, the color can be changed without needing to recompute the bevel faces of the polygon!