This program is our final project for the IA41 class. We had as specifications to realize a tangram solver and to let the user realize his own puzzles.
A tangram is a set of 7 geometric pieces (2 large triangles, 1 middle triangle, 1 parallelogram, 1 square and 2 small triangles). The goal is to complete an image where only the shadow of the pieces appears.
This project has been made 100% in python.
This program is able to solve mutliple tangrams puzzles in matters of seconds. It includes a built-in tangram editor allowing the user to create its own tangram puzzles and use the program to solve them.
You can save the results of the execution of the program. This saved data includes the position of the solved piece on the 800x700px canvas, the execution time of the program and the differents steps to complete the tangram :
In order to use the program you will need to have a python 3.X interpretor installed. The required libraries are listed in the requirements.txt file.
- Clone the project and unzip it.
- Install the librairies listed in requirements.txt
A simple use of the program to save the results of the solver is to execute this line in the terminal :
py main.py --saveData True
The arguments available to use the program are :
imagePath
: Allow the user to use the solver on an prebuilt image (if no path is provided the program will use the built-in editor)saveData
: Allow the user to save the data of the execution in a .json file and the steps as .png files. (By default False)
This program includes a built-in editor that lets you design your own tangram puzzles. You can select the piece you want to use using the numbers keys :
- 1 Large triangle n°1
- 2 Large triangle n°2
- 3 Medium Triangle
- 4 Parallelogram
- 5 Square
- 6 Small triangle n°1
- 7 Small triangle n°2
When a piece is selected you can :
- Press F to flip the active piece (useful when dealing with the parallelogram)
- Press R to rotate the active piece
- Press N to change the active piece's corner held by the mouse cursor
Time (in seconds) | 0.7 | 44.9 | 0.2 | 2586.5 |
---|---|---|---|---|
Solution steps |
With our algorithm, most tangrams are solvable in only a few seconds. However, as shown here, some tangrams (usually those with few corners) are very difficult and the algorithm can spend a few tens of minutes.
Distributed under the MIT License.