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.

Slides:



Advertisements
Similar presentations
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Advertisements

Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
In our lesson today we will learn how to find the area of a building.
Which of the following areas are you trying to find? ParallelogramTriangleTrapezoid AREAS OF POLYGONS.
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
Display of Objects on Screen. COUNTERS b A horizontal counter represents the horizontal position of the monitor’s electron beam. b A vertical counter.
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.
CSC 160 Computer Programming for Non-Majors Section 1.3: Animating the UFOs Flight Prof. Adam M. Wittenstein
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.
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 Section 1.2: Drawing a UFO Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 3: Programs are Functions Plus Variable Definitions Prof. Adam M. Wittenstein
4.7 Quadratic Equations and Problem Solving BobsMathClass.Com Copyright © 2010 All Rights Reserved. 1 General Strategy for Problem Solving Understand the.
Today, I will learn the formula for finding the area of a rectangle.
Shorter of two objects and changing color Functions, events and setting the color Susan Rodger, Duke University June 2008.
Bug Session One. Session description In this session, pupils are introduced to a programming sequence which will make a light pattern on their Bug. Objectives.
Checkerboard Examples Top Down Design. The Problem On a checkerboard where locations are numbered similar to java coordinates, draw a rectangle using.
6-2 Warm Up Problem of the Day Lesson Presentation
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 5 Sept 4th, 2001 Fall Semester.
Do Now.
Today we will derive and use the formula for the area of a triangle by comparing it with the formula for the area of a rectangle. derive = obtain or receive.
6-2 Warm Up Problem of the Day Lesson Presentation
8.3 Area of Squares and Rectangles
Code Club Session 2 Dance Party. What will we learn ?  How to change the background  How to create animations  How to make objects talk to each other.
Geometry Monday 8/25 Please get a piece of paper to complete the warm up…
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
Shorter of two objects and changing color V2 Functions, events and setting the color in sequence and randomly This is a modification of the Changing Color.
Introducing Scratch the Cat
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Geometry 11.1 Areas of Rectangles.
Creating Buttons – Lesson 51 Creating Buttons Lesson 5.
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
MAT 1234 Calculus I Section 3.7 Part I Optimization Problems
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.
Variables. Todays Lesson  In todays lesson you are going to:  Learn to use variables  Learn to ask for user input  Learn to save the users response.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
6-2 Warm Up Problem of the Day Lesson Presentation
Lesson Topic: Drawing Polygons on the Coordinate Plane Lesson Objective: I can…  Given coordinates for the vertices, I can draw polygons in the coordinate.
Area of Triangles Return to table of contents. Area of a Triangle Let's use the same process as we did for the rectangle & parallelogram. How many 1 ft.
COMPUTER PROGRAMMING I SUMMER 2011 Objective 8.01 Understand coordinate systems. (3%)
First Project: Dance Dance Sprite  Write a dance with your sprite (You pick or create the sprite)  Incorporate as many of the Motion Commands as you.
CS305j Introduction to Computing Simple Graphics 1 Topic 11 Simple Graphics "What makes the situation worse is that the highest level CS course I've ever.
SECTION 11.2 Areas of Parallelograms, Triangles, and Rhombuses.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Focus: Basketball Review for Note Taking Skills. Parts of the test Part 1: Matching column of vocabulary words. Part 2: Label the diagrams of note- taking.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Turtle Graphics Let’s see what we can draw on Python!
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Warm Up Find the area of each figure. Give exact answers, using  if necessary. 1. a square in which s = 4 m 2. a circle in which r = 2 ft 3. ABC with.
Announcements Finish factoring expressions Study for quiz over: Writing addition and subtraction expressions Writing and expanding multiplication expressions.
HW: Finish Problem 4.3 (assigned parts) Weekly Review due Friday Do Now3/7/16 Using graph paper, draw a possible net for a rectangular prism with a length.
Stage 3: Artist What do you remember from the last class?
Pixels, Colors and Shapes
Adapted from slides by Marty Stepp and Stuart Reges
Week 1 - Friday CS 113.
Animation & Games Module
Section 11-7 Ratios of Areas.
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Basic Graphics Drawing Shapes 1.
Introduction to Object-Oriented Programming
Building Java Programs
Graphics -- Introduction
Lecture 7: Introduction to Processing
Spell your name using word art from above
Presentation transcript:

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 draw and erase the UFO on the screen (using the UFO-draw and UFO-erase functions). Today… ● In programming, one should not have two functions that both have similar code. So, we will see another way to write UFO-draw and UFO-erase. ● Then, a practice exercise to introduce HW3.

UFO-draw vs. UFO-erase ● The UFO-draw program and the UFO-erase program are extremely similar. ● We are wasting time doing the same thing twice. ● What do both programs have in common? (define (ufo-… t) (and (draw-solid-disk0 (X t) (Y t) 10 …) (draw-solid-rect0 ( - (X t) 20) (Y t) 40 3 …))) ● What is different? The color (‘green or ‘white)

● What if we had a program that allowed the user to pick the color for the UFO to be drawn? ● Let’s call it UFO-paint. (if we didn’t already have a UFO- draw program, that name would be fine.) ● The trick to avoiding duplicate work is abstraction, a fancy word for writing functions that do as many different things as possible. ● In our case, we want to define a function that is like ufo-draw and ufo-erase but it can do both. Another way to write the program…

● Since the difference between the two functions is the color that they use, we merge them into one function by adding a second variable for the color. ● The parts that change from ufo-draw and ufo- erase are underlined: (define (ufo-paint t c) (and (draw-solid-disk0 (X t) (Y t) 10 c) (draw-solid-rect0 (X t) (Y t) 40 3 c)))

Now a shorter ufo-draw… (define (ufo-draw t) (ufo-paint t ‘green)) …and a shorter UFO-erase (define (ufo-erase t) (ufo-paint t ‘white))

Exercise 1.2.2: Drawing Shots We can draw the UFO. However, to play the game, we also have to draw the shots. We can draw the UFO. However, to play the game, we also have to draw the shots. Let’s display a shot as a thin, upward pointing, equilateral triangle. Let’s display a shot as a thin, upward pointing, equilateral triangle. Step 1: Draw a canvas of 100 by 100 pixels, and draw a small equilateral triangle into it with the points: (50, 30), (45, 40), and (55, 40). Step 1: Draw a canvas of 100 by 100 pixels, and draw a small equilateral triangle into it with the points: (50, 30), (45, 40), and (55, 40). --Connect the base points with three lines. --What is the height of the triangle? --What is the width of its base?

Exercise 1.2.2: Drawing Shots Step 2: Next, draw a triangle of the same width and height but with the highest point at (70,10). Step 2: Next, draw a triangle of the same width and height but with the highest point at (70,10). --What are the other two points? Step 3: Draw another shot at (20, 30). Step 3: Draw another shot at (20, 30). Step 4: Draw another shot at (80, 30). Step 4: Draw another shot at (80, 30). --You can think of the shots in Steps 1, 3, and 4 as one and the same shot moving across the screen.

Exercise 1.2.2: Drawing Shots Step 5: Use your experience with drawing these four triangles to define a Scheme function that can draw a triangle of this size, given the coordinates of the top point: Step 5: Use your experience with drawing these four triangles to define a Scheme function that can draw a triangle of this size, given the coordinates of the top point: ;; given: xtop is the x coordinate of the top-most point, ;; given: xtop is the x coordinate of the top-most point, ;; ytop is the y coordinate ;; ytop is the y coordinate (define (triangle-draw xtop ytop) (define (triangle-draw xtop ytop) (and )) The first two lines are called comments, and they remind you what xtop and ytop are, when you will read this program in two months or years from now. The first two lines are called comments, and they remind you what xtop and ytop are, when you will read this program in two months or years from now.

Homework 3 (due Sunday) Do Exercise ● A) Create a canvas of 100 by 200 pixels. ● B) Draw a shot close to the bottom of the canvas. Use thin, tall rectangles to depict shots. ● C) Draw a second shot. ● D) Define the function shot-draw, which -- like ufo-draw -- consumes t and draws a shot. It computes the X and Y coordinates of the shot using the shot-X and shot-Y functions from HW2.

Homework 3 (due Sunday) Finish Exercise ● Define the function shot-draw, which draws a shot as a triangle. It consumes a single number, the time t, and draws a triangle on a canvas of size 100 by 200: ;; given: t (define (shot-draw t)...) ● Again, use the functions shot-X and shot-Y from HW2 to determine where the base point is. ● Hint: You should also use triangle-draw.

In summary… ● Just as we can draw and erase UFOs, we can draw and erase shots. ● We will create a function to do the repeated drawing and erasing, and from there, we write the animation for the UFO game. Next time…