
Introduction to Graphics and Animation with Turtle in Python
This week's lecture covers graphics and animation using Turtle in Python. The content includes information on weekly exercises, lab activities, software development processes, functions, incremental software development, and real-world function examples. The incremental software development process is explained using an Encryption/Decryption program as an example. Various functions and their characteristics are detailed, and real-world scenarios demonstrating the concept of functions are provided.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
CMPT 120 Lecture 15 Unit 3 Graphics and Animation Python Introducing Turtle
This week, we will have Weekly Exercise 6 Lab Functions and Turtle Posted beside our Weekly Exercise 6 To be done during Wednesday s open lab in CSIL or on your own time Not submitted, not marked but an opportunity for you to practice developing software using Python Solutions will be posted on Friday June 14 Assignment 1 Will be posted on our course web site this week 2
Last week, we looked at What are these comments? Why are we returning plain? Should we not be returning cipher instead? Why are we returning cipher? Should we not be returning plain instead? 3 https://repl.it/repls/TimelyJovialAssociate
Software Development Process Incremental Software development Part of the software development process is the idea of developing a program (software) incrementally one piece at a time Once this piece has been tested and shown to work, we move on to the next piece Example of incremental software development using our Encryption/Decryption program (with functions) Piece 1 -> Main part of program + functions encrypt() and decrypt() without body -> called STUB Piece 2 -> Implement encrypt() function -> change return value from plain to cipher Piece 3 -> Implement decrypt() function -> change return value from cipher to plain 4
Solution: Different kinds of functions Activity: Fill this table using functions we have used so far! Function takes parameters Function does not take parameters Function returns a result (i.e., a returned value) upper( ) <- does not take parameters strip( ) len( ) input( ) upper( ) strip( ) input( ) isalpha( ) Function does not return a result (i.e., a returned value) print( ) print( ) 5
Are there functions in the real world? 1. Mom says to Louise Please, can you go make your bed? Specific task: Make bed Parameter(s): None required Returned value: None returned 2. Mom says to Louise Here s $5, please, can you go buy a bag of apples? Specific task: Parameter(s): Returned value: 6
Are there functions in the real world? 3. Mom says to Louise Please, can you find my cell phone? Specific task: Parameter(s): Returned value: 4. Mom says to Louise Please, can you put these bags on the kitchen counter? Specific task: Put bags on kitchen counter Parameter(s): Returned value: 7
While loop using a sentinel From our Weekly Exercise 5 8 https://repl.it/repls/IdenticalInterestingScans
Unit 3 - Graphics and Animation Pixar movies and your favourite 3D animated films these days are built with code Indeed, animated movies and video games today rely heavily on 2D and 3D graphics and animation technology In this unit, we ll make basic animations using code, and learn how to build complex and beautiful graphics 9
Unit 3 - Graphics and Animation 1. APPLICATIONS o In this unit, we ll learn about the computing science field of graphics and animation 2. ALGORITHMS o One of the algorithms we shall learn is called recursion 3. Python o We ll learn about Turtle graphics, functions and loops 10
Python (with Turtle) 1. Click on 2. Choose this one, not regular Python 11
Lets try it! Problem Statement: Write a program that draws a blue square with our Turtle We may need to know the Turtle coordinate system: ? (100,100) (0,0) 12 ? (-100, -100)
How about this! Problem statement: Write a program that draws a chocolate chip cookie with our Turtle 13
But what if I want many cookies? Solution 1 Could I use a for loop? 14
But what if I want many cookies? Solution 2: Could I copy and modify the code many times, each instance drawing one cookie? Hum This solution would lead to a lot of repeating code, which is not a good idea! Why is that? See GPS! 15
But what if I want many cookies? Solution 3: Best solution would be to use a __________________ 16
But what if I want many cookies? But our function draws many cookies in the same spot! We have not solve our problem! Solution 4: So, the ultimate solution would be to design our function such that it takes __________________ ! 17
Review - For next lecture 1. How do we create a Turtle object, given the turtle module? 2. What is the keyword necessary to make a while loop? 3. What is the keyword necessary to create a function? 4. What is the difference between function parameters and function arguments? 5. What are the commands necessary to create an animation with Turtle? 6. Why do we place our functions at the top of our program? 18