CSC 160 Computer Programming for Non-Majors Section 1.3: Animating the UFOs Flight Prof. Adam M. Wittenstein

Slides:



Advertisements
Similar presentations
An introduction to pointers in c
Advertisements

Code Club Session 3 Shark Eats Fish. Picture of finished product here.
CSC 160 Computer Programming for Non-Majors Lecture #9: Booleans Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #4: Defining Variables Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Images: Another Form of Symbolic Data Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 2: Numbers, Expressions, and Simple Programs Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 6: Structures Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #11: Conditionals II Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Introduction Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3c: Working with Pictures (continued) Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Draft Chapter: The UFO Example Prof. Adam M. Wittenstein
Section 1.1: Flying a UFO (continued). Conversion recipe 1)Expand abbreviations 2)Parenthesize all subexpressions that have an operator. Should end up.
Section 1.2: Drawing a UFO (conclusion). Last time… ● Using figure 1, we can now find a UFO’s location (using the X and Y functions). ● And, we can now.
Exercise A) Find out how tock in that figure works manually. Enter expression expressions such as (tock 0) and (tock 1) into DrScheme's Interactions.
CSC 160 Computer Programming for Non-Majors Lecture #10: Conditionals I Prof. Adam M. Wittenstein
CS 201 Functions Debzani Deb.
Section 1.2: Drawing a UFO (continued). Writing a program to draw UFOs Remember that the header includes: define program’s name(let’s call it UFO-draw)
CSC 160 Computer Programming for Non-Majors Introduction Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Section 1.2: Drawing a UFO Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 4: Conditional Expressions and Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5b: Designing Programs Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 3: Programs are Functions Plus Variable Definitions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #2: What are Functions? Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5a: Defining Functions on Words and Sentences Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #6: Function Composition Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3b: Working with Pictures Prof. Adam M. Wittenstein
Wizard Game: Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July
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.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 5 Sept 4th, 2001 Fall Semester.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Willingness to Pay, MB and Consumer Surplus
PRESENTATION SOFTWARE PowerPoint, Keynote, Prezi Purpose?
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
Multimedia- Microsoft PowerPoint
Locally Edited Animations We will need 3 files to help get us started at
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Python Programming Chapter 6: Iteration Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
CSC264 Modelling and Computation 10. Modelling State Steve Riddle, John Fitzgerald, Maciej Koutny Computing Science Semester /06.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Indexed and Relative File Processing
Click your mouse for next slide Dreamweaver – Inserting and Formatting Text Inserting text is just as easy as inserting pictures If you wish to type text.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
Software Engineering Chapter 3 CPSC Pascal Brent M. Dingle Texas A&M University.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
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.
1 Advanced Computer Programming Lab Calculator Project.
Exercises Graph the following functions. Solutions will follow the exercises.
Copyright © Curt Hill Loop Types and Construction Logical types and construction hints.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Sight Words.
CSC 480 Software Engineering Test Planning. Test Cases and Test Plans A test case is an explicit set of instructions designed to detect a particular class.
1 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1. Design: Plan in detail Look at the two images below. One is a design and one is the final product. The examiner needs to see your designs AND your final.
Introduction to System Analysis and Design MADE BY: SIR NASEEM AHMED KHAN DOW VOCATIONAL & TECHNICAL TRAINING CENTRE.
Graphics in Python On entry: Run Python 2.78 from N: drive/computing and ICT VLE: Computing home page - check your feedback Success criteria: ●Understands.
1. Design: Plan in detail Get the analysis document from this folder. There are two GCSE ICT tasks in unit 2: Power Point for the garden centre and Database.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
مباني کامپيوتر و برنامه نويسي
BUSINESS COMMUNICATION SKILLS PRESENTATION SKILLS OF THESIS & PROJECT
CSC 581: Mobile App Development
Presentation transcript:

CSC 160 Computer Programming for Non-Majors Section 1.3: Animating the UFOs Flight Prof. Adam M. Wittenstein

So far… We have learned how to: -find the UFOs location -draw and erase UFOs and shots. But… The drawing and erasing is too slow to use in creating a game. We want to make it look like the UFOs and shots are moving continually across the screen.

Back to simple-draw.ss There are actually two more programs in that file: (big-bang n x) starts the clock and makes it tick every n seconds; it creates a world from x. (on-tick-event tock) sets the tick handler to tock, which is applied to the current world at every tick of the clock and produces the next world. Clearly, to understand these functions and to see what they do, we must understand what it means to create a world and to compute a new one.

What is a world? A “world” is something that we want to track during our computations. Usually it is an entire collection, say a UFO and a bunch of shots and perhaps some surface vehicles that fire these shots and so on. For now, since all we know are numbers, our world is just a number (representing the current time). For example, if all we want to do is move a single UFO across the canvas, we can just use t to represent the world.

Starting to create the animation… From that, –the X and Y functions can compute the UFO's coordinates and –the UFO-paint function can draw the UFO at these coordinates. This suggests the following to get started: (start ) ; creates the canvas (big-bang.5 0) ; starts the clock and sets t to 0

What to do when the clock ticks The critical step is to tell the teachpack which function we want to run at every tick of the clock. Let's call this function tock. Enter (on-tick-event tock). Then at the first clock tick, the teachpack applies tock to the first world, call it w0, and tock produces another world, say w1. Then the teachpack applies tock to w1 and obtains w2, and so on. Every time the clock ticks, the tock function is called on.

The tock function – Version 1 In our specific example, the world is t. We know that t starts with 0, and then becomes 1, 2, and so on. Hence, the function that consumes t and produces the next one just adds 1 to t: (define (tock t) (+ t 1)) Of course, this accomplishes nothing yet. The first use of tock consumes 0 and produces 1, the second consumes the 1 and produces 2, and so forth, but no UFO is drawn or erased.

Keywords We have already seen one keyword – define. It sets the header of a program equal to its body. Often, we use bold font for keywords. Our teachpack simple-draw.ss provides two other keywords: --The draw keyword allows you to evaluate a sequence of drawing functions (that you wrote or that are predefined). --The produce keyword is Scheme’s version of an assignment statement. For example, we can increase the value of t by 1, so that “t” BECOMES “t + 1”. --Assignment statements can be done in Scheme without the teachpack, but not in the Beginner Mode that we are restricting ourselves to.

To get our ''world transforming'' functions to draw something on the canvas, we need one more piece of knowledge about simple-draw.ss. We need to erase the UFO and draw a new one. (define (tock t) (draw (ufo-erase t); erases the old UFO (ufo-draw (+ t 1)) ; draws a new UFO produce (+ t 1))) ; changes the world, ; by adding 1 The tock function – Version 2

The tock function at work clock tick the world (t)012 draw(ufo-erase 0) (ufo-draw 1)(ufo-erase 1) (ufo-draw 2)(ufo-erase 2) (ufo-draw 3) produce (the next world) 123 The tock function ensures that each use of ufo-draw is followed by an equivalent use of ufo-erase, which erases the UFO before it is redrawn at a different spot.

Our first complete animation (define (X t) (+ (* 10 t) 20)) (define (Y t) (+ (* 20 t) 60)) (define (ufo-paint t c) (and (draw-solid-disk0 (X t) (Y t) 10 c) (draw-solid-rect0 (- (X t) 20) (Y t) 40 3 c))) (define (ufo-draw t) (ufo-paint t 'green)) (define (ufo-erase t) (ufo-paint t 'white)) (define (tock t) (draw (ufo-erase t) (ufo-draw (+ t 1)) produce (+ t 1))) (start ) (big-bang.5 0) (on-tick-event tock)

Next time… Wrap up the UFO chapter --Practice with animations Quiz #2