Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation

Similar presentations


Presentation on theme: "CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation"— Presentation transcript:

1 CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation
Python – Introducing Turtle

2 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

3 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?

4 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

5 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( )

6 Are there “functions” in the real world?
Mom says to Louise “Please, can you go make your bed?“ Specific task: Make bed Parameter(s): None required Returned value: None returned Mom says to Louise “Here’s $5, please, can you go buy a bag of apples?“ Specific task: Parameter(s): Returned value:

7 Are there “functions” in the real world?
Mom says to Louise “Please, can you find my cell phone?“ Specific task: Parameter(s): Returned value: Mom says to Louise “Please, can you put these bags on the kitchen counter?“ Specific task: Put bags on kitchen counter

8 While loop using a sentinel – From our Weekly Exercise 5

9 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

10 Unit 3 - Graphics and Animation
APPLICATIONS In this unit, we’ll learn about the computing science field of graphics and animation ALGORITHMS One of the algorithms we shall learn is called recursion Python We’ll learn about Turtle graphics, functions and loops

11 2. Choose this one, not regular Python
Python (with Turtle) 1. Click on … 2. Choose this one, not regular Python

12 Let’s 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) ? (-100, -100)

13 How about this! Problem statement:
Write a program that draws a chocolate chip cookie with our Turtle

14 But what if I want many cookies?
Solution 1 Could I use a for loop?

15 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! See GPS! Why is that?

16 But what if I want many cookies?
Solution 3: Best solution would be to use a __________________

17 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 __________________ !

18 Review - For next lecture
How do we create a Turtle object, given the turtle module? What is the keyword necessary to make a while loop? What is the keyword necessary to create a function? What is the difference between function parameters and function arguments? What are the commands necessary to create an animation with Turtle? Why do we place our functions at the top of our program?


Download ppt "CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation"

Similar presentations


Ads by Google