L-1 Lecture 13: Functions and Design © 2000 UW CSE University of Washington Computer Programming I.

Slides:



Advertisements
Similar presentations
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Advertisements

More on Algorithms and Problem Solving
Lecture 12 Recursion part 1
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
More About Recursion - 2 Java. Looking at more recursion in Java A simple math example Fractals.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Designing with Methods COMP.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
M-1 University of Washington Computer Programming I Lecture 13 Pointer Parameters © 2000 UW CSE.
C++ Graphics Primitives April 15th. void clearscreen(int c) –clear the screen to background color c –If c = 1 screen black.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Chapter 2: Algorithm Discovery and Design
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
Abstract # 0000 Make the Main Title with Large Bold Type Your Name Here Your Department Here Texas A&M Health Science Center Make the Main Title with Large.
Find the Perimeter and Area:
Discourse Part II: Top - Down Chapter Overview This presentation continues the topic of figure/ground and how this relates to discourse, that is,
Intro to Java & Processing. Review CS is about problem-solving CS is about problem-solving To write programs you must To write programs you must –Be able.
> 1 Diagrams in Word Faculty of Health Alan Grace.
Dynamic Programming Nattee Niparnan. Dynamic Programming  Many problem can be solved by D&C (in fact, D&C is a very powerful approach if you generalized.
Section 8.4.  The definition of a hyperbola is similar to that of an ellipse. However, this time it is the difference in the distances to the two foci,
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 9, 2014 Carolyn Seaman Susan Martin University of Maryland, Baltimore.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Assignment 6.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
11 Working with Images Session Session Overview  Find out more about image manipulation and scaling when drawing using XNA  Start to implement.
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 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Designing with Methods COMP.
L061 Algorithms, Part 3 of 3 Topics Top down-design Structure charts Reading Sections , 3.3.
Dynamic Programming. Many problem can be solved by D&C – (in fact, D&C is a very powerful approach if you generalize it since MOST problems can be solved.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
(c) University of Washington02-1 CSC 143 Java Object and Class Relationships: Interfaces Reading: Ch. 9 (on Java interfaces)
G3-1 University of Washington Computer Programming I Structuring Program Files © 2000 UW CSE.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Functional Abstraction Reduces Complexity.
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.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
SYSTEM ANALYSIS AND DESIGN SAFAA S.Y. DALLOUL. DESIGN THE PROGRAM.
Agenda For Feb PowerPoint Presentation on Java Methods. 3. Finish Happy Face Assignment (Due by the.
Lec 15 Writing an Applet Class. Agenda Writing an Applet class Java Graphics class.
L-1 Lecture 12: Functions and Design © 2000 UW CSE University of Washington Computer Programming I.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
In the last several lessons, you have described translations using coordinates. You have also developed strategies for determining where an object started.
Mrs. Whalen’s Kindergarten Math Lesson #44: Creating shapes from shapes.
Adapted from slides by Marty Stepp and Stuart Reges
CSE / ENGR 142 Programming I
Algorithms IV Top-Down Design.
Building Java Programs
Creating Vector Graphics
Perimeters and Areas of Similar Figures
My Google Sketch up Historical House By: Ashley Mahoney
Building Java Programs
Building Java Programs
Example: Card Game Create a class called “Card”
Building Java Programs
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
CSc 110, Spring 2017 Lecture 6: Parameters (cont.) and Graphics
CSE 8A Lecture 6 Reading for next class:
More About Recursion Java.
Algorithms IV Top-Down Design.
Building Java Programs
Building Java Programs
Building Java Programs
Algorithms, Part 3 of 3 Topics Top down-design Structure charts
Building Java Programs
Building Java Programs
Making a Smile Face Pepper.
Graphics Reading: Supplement 3G
Direct Variation How else could we have solved for k?
Algorithms, Part 3 of 3 Topics Top down-design Reading
2D Shapes Rectangle Circle Triangle Rectangle. What shape is the door? Rectangle.
Presentation transcript:

L-1 Lecture 13: Functions and Design © 2000 UW CSE University of Washington Computer Programming I

L-2 Overview Design process Functional decomposition Top down vs. bottom up Graphics primitives

L-3 Drawing a House

L-4 Drawing a House

L-5 Drawing a House

L-6 Drawing a (Similar) House

L-7 Draw House (Pseudo-code) draw_house (color, ll_x, ll_y, num_windows) draw body as a colored rectangle draw roof as a colored triangle if num_windows is one draw door draw window if num_windows is two draw door draw window

L-8 Functional Decomposition Draw House Draw Body Draw Roof Draw Door Draw Window Rectangle Triangle Rectangle Circle Rectangle Line This is a "calling tree" or "static call graph." Each function is shown, with an arrow down to each function called.

L-9 Functional Decomposition Draw House Draw Roof Draw Body Draw Door Draw Window Triangle Rectangle Circle Line Each function shown only once (preferred)

L-10 Analysis to Design to Programming Analyze the problem Then design a "big-picture" solution A functional decomposition shows how the pieces fit together Then design individual functions May depend on low-level ("primitive") functions available Final programming may be very detailed

L-11 Top Down vs. Bottom Up Sometimes designers start from the big picture Gradually work down to smaller pieces and then to fine details Called the “top down approach” Sometimes people start with small pieces Figure out how they can fit together pieces to solve ever larger and larger problems Called the “bottom up approach”

L-12 Top Down or Bottom Up? Which approach are we following with DrawHouse? Answer: Generally, top down. But we have to look ahead and know what low level functions will be available Eventually, there will be graphics programming to do. Fortunately, most systems supply a library of graphics “primitives”

L-13 Graphics Primitive Typical functions: clearscreen, draw circle, rectangle, line, ellipse, etc. Typical parameters: location, color, fill, etc. Requires a coordinate system (0, 0) X Y (a,b).

L-14 Typical 'rectangle' and 'line' (x1, y1) (x2, y2) (x1, y1) (x2, y2) void rectangle (int color, int x1, int y1, int x2, int y2); void line (int x1, int y1, int x2, int y2);

L-15 Big Picture Again Draw House Draw Roof Draw Body Draw Door Draw Window Triangle Rectangle Circle Line Fill in the pieces one at a time

L-16 WIN_W WIN_H MID_Y Window Constants MID_X Our analysis of how to describe a window

L-17 Map Analysis to C Code Identify and declare constants Choose parameters Utilize primitives Get the picky details right, too! void draw_window(int x, int y) /* (x,y) is the lower left corner of the window */ { rectangle( WHITE, x, y, x + WIN_W, y + WIN_H); line( x+MID_X, y, x + MID_X, y + WIN_H); line( x,y + MID_Y, x + WIN_W, y + MID_Y); }

L-18 Keep Filling in Pieces Draw House Draw Roof Draw Body Draw Door Draw Window Triangle Rectangle Circle Line Analyze and code remaining functions Does the order matter? Coding could be bottom-up, even if design was top-down, and vice-versa If the design is good, the functions can be implemented independently

L-19 Draw House (Gory Detail I) void draw_house (int color, int ll_x, int ll_y, int windows) { int roof_ll_x, roof_ll_y ; /* Draw Body */ draw_body (color, ll_x, ll_y) ; /* Draw Roof */ roof_ll_x = ll_x - OVERHANG ; roof_ll_y = ll_y + BODY_HEIGHT ; draw_roof (color, roof_ll_x, roof_ll_y) ;

L-20 Draw House (Gory Detail II) /* Draw Door and Window(s) */ if (windows == 1) { draw_door (ll_x + DOOR_OFFSET_1, ll_y) ; draw_window (ll_x + WINDOW_OFFSET_1, ll_y + WINDOW_RAISE) ; } else...

L-21 Draw House (Gory Detail II) /* Draw Door and Window(s) */ if (windows == 1) { draw_door (ll_x + DOOR_OFFSET_1, ll_y) ; draw_window (ll_x + WINDOW_OFFSET_1, ll_y + WINDOW_RAISE) ; } else if (windows == 2) { draw_door (ll_x + DOOR_OFFSET_2, ll_y) ; draw_window (ll_x + WINDOW_OFFSET_2A, ll_y + WINDOW_RAISE) ; draw_window (ll_x + WINDOW_OFFSET_2B, ll_y + WINDOW_RAISE) ; }

L-22 Draw House (gory details) void draw_house (int color, int ll_x, int ll_y, int windows) { int roof_ll_x, roof_ll_y ; /* Draw Body */ draw_body (color, ll_x, ll_y) ; /* Draw Roof */ roof_ll_x = ll_x - OVERHANG ; roof_ll_y = ll_y + BODY_HEIGHT ; draw_roof (color, roof_ll_x, roof_ll_y) ; /* Draw Door and Window(s) */ if (windows == 1) { draw_door (ll_x + DOOR_OFFSET_1, ll_y) ; draw_window (ll_x + WINDOW_OFFSET_1, ll_y + WINDOW_RAISE) ; } else if (windows == 2) { draw_door (ll_x + DOOR_OFFSET_2, ll_y) ; draw_window (ll_x + WINDOW_OFFSET_2A, ll_y + WINDOW_RAISE) ; draw_window (ll_x + WINDOW_OFFSET_2B, ll_y + WINDOW_RAISE) ; }

L-23 Next Step: A Neighborhood We could write 6 different functions... Smarter - call 1 function 6 times...

L-24 Summary of Functional Decomposition Look for common elements (similarities) Parameterize for special features (differences) Determine which functions will use others Draw a graph to show their relationships