Let’s see what we can draw on Python!

Slides:



Advertisements
Similar presentations
The Peanut Butter & Jelly Computer Instructor’s Handout (modified from zerorobotics and CS10K Community handouts) KEY CONCEPTS Software and hardware work.
Advertisements

Making a “P and J” sandwich
How to make a peanut butter and jelly sandwich
How to Make a Peanut Butter and Jelly Sandwich By Kristy and Jon.
By Droids Robotics Good Coding Practices: Start with Pseudocode BEGINNER EV3 PROGRAMMING LESSON © 2015 EV3Lessons.com, Last edit 4/1/
Programming in Python Turtle Graphics Dr. Kristine Nagel Genie Yang Raquel Lawrence Dr. Kristine Nagel Genie Yang Raquel Lawrence Georgia Gwinnett College.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
StarLogoTNG Treasure Hunt Game Unit Lesson 1: Basic Movement.
By: Rachel Kenney. First Step Get a plate and bread out.
Explanation of Web 6, Web 7 and Web 9 at my site Please be sure to bring up the speaker notes for the explanation Intro - Web 6, Web 7 and Web 9.
1 Exercise Two The Digital Camera Helpful Notes 2004.
How to make a Peanut Butter and Jelly Sandwich!
Computer Bugs Original Powerpoint By: Spring LIS4480 Coding Team Jon.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Introducing Scratch the Cat
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 2.
TURTLE GRAPHICS IP MR. MELLESMOEN. LOGO IN THE 1970’S THERE WAS A SIMPLE BUT POWERFUL PROGRAMMING LANGUAGE CALLED LOGO THAT WAS USED BY A FEW.
Introduction to Using the Notebook 10 Software for SMART Board Day 2 LIVINGSTON PARISH PUBLIC SCHOOLS Facilitated by S. Waltman.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
How to Make the Perfect PB&J By: Jade Edwards. Materials Needed: ➾ 2 slices of white bread ➾ 1 jar of peanut butter ➾ 1 jar of grape jelly ➾ 1 paper plate.
Learning PowerPoint Presenting your ideas as a slide show… …on the computer!
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Drawing pictures … It’s not art, it’s fun.
Presented by: Mr. Pugh’s Class 2011 Ingredients Peanut Butter Jelly Two Slices of Bread.
Computer Science Unplugged Dr. Tom Cortina Carnegie Mellon University Sponsored by.
Intro to Turtle Graphics (Part 2)
Turtle Graphics Let’s see what we can draw on Python!
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
LOGO WHAT IS IT? HOW TO USE IT AND HOW USEFUL CAN IT BE?
What is it? How to use it and how useful can it be?
Introducing the turtle
Informational Writing (Procedural) ELACC5W2: Write informative/explanatory texts to examine a topic and convey ideas and information clearly. EQ: How can.
Create a Halloween Computer Game in Scratch
Graphics CIS 40 – Introduction to Programming in Python
An Introduction to Alice (Short Version)
SketchUp Chocolate Level of Difficulty Time
Going Green By Ima Librarian
Formatting Output.
Principles of Programming I (CIE 105)
Forces and Magnets – Block 3FM
A Tiny Look at the Graphics Window
Learning to program with Logo
BEGINNER PROGRAMMING LESSON
Adobe illustrator.
The procedure.
Microsoft® Small Basic
Teaching Java using Turtles part 2
How to make a peanut butter & jelly sandwich
BEGINNER PROGRAMMING LESSON
An Introduction to Alice
Go to =>
Go to =>
Suppressing print Newline
Go to =>
Objective Given this activity, the students will be able to make the perfect peanut butter and jelly sandwich by following the steps in order.
BEGINNER PROGRAMMING LESSON
Introduction to Turtle Graphics
Nested If Statements While Loops
Robotics Week 4 Functions and reusable code
Lawrence Snyder University of Washington, Seattle
A Tiny Look at the Graphics Window
For this test you will be asked to remember the colors of words that are briefly presented on the computer screen. After several have been presented you.
Basic Processing … Drawing pictures … It’s not art, it’s fun
Chapter 1 Introducing Small Basic
Creating a Simple Game in Scratch
Developing A Good Procedure
Teaching Java using Turtles part 2
Instructional Focus Lesson Plan Reading 2.3 Grade 1
Presentation transcript:

Let’s see what we can draw on Python! Turtle Graphics Let’s see what we can draw on Python!

Turtle Graphics Turtle graphics is a method of programming “vector” graphics using a relative cursor upon a Cartesian plane (in other words, Turtle uses the foundation of a coordinate plane in order to help draw it’s graphics) Python has a built-in module that supports turtle graphics called “turtle” Importing this module gives you access to all the functions necessary in order to draw vectors on the screen

Turtle Graphics In Turtle, you control a cursor, also know as the “turtle” It has the following properties: A position in 2D space on the coordinate plane An orientation, or heading A pen that can lay down color on the canvas

Setting up your environment #first we need to import the turtle module import turtle # set a title for your window turtle.title(“My turtle animation”) # set up the screen size (in pixels – 400 x 400) # set up the starting point of the turtle (0,0) – origin turtle.setup(400,400,0,0)

Setting up your environment Because we are unable to download Python onto our computers, we will be using a website called: https://trinket.io/python However this website was somewhat created for the sake of using Turtle, not so much Python in it’s entirety So, the environment is already set up for you as a 400 x 400 canvas window and the turtle is set to start at the origin (0, 0)

trinket.io/Python

Important Note! Do not name your Python source code file “turtle.py” This will prevent Python from finding the correct “turtle.py” module when using the import turtle statement at the top of your program

Getting rid of your turtle window This function call will cause your turtle window to deactivate when you click on it. Place it at the end of your turtle program. turtle.exitonclick() This will not be applicable on our website

Basic Turtle Functions You can move your turtle forward by using the following command: turtle.forward(pixels) #pixels can also be denoted by the number of spaces you want to move And you can have your turtle turn by using the following commands: turtle.right(degrees) turtle.left(degrees) Your turtle will continually “draw” while it’s moving

Programming Challenge Draw a box!

Programming Challenge Draw a regular pentagon

Programming Challenge Try drawing a star!

Moving your turtle You can also command your turtle to move to any coordinate on the screen by using the turtle.goto() function This function accepts two arguments, x and y, denoting the x and y coordinates on the coordinate plane turtle.goto(50,50) Note however that your pen will continue to draw as you move your turtle to a new position

Moving your turtle You may have guessed that if your pen keeps on drawing, you may end up with a bunch of lines that you might not want … You can tell the turtle to stop drawing by using the turtle.penup() function. You can tell the turtle to start drawing again by using the turtle.pendown() function

Programming Challenge Try drawing three stars!

Review: Peanut Butter Jelly Time! Remember this guy …

Review: Peanut Butter Jelly Time! Recall that in the beginning of the year we learned that software is basically a set of instructions for your computer Remember, computers may be powerful but they’re really not all that smart! We’ve learned that we need to be very precise in our instructions as computers are very obedient, but they won’t think for themselves.

Review: Peanut Butter Jelly Time! Well, let’s look at some of the “software” we created before practicing programming … Example 1: Walk to the kitchen. Walk towards the cabinets. Take a plate out of the cabinet. Walk towards the counter that has the bread. Put a slice of bread on your plate. Walk towards the toaster. Put the bread in the toaster.

Review: Peanut Butter Jelly Time! Toast the bread. Walk to the refrigerator. Take out the peanut butter and Nutella jars. Walk towards the utensil drawer. Take out two butter knives. Open the jars. Use one knife for peanut butter and spread peanut butter on one side of the toast.

Review: Peanut Butter Jelly Time! Example 2: Get the peanut butter and jelly. Get two slices of bread. Open the peanut butter. Take some of the peanut butter and spread it. Then, take some jelly and spread it. Put bread together and eat.

Review: Peanut Butter Jelly Time! Now that we’ve had some practice with programming and we understand just how specific we need to be, let’s try this again! Write out a set of instructions for your robot at home that will allow it to successfully make a peanut butter and jelly sandwich. This does not necessarily mean your program needs to be longggg and include every minute detail, we just need to be sure to include all steps (concise, is nice!)

Review: Peanut Butter Jelly Time! Example 3: Hello. First walk into the kitchen. Walk towards the pantry. Grasp the handle. Pull outwards until pantry is open. Reach into the pantry and grasp the peanut butter jar. Retract your arms backward. Turn 90 degrees. Walk towards counter and place jar on counter by removing your grasp of the jar. Walk towards the pantry and grasp the bag of bread with one hand. With the other grab the jar of jelly. Retract both hands inward, turn 90 degrees, and walk back towards the counter. Place the bread and the jelly on the counter. Walk towards pantry again just as before and remove a plate and a knife and spoon. Carry the spoon and knife in one hand and the plate with the other. Close the pantry. Take the plate, spoon, and knife back to counter and place on counter. Take hold of the top of the peanut butter jar. Turn your hands until top removes itself. Place top on counter. Take hold of the top of the jelly jar. Turn your hands until top removes itself. Grab bag of bread and undo twisty-tie. Remove twisty tie. Open bag of bread. Grab two slices of bread. Remove two slices of bread and place on plate. Close bag of bread. Take hold of the knife and position your hand above the jar of peanut butter. Lower the knife into the jar of peanut butter. Turn the knife as it’s in the peanut butter to get some on the knife. Remove the knife gently from the jar and bring knife over to either slice of bread on the plate. Lower the knife with peanut butter onto the bread and slide back and forth until it is covered with peanut butter. Place knife on the plate. Grab hold of the spoon and position it over the jar of jelly. Lower the spoon into the jar and scoop up some jelly. Remove spoon from jar and bring spoon over to the other slice of bread. Dump the jelly from the spoon onto the bread and spread back and forth. Now, take hold of the slice of bread with peanut butter and pick it up on the sides so as to not touch the peanut butter. Turn it over (180 degrees) and place it on top of the piece of bread with jelly so as the shapes match. Eat.

Review: Peanut Butter Jelly Time! In addition, create at least TWO functions, for activity that we might see ourselves repeating throughout the process. Example:

Review: Peanut Butter Jelly Time! In addition, create at least TWO functions, for activity that we might see ourselves repeating throughout the process. Example: def spread(type): - pick up knife - dip in type of jar - scoop some spread out of jar - place knife with spread facing bread at top right corner on blank side of bread - evenly spread throughout one side of bread

Review: Basic Turtle Functions Okay, now let’s get back to Python Remember, we learned a few instructions that turtle understands in Python: turtle.forward(spaces) turtle.right(degrees) turtle.left(degrees) Note that we have both a function for turning left AND turning right, but maybe this wasn’t always the case …

Meet Karel This is Karel … Karel was a programming language created to help beginners understand the precision of instructions necessary when programming a computer. Unfortunately, Karel only knows two directional commands: >> move – moves forward one coordinate >> turnLeft – turns left 90 degrees

Meet Karel So, how the heck does Karel turn right?

Meet Karel The Karel language also allows for users to create functions, which is where the turnRight function comes from def turnRight(): turnLeft()

Review: Basic Turtle Functions We learned a few more: turtle.goto( x_coor, y_coor ) turtle.penup() turtle.pendown() Remember that whenever you pick the pen up, you need to put it back down if you want to begin drawing again. Also, by default, turtle will begin drawing when first starting a program. In other words, you do not need to begin by calling turtle.pendown()

Review: Basic Turtle Functions We also briefly took a look at this function: turtle.speed(level) This function takes one float argument, denoting the speed at which the turtle draws. You can pass arguments as large as you want but at a certain point, turtle will be moving as quick as it can. Give it a break … It seems you can pass an argument as long as it is greater than 0.5. Any argument less than or equal to 0.5 will just cause turtle to fly through your instructions.

Pen Color By default, turtle will draw solid black lines However, you can change the color of your lines by calling the function: turtle.pencolor(“color_code”) This function accepts one argument, which is the color code. Note: the color code must be inside of delimiters!

RGB Color The color value can be a standard Red Green Blue (RGB) color code. # this is to set the color as red turtle.pencolor(“#FF 00 00”) # this is to set the color green turtle.pencolor(“#00 FF 00”) # this is set the color blue turtle.pencolor(“#00 00 FF”)

RGB Color RGB color codes define how much red, green and blue should be mixed into a given color They are divided into three channels: - the first two characters denote the amount of red - the second two characters denote the amount of green the third two characters denote the amount of blue Color code: “ # 00 00 00 ”  this would be black Note that they do not need to be spaced out Note also that most color codes begin with a # symbol

RGB Color RGB uses a number system called “hexadecimal” Hexadecimal (or “hex”) is a base 16 number system. This means it uses 16 digits to represent numbers Counting in hex: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F You’ll notice that here the 11th to 16th digits are represented by letters

RGB Color #000000  this denotes black #FFFFFF  this denotes white #FF0000  this denotes all red #00FF00  this denotes all green #0000FF  this denotes all blue

RGB Color Resources Web based color tools/websites: http://cloford.com/resources/colours/500col.htm http://paletton.com/#uid=14r0u0kllllaFw0g0qFqFg0w0aF

Programming Challenge: RGB Squares Draw three squares in different colors. One in red, one in green and one in blue.

Fill Shape Command We can also fill in our shapes with colors: turtle.fillcolor(“color_code”) turtle.begin_fill() turtle.end_fill()

Programming Challenge: RGB Squares Draw three squares in different colors. One in red, one in green and one in blue.