Raspberry Pi: Tips and Tricks to Learn Raspberry Pi Programming by Pratt Logan

Raspberry Pi: Tips and Tricks to Learn Raspberry Pi Programming by Pratt Logan

Author:Pratt, Logan [Pratt, Logan]
Language: eng
Format: epub
Published: 2020-08-04T00:00:00+00:00


Self-Project: Turtle Snowflakes

By now, you learned how Python works. Now the time is right to learn about graphics and create some snowflakes. In essence, physical robots have shapes similar to their animal namesakes. For example, turtles are constructed to only move in a straight line, either lift or lower a pen. When we convert it to a digital version, it means to start or end, drawing a specific line with its movement.

Opposite to other languages, e.g., Logo along with its variants, Python doesn’t have this turtle tool. However, it has numerous add-on codes to provide it a turtle power. These codes libraries have numerous codes that include new information and instructions to increase the capabilities of Python. These codes libraries are provided into your programs through an import command. Form a new program through pressing on the New icon, and writing the following:

import turtle

For using the instructions given in the library, use the library name, and then add a full stop and complete it with the instruction name. It feels hard to type your user name repeatedly, therefore, choose a smaller variable name. It can be as short as one letter, or you can use twice the pet name. Therefore, type the following:

var = turtle.Turtle()

To check the program if it is working or not, give the turtle a task to do. So type:

pat.forward(50)

Now press icon saying Run and save the program with the name Turtle Snowflakes. As soon as the program is saved, one new window with the name of Turtle Graphics will appear. This window will show the results of your program as your turtle, Pat, will go forward for 50 units forming one straight line.

After this step, go back to the main Thonny window. Possibly, it will be hidden on the backside of the Turtle Graphic window, so click the minimize option visible on the Turtle Graphics window. Another option to switch back to Thonny’s main window is to press the Thonny entry present in the taskbar on the upper side of the screen. After this, press the Stop button in order to terminate the Turtle Graphic window.

Writing each and every movement instruction is a difficult task to do; therefore, delete line three and form a loop to perform a difficult task of creating shapes:

for i in range(1):

pat.forward(50)

pat.right(30)

pat.forward(50)

pat.right(60)

Now run the program, var will draw one parallelogram.

To convert it into a shape similar to the snowflake, press the Stop icon Thonny’s main window and form a loop which circles your loop through adding the below-given line for line 3:

for i in range(5):

And the below-given line at the lower side of your program:

pat.right(18)

It is hard for your program to run it because the existing loop is not rightly indented. For fixing it, press at the beginning of each line of the current Start of Loop from line 4 till line 8 and push the SPACE key for up to 4 times to make indentation correct. After this step, your program will look like the following:

import turtle

var = turtle.Turtle()

for i in range(5):

for i in range(1):

pat.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Architecting High-Performance Embedded Systems by Jim Ledin(1203)
DIY Microcontroller Projects for Hobbyists by Miguel Angel Garcia-Ruiz Pedro Cesar Santana Mancilla(1115)
Raspberry Pi For Dummies by Sean McManus(677)
Computers for Seniors for Dummies by Nancy C. Muir(572)
Windows 10: The Missing Manual by Pogue David(442)
Arduino Uno: A Hands-On Guide for Beginner by Agus Kurniawan(422)
Getting Started with Adafruit FLORA by Becky Stern(392)
Teach Yourself VISUALLY Chromebook by Guy Hart-Davis(391)
Troubleshooting and Maintaining PCs All-in-One For Dummies by Dan Gookin(374)
Samsung Galaxy S6 for Dummies by Bill Hughes(373)
IMac for Dummies by Chambers Mark L.;(315)
2020 Ultimate Guide to Raspberry Pi : Tips, Tricks and Hacks by oney Youssef & oney Youssef(310)
Raspberry Pi: A Step-by-Step Guide For Beginners to Program and Set-Up Top 10 Raspberry Pi Projects + First Steps on Configuration by Cage Jonathan(308)
Software Architecture by Neal Ford(289)
Super Arduino: Step-by-Step Instructions to Build Cool Gadgets by Kenneth Hawthorn(288)
iPad For Seniors For Dummies by Jesse Feiler(286)
Raspberry Pi 4: The Ultimate Step-by-Step Guide to Using Raspbian to Create Incredible Projects and Expand Your Programming Skills with the Latest Version of Raspberry Pi by Liam Clark(285)
Raspberry Pi: Tips and Tricks to Learn Raspberry Pi Programming by Pratt Logan(272)
RASPBERRY PI 4 : A Comprehensive Guide to Raspberry Pi 4 Setup, Learning Programming and Developing Innovative Projects by DENTON DUKE(266)
Arduino new different projects Tachometer utilizing, Advanced Code Lock, Shading Detector, Electronic Voting Machine,Bidirectional Visitor Counter etc.., by Anbazhagan K & Ambika Parameswari K(262)