Posts

Showing posts with the label Project

Dice grid from a photo with Python (V) - Creation of a stand-alone executable

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Drawing the dice Create a grid of dice from a photo Design of the GUI Creation of the stand-alone executable Introduction Up to this point, we've designed the program and created the modules and the GUI coding with Python. We could now say that the program is complete! But we can still work on one last thing: The creation of a stand-alone executable that will help us to distribute our program, as it will be able to be run on any machine even without a Python interpreter installed. For this, we'll use Pyinstaller . With pyinstaller you can create an executable file for your operative system (i.e. you can not create an EXE for Windows running pyinstaller on Ubuntu, to do that you'd need to run it on Windows).  Downloading Pyinstaller Pyinstaller can be added to your machine through PIP with the following command: pip install pyinstaller ...

Dice grid from a photo with Python (IV) – Designing the GUI with Tkinter

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Drawing the dice Create a grid of dice from a photo Design of the GUI Documentation and creation of the stand-alone executable Introduction So far, we've been able to successfully create a dice grid from any picture using PIL and Python. However, running the script and modify the path to the picture every time we want to make a grid becomes tedious very quickly and its not the most friendly way to do the things. We can significantly enhance the user-experience through a GUI that will let us visualize a preview of the final result and browse through the folders of our system to find the pictures we want to send to the script. In this post, I'll show you how to design a GUI with Tkinter , and in the next post, I'll show you how to create an stand-alone executable that you will be able to distribute and run without having Python installed in your c...

Dice grid from a photo with Python (III) – Creating the resulting picture

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Drawing the dice Create a grid of dice from a photo Design of the GUI Document and creation of the stand-alone executable Introduction In the first post of this project I mentioned the steps to create a dicing grid parting from a picture: Divide the picture into subsets Analyze each subset and replace it with the correspondent die based on its brightness I already defined the functions to draw the dice, so in this post I'm going to continue with the functions needed to transform the picture into a grid of dice, basically finishing the main purpose of this project. The steps to code the dicing grid are a bit different than the mentioned before, being like this: Get the constant values using the formula mentioned in the first post Validate or resize the size of the picture Divide the picture into subsets Analyze each subset and replace it with th...

Dice grid from a photo with Python (II) – Drawing the dice

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Drawing the dice Create a grid of dice from a photo Design of the GUI Document and creation of the stand-alone executable Introduction In the previous post we analyzed all the steps to create a dicing grid from a picture in theory, but no code was written. In this post, I will show you how to draw dice with Pillow and its methods. In this post, we will see: How to install Pillow as a Python module How to import and use the methods in PIL.Image and PIL.ImageDraw in our code How to divide our code into functions Use of arguments and keyword arguments Installation of Pillow Pillow is a library that adds support for manipulation of images in Python. Pillow is a fork of PIL , appearing after the later stopped being updated in 2009. You can install Pillow through PIP on Windows, Mac, and Linux with the command: pip install Pillow Installing Pillow ...

Dice grid from a photo with Python (I) – Logic behind the program

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Creation of the dice Create a grid of dice from a photo Design of the GUI Document and creation of the stand-alone executable Introduction Before we code the program, it is necessary to have a general idea about how we will solve the problem that surrounds us. Here, we want to know how can we create a grid of dice parting from a picture, and what must we do to put the correct dice in each part of the picture in such a way that the result resembles the original picture. Note: In this post, I will only show the logic behind the program and therefore no coding will be done. In this post, we will analyze: How to draw the dice How to divide the picture into subsets How to decide which die paste in each part of the picture Thinking of a template for the die We are going for the simplest approach to draw the dice: 1 dot per pixel. As the die is a cube...