PHP is best known as the year of the programming language, Python is today the most simple programming language, a small program, a few lines of code, take you to experience the fun of programming.
The easiest programming language
Today to introduce the gadget is installed after Python environment, comes with a library, we can call it the turtle drawing, turtle library is easy to use accumulated novice confidence in the program, because it is able to show up a visualization page library, we write code that can visually see the effect, it is not generally learn programming route that has been knocked code can only communicate with the console, very abstract understand this process, it is very friendly, very straight white communicate results to show with your computer.
If you are reading the article, do not know how the Python runtime environment installed, you can search on their own, very simple process that can be downloaded after installing a package, has been click Next on it, there are many online tutorials , I will not elaborate on this process up. Now I will be progressive on this turtle drawing code to explain, to ensure that everyone will be able to learn.
Cute turtle, easily lead us into the world of programming
First open our programming environment, you can type python at the command line, I will use my command line to show the execution and explanation of these codes
I open the command line, like this
After the command to open the way
Your appearance may be with me will be different, but do not worry, you can simply open up.
The first step, we need to import turtles library, import library is the purpose of turtles that we can use as a tool for other developers we've written, we'll understand it is a tool like, for example, use a screwdriver to tighten the screws on child well, this child is a screwdriver others has helped us produce a good tool to avoid screwing up our bare hands. This is the same reason Turtles library.
This wording is: Import Turtle
Imported turtles library, pay attention to import no spaces in front of the word
Once imported, we can use this library a turtle.
The first step we need to get the turtles brush, specific wording is: t = turtle.Pen ()
The t now that we brush, we can use a brush to paint. Now get started right away!
When we press enter, your screen will pop up a box canvas bomb!
The middle of the canvas with an arrow, this is our brush up
This time, we again enter the painting instruction: t.forward (100) This instruction means that draw pixels in the direction of the arrow 100 in programming, our specific length and width and other units of length are used to represent the pixels . A pixel width of about one millimeter.
Visual display after running t.forward (100)
This time, we can choose to rotate the arrow to the left 90 degrees, the equivalent of driving a left turn when the meaning of the code is t.left (90)
Note that the arrow from the original right up into the present
Again run t.forward (100)
This time it drew up a 100 pixel line
Repeat the above procedure twice, we can draw a square, the complete code as shown below:
Line by line in the editor can enter
The final results show
See, codes of a total of 9 lines, if the logic loop will be much easier so
Figures for x in range (100) which is circulating wording
Circulating about specifically what it means, the article can continue after you explain, because the wording and application cycle there are a lot of scenes. You can start to feel the results of running this piece of code
After 100 cycles results
When we adjust the angle, will demonstrate the same effect, we are now into the 91-degree angle to try again
The left turn angle set to 91 degrees
Turn left 91 degrees, the result becomes very interesting pictures of the bar
Here, there is no program that is actually a very interesting thing, quickly hands to write it. If you encounter any problems in the process of writing are welcome to ask questions at the bottom!