35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

Time:2021-7-27

35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

Python character painting is a simple and interesting small program, which is very suitable for beginners to learn (Zhang) and learn (BI). The principle of Python character painting generation is very simple. In a word, it is to replace the picture pixels with different characters, so as to transform the picture composed of pixels into a character painting composed of characters. In order to make the character painting display effect the same as the picture as much as possible. Pixels with high gray values are represented by visually darker characters (such as $), and pixels with low gray values are represented by visually lighter characters

Running in Python 3, you can generate character pictures by inputting pictures. The general principle is mentioned in the notes. I didn’t have a deep understanding of the specific relationship between pixel and symbol conversion.

35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

Run command:

python3 draw.py –width 60 –height 30 test.png

35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

The following is the rendering:

35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

Python beginners can confide in me if they don’t understand anything – I just sorted out a set of 2021’s latest 0 basic introduction and advanced tutorials and shared them selflessly.

Access method: private letter editor’s reply: there are development tools, installation packages and system learning roadmap in the data (click on the small editor’s Avatar and send private letters in the upper right corner).Therefore, it is necessary for students who want to learn to listen to the teacher’s class and receive Python fulio. Students who want to learn can go to Wai Xin of Mengya teacher (homonym): the front group is mengy and the back group is 7762. Just combine the above two groups of letters in order, and she will arrange learning.

be careful:

The display effect may be different in different environments. Whether the font displayed on the terminal is an equal width font, the line height and line width displayed on the terminal, the width and height of the input and output image, etc. all these will affect the display effect.

In addition, the character set used in the character drawing has a total of 70 characters, that is, the following line of code:

35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

35 lines of code, using Python to generate character painting, which is very suitable for beginners to practice, with source code!

The more types and numbers of characters, the more colors they show, and the better the sense of hierarchy of character painting. You can debug them repeatedly according to the effect of character painting.

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]