CISC101 Reminders Assignment 2 due this Friday.

Slides:



Advertisements
Similar presentations
Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Advertisements

Agent P, I have been hearing some rumours about a Python Turtle.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
ForLoopsInAlice1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009 Counted (For) Loops in Alice.
Getting started with the turtle Find the latest version of this document at
Let’s Learn 3. Modules Saenthong School, January – February 2016
Functions. functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
COMPSA Exam Prep Session by Paul Allison On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
See Winter 2016CISC101 - Prof. McLeod1.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Today… Strings: –String Methods Demo. Raising Exceptions. os Module Winter 2016CISC101 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Today… Files from the Web! Dictionaries. Lists of lists. Winter 2016CISC101 - Prof. McLeod1.
Next Week… Quiz 2 next week: –All Python –Up to this Friday’s lecture: Expressions Console I/O Conditionals while Loops Assignment 2 (due Feb. 12) topics:
Today… Loops and Drawing, Cont. –Two slightly more advanced demos. Collections Overview. Winter 2016CISC101 - Prof. McLeod1.
Using the Python Turtle
MOM! Phineas and Ferb are … Aims:
Graphics CIS 40 – Introduction to Programming in Python
CMPT 120 Topic: Python Modules.
CISC/CMPE320 - Prof. McLeod
CISC101 Reminders Last lecture!  Grading of Quiz 4 underway.
CISC101 Reminders Grading of Quiz 4 underway.
Paddle Ball! We will begin creating, in steps, a video game similar to ‘brick breaker’ or ‘pong’, were we can move paddles to hit a bouncing ball. I hope.
Agent P, I have been hearing some rumours about a Python Turtle.
Winter 2018 CISC101 11/9/2018 CISC101 Reminders
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
CISC101 Reminders Quiz 2 this week.
CISC101 Reminders Assn 3 due Friday, this week.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
Winter 2018 CISC101 11/19/2018 CISC101 Reminders
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
CISC101 Reminders Slides have changed from those posted last night…
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Module 2 Lesson 3 Over and Over Again
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Winter 2018 CISC101 12/5/2018 CISC101 Reminders
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
CISC101 Reminders Quiz 2 this week.
CISC124 Assignment 4 on Inheritance due next Friday.
CISC124 Assignment 3 due tomorrow at 7pm.
CISC124 Assignment 4 on Inheritance due next Friday.
Section 3 Programming with Turtle Graphics
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
CMPE212 – Reminders The other four assignments are now posted.
CISC101 Reminders All assignments are now posted.
CMPE212 – Reminders Assignment 2 sample solution is posted.
CMPE212 – Reminders Assignment 3 due next Friday.
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
CISC101 Reminders Quiz 1 marking underway.
Winter 2019 CISC101 4/29/2019 CISC101 Reminders
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
CMPE212 – Reminders Quiz 1 marking done. Assignment 2 due next Friday.
Module 2 Lesson 3 Over and Over Again
CMPE212 – Reminders Assignment 2 due today, 7pm.
Mod 2 Lesson 2 Repeating with loops
Module 2 Lesson 3 Over and Over Again
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
CISC101 Reminders Assignment 3 due today.
Winter 2019 CISC101 5/30/2019 CISC101 Reminders
CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation
Presentation transcript:

CISC101 Reminders Assignment 2 due this Friday. Winter 2019 CISC101 4/14/2019 CISC101 Reminders Assignment 2 due this Friday. Quiz 2 this week, as well. See updated Quiz topics listed in Friday’s lecture. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Today Introduce the use of the turtle module. Winter 2019 CISC101 4/14/2019 Today Introduce the use of the turtle module. Use the turtle to illustrate more examples of iteration. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Turtle Graphics The “Turtle” is an easy way of drawing to the screen. CISC101 Turtle Graphics The “Turtle” is an easy way of drawing to the screen. One use is to illustrate how loops work. See the first section in “Program Frameworks” in the Python Standard Library. To start you’ll need to import the turtle module: from turtle import * Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Aside – Importing Modules Normally, you would use a simpler import statement, like: import random To use a function from this module, you would write, for example: dice1 = random.randint(1, 6) So, you need to keep naming the module to obtain its members. Winter 2019 CISC101 - Prof. McLeod

Aside – Importing Modules, Cont. A more involve import is, for example: from math import * Now, instead of having to say math.sqrt(), you can just say sqrt(). You don’t have to keep using the module name. Since we will be using so many turtle functions, it is easier to import as in: from turtle import * Winter 2019 CISC101 - Prof. McLeod

Aside – Importing Modules, Cont. While this usage looks like it would be quite convenient, you need to be cautious and not use it with more than one or two imports at a time. What would happen if two imports contain one function or more with the same name? Which one would you get? Winter 2019 CISC101 - Prof. McLeod

A Few turtle Commands To make the turtle look like a “turtle”: shape(“turtle”) To set the line thickness and line colour: pensize(5) pencolor(“green”) The turtle starts out at the “home” position, (0, 0), facing right or “east”. To draw, just issue commands to move the turtle. Winter 2019 CISC101 - Prof. McLeod

A Few More turtle Commands Turning: right(num_degrees) # clockwise left(num_degrees) # counter-clockwise Moving in the direction he is pointing; forward(length) Changing speed: speed(5) # 0 is no animation, 1 slow 10 fastest Winter 2019 CISC101 - Prof. McLeod

turtle Demos Start with five demo programs that illustrate turtle commands. These five do not have any iteration. Start with TurtleDemo1.py Winter 2019 CISC101 - Prof. McLeod

Filling Commands Use begin_fill(), then draw, followed by end_fill() to fill a closed, drawn area. See TurtleDemo2.py See TurtleDemo3.py to see how to draw a filled circle. Winter 2019 CISC101 - Prof. McLeod

Regular Polygons Modify how circle() is invoked to draw regular polygons instead of circles. See TurtleDemo4.py Draw text, too! See TurtleDemo5.py Fun! Winter 2019 CISC101 - Prof. McLeod

Turtle Loop Demos The turtle can use loops to draw many similar figures one after the other without a lot of extra code. These demos will show loops, nested loops and the use of conditionals inside loops. Winter 2019 CISC101 - Prof. McLeod

while Loop Demo Draw 10 squares with turtle, one inside the other. CISC101 while Loop Demo Draw 10 squares with turtle, one inside the other. See TurtleLoopDemo1.py In essence: size = 40 while size <= 400 : # drawing stuff size = size + 40 Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Nesting Loops, Example A loop can be useful in preventing repetitious coding practice. Can you see any part of the previous example that is repetitive? How would you fix it? See TurtleLoopDemo2.py Every time the outer loop iterates once, the inner loop iterates 3 times. Also note the use of the speed(0) setting… Winter 2019 CISC101 - Prof. McLeod

Nesting Loops, Example Cont. A more compact version that takes advantage of two more turtle functions: TurtleLoopDemo2Alt.py Uses goto(x, y) to move to a corner of the square. (Think of the transporter in Star Trek…) Uses setheading(angle) to make the turtle point South. Inner loop iterates four times now. while loop is changed to a for loop. Winter 2019 CISC101 - Prof. McLeod

Turtle Squares Again Alternate red and blue squares. See TurtleLoopDemo3.py Uses for loops. Shows an if statement inside the loop. Every time the outer loop iterates once, the if statement executes once. How can you change the code to have just the top side of the red square drawn in green? Draw the bottom side of the blue square in green? Winter 2019 CISC101 - Prof. McLeod

Random Walk See “Random Walk” in Wikipedia. Think of a drunk turtle staggering through a regular grid of city streets. Used to model any sort of random population movement. Brownian Motion, for example. See RandomWalk.py Advanced features include the use of a tuple to store possible direction choices. Winter 2019 CISC101 - Prof. McLeod

Spiral of Theodorus Supposedly invented by the ancient Greek philosopher Theodorus as a geometric means of estimating square roots. It consists of a set of contiguous right angle triangles, drawn as shown: Winter 2019 CISC101 - Prof. McLeod

Spiral of Theodorus, Cont. See FilledTheodorusSpiral.py Draws the spiral and fills the triangles with a gradation of colour. Uses a tkinter dialog to allow the user to choose colours for the start and end of the gradation. More tkinter towards the end of this course! Winter 2019 CISC101 - Prof. McLeod