Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

Similar documents
In this project, you ll learn how to use a turtle to draw awesome shapes and patterns.

Self-Teach Exercises: Getting Started Turtle Python

LO: To recreate Matisse s Snail in Python

Understanding the Screen

Intro to Python Programming

Computer and Programming: Lab 1

Quick Reference Tables

Interactive Tourist Map

Step 1: Create A New Photoshop Document

Adobe Flash CS3 Reference Flash CS3 Application Window

Create Turtles with Python

Art, Nature, and Patterns Introduction

Exercise 1.1 A First NetLogo Session Turtle commands and properties

In this lesson you are going to create a drawing program similar to Windows Paint. 1. Start with a new project and remove the default cat sprite.

Paint Tutorial (Project #14a)

Adobe Photoshop How to Use the Marquee Selection Tools

CMPSCI 119 LAB #2 Anime Eyes Professor William T. Verts

Python Turtle Graphics The Complete Guide.

Spring CS Homework 3 p. 1. CS Homework 3

Transformation, tessellation and symmetry line symmetry

Honors Computer Science Python Mr. Clausen Program 7A, 7B

[ the academy_of_code] Senior Beginners

Python with Turtle. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : November, More documents are freely available at PythonDSP

Polygons and Angles: Student Guide

Problem Solving with Python Challenges 2 Scratch to Python

CSC 101: Lab Manual#11 Programming Turtle Graphics in Python Lab due date: 5:00pm, day after lab session

Project activity sheet 3

Turtle Graphics and L-systems Informatics 1 Functional Programming: Tutorial 7

Chapter 7. Polygons, Circles, Stars and Stuff

CS 100 Spring 2014 Roadmap to Computing Final May 14, 2014

Name: Tutor s

BIM - ARCHITECTUAL INTRODCUTION TO CLASSES

COMP : Practical 6 Buttons and First Script Instructions

Problem 1.1 (3 pts) :Python uses atomic data types and builds up from there. Give an example of: a. an int b. a double c. a string

A cipher is a type of secret code, where you swap the letters around so that noone can read your message.

CMPSCI 119 LAB #2 Greebles / Anime Eyes Professor William T. Verts

Introduction to Flash - Creating a Motion Tween

CISC 1600 Lecture 3.1 Introduction to Processing

Welcome to the Turtle World of Logo

Activity Guide APIs and Using Functions with Parameters

A First Look at Logo

My First iphone App. 1. Tutorial Overview

Day 1: Introduction to MATLAB and Colorizing Images CURIE Academy 2015: Computational Photography Sign-Off Sheet

Grade 6 Math Circles. Shapeshifting

Unit Using Logo Year Group: 4 Number of Lessons: 4

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

TSM Report Designer. Even Microsoft Excel s Data Import add-in can be used to extract TSM information into an Excel spread sheet for reporting.

Introduction to VPython for E&M This tutorial will guide you through the basics of programming in VPython

Monday 9 June 2014 Afternoon

roboturtle Documentation

Introduction to Desktop Publishing

Self-Teach Exercises 1-12 Turtle Pascal

OrbBasic LESSON 1 Goto and Variables Student Guide

CS Problem Solving and Object-Oriented Programming

Creating a new syntax file 1. In the toolbar Go to File > New > Syntax 2. The syntax window will appear

Lesson 1 New Presentation

NetLogo Lab 3 Tutorial: Finding Peaks

Making a maze with Scratch

Introduction to the Turing Programming Language program commands run Exercise #1 not var put get put Programming Names File/Save As..

Create a Cool Vector Robot Character in Illustrator

Othello Turtle Extra Credit (20 points) Due Sunday, Nov 29 (really!)

MITOCW watch?v=se4p7ivcune

CS 100: Gates and Drawing and Turtles

An Introduction to Processing

Update Your Profile & Membership Directory Listing

1. Navigation and menus

BEGINNER PHP Table of Contents

Introduction to Google SketchUp

INKSCAPE INTRODUCTION COMPONENTS OF INKSCAPE MENU BAR

Creating Digital Illustrations for Your Research Workshop III Basic Illustration Demo

Unit 21 - Creating a Navigation Bar in Macromedia Fireworks

A Step-by-step guide to creating a Professional PowerPoint Presentation

CMPSCI 119 LAB #4 Fish Tank Professor William T. Verts

I put a shortcut onto your desktop, the screen that you look at after you log in.

Continental Mathematics League

CLASS 3. Lesson 1: Know your Computer

Adobe Illustrator. Always NAME your project file. It should be specific to you and the project you are working on.

Logo & Brand Identity Guidelines. Media Sonar Technologies

Coordinates - Activity 1 Plotting whole number ordered pairs.

5. LAPTOP PROCEDURES

Starting. Read: Chapter 1, Appendix B from textbook.

5. Introduction to Procedures

Computer learning Center at Ewing. Course Notes - Using Picasa

CS Lab 8. Part 1 - Basics of File I/O

Lesson 18: Animation. Computer Programming is Fun!

DOING MORE WITH WORD: MICROSOFT OFFICE 2013

Mathematics 43601F. Transformations. In the style of General Certificate of Secondary Education Foundation Tier. Past Paper Questions by Topic TOTAL

Using Formulas and Functions in Microsoft Excel

Blender Lesson Ceramic Bowl

FUN TECH TIPS 101 SUMMER CLOVIS UNIFIED SCHOOL DISTRICT INFORMATION TECHNOLOGY SERVICES Prepared by Tanie McKinzie, TSS III

CS100 Spring 2017 Final

SMART Notebook Handbook Old Vicarage School SMART Notebook 18.1 Handbook. Guy Colnbrook Page 1 of 64

Get comfortable using computers

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

c. Typically results in an intractably large set of test cases even for small programs

GETTING AROUND STAGE:

Beyond Captioning: Tips and Tricks for Accessible Course Design

INFORMATION TECHNOLOGY

Using Excel to produce graphs - a quick introduction:

Part II: Creating Visio Drawings

Transcription:

Raspberry Pi Learning Resources Turtle Snowflakes Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python. How to draw with Python Turtle 1. To begin, you will need to open the Python 3 programming environment IDLE3. You can do this by selecting it from the Main Menu with your mouse. 2. Then click on File and New Window to open a blank text editor window to write your code in. 3. Save your empty file by clicking on File, Save As and naming it snowflake.py. 4. To begin using Turtle in Python you need to import the Turtle library. At the top of the text editor window type import turtle. 5. Next, a command is needed to create the window which will display your turtle drawings: turtle.screen(). To save having to type it out every time you need the command, you can store it as a variable: wn = turtle.screen() Note: There is a capital letter used here for Screen. It is important to get uppercase and lowercase syntax correct in Python in order for your code to work. 6. Time to give your turtle a name; you can use a variable to do this. I'm naming my turtle

Elsa but you can name yours whatever you like. elsa = turtle.turtle() 7. Now you can tell your turtle what to do; for example, to move forward 100. Give it a go. 8. To complete your first turtle program, add wn.exitonclick() ; this means that the turtle window will stay open so you can see your drawing for as long as you like. It will only close when you click on the x in the top right hand corner of the window with your mouse. wn.exitonclick() 9. Click on File and Save, and then click on Run and Run Module to run your first turtle program. What happens? How to turn with Python Turtle

Your turtle is pointing in one direction, which is good news if you want to draw a line, but it is time to think about drawing a shape like a square! 1. Underneath the line in your Python code, add: Note: Turtle uses angles in degrees. There are 360 degrees in a circle. How many are in the right angle of a square? That's right: 90. The value 90 inside the brackets in is in degrees. So this line is telling your turtle to turn right by 90 degrees. 2. Add another instruction underneath to move your turtle forward by 100: 3. Save and run your code to see what happens. 4. You are on your way to creating a square. What do you need to add to your code in order to complete the square? Using loops to create shapes To create a square, you have repeated some lines of code. It is not the most efficent way of doing it. Instead of typing out many lines of code, it makes more sense to use a loop. Instead of code to create a square like this:

You can type: for i in range(4): Try it yourself and see what happens when you save and run your code. Creating spiral patterns Don't be a square! Let's create some different shapes and repeat them to make a snowflakelike spiral. 1. Replace the code for your square with the following: for i in range(2): elsa.right(60) elsa.right(120)

It will draw a shape called a parallelogram. You can see what it looks like by saving and running your code. 2. You can put loops inside of other loops. This is good news for us as we can make a drawing that looks like a snowflake. Above for i in range(2): type: for i in range(10): How many times will this loop go round? 3. Move to the bottom of your sequence of code and press the space bar four times to indent your code. Indentation in Python is very important to ensure that your code works as you expect. Then type: elsa.right(36) 4. Save and run your code to see what happens. You should see a drawing like this:

Changing the pen colour randomly So far the turtle has been drawing black lines on a white background. Time for some colour! To set the colour of the turtle, use the following instruction underneath the naming of your turtle and before the loops: elsa.color("cyan") Note: The spelling of colour is different in other countries. In the US it is spelled 'color' and in Python it has to be spelled in the American way for it to work. I have chosen to use the colour cyan but you can use any from this list: "blue" "magenta" "grey" "purple" You can also change the colour of the background window. To set the colour of the

background use this instruction: wn.bgcolor("blue") For fun you can add a random colour for your turtle, so that every time you run your code you will get a slightly different result. 1. First you will need to import the random library. Underneath import turtle type import random. 2. Next, change the background colour from "blue" to "grey". 3. Below, create a variable called colours to store a list of the colours to select from, like this: colours = ["cyan", "purple", "white", "blue"] 4. At the end of the spiral loop, underneath elsa.right(36), type: elsa.color(random.choice(colours))

5. Save and run your code for a multi-coloured snowflake! Using a function to draw a snowflake Your parallelogram snowflake is cool, but it does not look as snowflake-like as it could. Let's fix that! 1. For this drawing, we need to move the turtle from starting in the centre of the window. The penup() and pendown() instructions allow this to happen without drawing a line. It's like picking up a real pen from the paper and moving it somewhere else to start to write. Type the following instructions underneath the colours list: elsa.penup() elsa.forward(90) elsa.left(45) elsa.pendown() 1. Next, define a function by typing: def branch():

Note: The code to draw one branch of the snowflake will be stored inside this function, so that you can repeat it over and over to create an entire snowflake. 1. Remove the code for the parallelogram snowflake loops and replace it with: for i in range(3): for i in range(3): elsa.forward(30) elsa.backward(30) elsa.right(45) elsa.left(90) elsa.backward(30) elsa.left(45) elsa.forward(90) Note: Remember that indentation is important. Make sure that you check your indentation is correct or your code might not work! 2. The last section of this code will call the snowflake function and repeat it eight times. You can use a loop in the same way as with the last snowflake: for i in range(8): branch() elsa.left(45) 3. Use a # at the start of the elsa.color(random.choice(colours)) instruction to turn it into a comment. This means that the computer will skip that line of code. You could delete the line, but you might want to use it to add colour to your snowflake later on. 4. Save and run your code, and a snowflake should appear before your eyes!

What next? Can you uncomment the random colour instruction and place it in the function, so that each branch has a different colour? Can you create a snowflake function and then repeat it all over the window? Can you have many snowflakes of different colours and different sizes?