1.5.3 Walkthrough #4 bouncing_ball.py wrapping_ball.py

Slides:



Advertisements
Similar presentations
Beauty in Recursion, Fractals Gur Saran Adhar Computer Science Department.
Advertisements

Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
CS 112 Introduction to Programming
Computer Science: A Structured Programming Approach Using C Converting File Type A rather common but somewhat trivial problem is to convert a text.
Software Engineering 1. Introduction 2. Course schedule.
Designer contractor engineers Builders Owner.
R ECURSION. O VERVIEW Definition of Recursion Where recursion is used Recursion in Factorial (!n)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
CS 101 Course Summary December 5, Big Ideas Abstraction Problem solving Fundamentals of programming.
CSE 326: Data Structures Lecture #25 EOQ Steve Wolfman Winter Quarter 2000.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 9.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 9/18/2009.
Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into.
General Computer Science for Engineers CISC 106 Lecture 08 James Atlas Computer and Information Sciences 9/21/2009.
ALICE 3D PROGRAM WORKSHOP. ALICE & MATHEMATICS Using Alice in Mathematics Using 3D Graphics to add in the understanding of math concepts.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 – Recursive Funtions From Deitel’s “C” Book 5.13Recursion 5.14Example Using Recursion: The Fibonacci.
CS 146: Data Structures and Algorithms June 18 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
August 19, August 19, 2015August 19, 2015August 19, 2015 Azusa, CA Sheldon X. Liang Ph. D. CS 470 Software Engineering I Azusa Pacific University,
12-1 Arithmetic Sequences and Series. Sequence- A function whose domain is a set of natural numbers Arithmetic sequences: a sequences in which the terms.
Welcome to Computer Science at Missouri S&T Daniel TauritzDan Lin Associate Professor Assistant Professor Margret A. Steele undergraduate.
Computer Science Lego Robotics Lab 07 Page 51. CS Lego Robotics Lab 07 (Updated ) Objectives: 1.Extend the Lego robot with three sensors. 2.Program.
1 K.Becker & J.R.Parker Serious Games + Computer Science = Serious CS.
CS 6068 Parallel Computing Fall 2013 Lecture 10 – Nov 18 The Parallel FFT Prof. Fred Office Hours: MWF.
CS-2852 Data Structures LECTURE 12B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Computer Science: A Structured Programming Approach Using C1 6-9 Recursion In general, programmers use two approaches to writing repetitive algorithms.
Algorithmic Recursion. Recursion Alongside the algorithm, recursion is one of the most important and fundamental concepts in computer science as well.
Chapter 13: Sequences & Series L13.2 Recursive Definitions + Function Iteration.
computer
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions (Recursion) Outline 5.13Recursion 5.14Example.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Recursive Solutions Recursion is an extremely powerful problem-solving.
Optimization revisited Prof. Noah Snavely CS1114
Sequences, Series, and Sigma Notation. Find the next four terms of the following sequences 2, 7, 12, 17, … 2, 5, 10, 17, … 32, 16, 8, 4, …
Algorithms: Branching and Iteration (in Scratch)
Computer Engineering School of Engineering at Fairfield University Prof. D. Lyon, Chair, Computer Engineering
A Brief Introduction to Recursion. Recursion Recursive methods … –methods that call themselves! –They can only solve a base case –So, you divide a problem.
1 CSE1301 Computer Programming: Where are we now in the CSE1301 syllabus?
March 19, March 19, 2016March 19, 2016March 19, 2016 Azusa, CA Sheldon X. Liang Ph. D. Software Engineering in CS at APU Azusa Pacific University,
Image from
16CS202 & Software Engineering
In what areas does engineering and C.A.D overlap?
In what areas does engineering and C.A.D overlap?
Introduction to Recursion
Topic: Recursion – Part 1
P.Kiruthika/ CS6403/Introduction
Sequences and Series.
Splash Screen.
Introduction to Computer Science - Alice
3-7 Sample Programs This section contains several programs that you should study for programming technique and style. Computer Science: A Structured.
12.5 use recursive rules w/ sequences & functions
Student Feedback on Robotics in CS1 The Fleet!
Cs212: DataStructures Computer Science Department Lab 3 : Recursion.
CS-401 Computer Architecture & Assembly Language Programming
CMSC201 Computer Science I for Majors Lecture 17 – Recursion (cont)
Notes Over 11.5 Recursive Rules
I UNDERSTAND CONCEPTS OF MULTIMEDIA
Topics discussed in this section:
Topics discussed in this section:
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
Module 3 Arithmetic and Geometric Sequences
Write the recursive and explicit formula for the following sequence
The University of Adelaide, School of Computer Science
Determine whether the sequence converges or diverges. {image}
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
CS Problem Solving and Object Oriented Programming Spring 2019
CMPT 120 Lecture 18 – Unit 3 – Graphics and Animation
Presentation transcript:

1.5.3 Walkthrough #4 bouncing_ball.py wrapping_ball.py Presentation Name Course Name Unit # – Lesson #.# – Lesson Name 1.5.3 Walkthrough #4 bouncing_ball.py wrapping_ball.py Computer Science and Software Engineering © 2014 Project Lead The Way, Inc.

Demo: bouncing_ball.py Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Run this program or watch your teacher demonstrate it. The slider changes the ball’s speed across the canvas. The ball bounces from the canvas’ edges.

Model Presentation Name Course Name Unit # – Lesson #.# – Lesson Name The program will need an IntVar for the speed widget. The variables r, x, y, and direction will reflect the ball’s location. Actually, r, x, and y are redundant; the canvas keeps track of those. But when we ask the canvas to tell us where the ball is, we will need variables to store those results.

Controller Presentation Name Course Name Unit # – Lesson #.# – Lesson Name The slider is the only control. Here a Label explains what to do, too.

View Presentation Name Course Name Unit # – Lesson #.# – Lesson Name The Canvas displays a single item, an oval created on line 46.

Animation Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Lines 51 and 52 require some advanced math. Don’t worry about them. The meat of this handler is on line 54 and line 68. Line 54 moves the circle on the canvas. Line 68 says to call this handler again after 1 millisecond. Hey! That means this handler calls itself! Yes, that’s recursion, discussed on the next slide. Lines 57 through 64 compare the item’s location to the edges of the canvas. If the item is off the canvas, they change the direction of the item so it will head back onto the canvas.

CS Concept: Recursion Recursion is when a function calls itself Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Recursion is when a function calls itself A base case ends the recursion One of four building blocks: Sequence Selection Iteration Recursion The animate() handler in the last slide called itself. This is known as recursion. Recursion is one of the four basic building blocks of programs. At the very beginning of the course, we learned about the other three building blocks. Recursion is hardly touched on in this course. To review: Instructions are sequenced; they happen one after another. Branching and iteration change this sequence. Conditional statements can be evaluated to select the next statement from two options (if-else). Conditional statements can also be evaluated to iterate across a block of instructions (while, for). Recursion is the final building block. Unlike iteration, recursion doesn’t finish with a block of code before repeating it. The recursion starts the recursive block over again, and over and over, without finishing any of them. Finally, (hopefully, if we are to avoid infinite recursion), one call to the function does finish and return to the previous call, which is finally able to return to the previous call, which returns to the one before that, and so on all the way back up to the first recursive call. Image courtesy Steve Mould 2012

CS Concept: Recursion Recursion is when a function calls itself Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Recursion is when a function calls itself A base case ends the recursion Example: In this example, the image processing function that created this image only needs to go so far into the smaller and smaller depths. At some point, it can say “I’m done!” That is the base case, the case where the recursive call returns a value instead of making another recursive call. Image courtesy Steve Mould 2012

CS Concept: Recursion Recursion is when a function calls itself Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Recursion is when a function calls itself A base case ends the recursion Example: In this example, backsum(6) calculates 6+5+4+3+2+1. How does it do this? Does the recursive function ever “miss” the base case? What will happen if you evaluate backsum(6.5)? (Hint: please don’t try it.)

Demo: wrapping_ball.py Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Your teacher will demonstrate the wrapping_ball.py program, and then you will create it. The ball bounces off the top and bottom but wraps around left and right.