CS 1321. CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 5 Sept 4th, 2001 Fall Semester.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

CS2984: Introduction to Media Computation Drawing directly on images.
CompSci Today’s topics Java Recursion in Graphics Writing a Class Simple Animation Upcoming Simulation Reading Great Ideas, Chapters 5.
The Data Design Recipe CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
Classes, Objects, and Methods CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.1 © Mitchell Wand, This work is licensed under a Creative.
CS 1107 Introduction to Multimedia Authoring Systems October 2010.
VisualLISA A Quick and Simple Demonstration. The default aspect of an attribute grammar specification on VisualLISA. In this view we can add a new production.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 6: Structures Prof. Adam M. Wittenstein
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
Fourteen lists and compound data. Some primitive data types Integers (whole numbers) 1, 2, 3, -1, 0, , etc. “Floating-point” numbers ,
Section 6.1: Structures (continued). Example 1: in-left-side? ; Purpose: To determine whether a point is in the leftmost 150 pixels of the screen. ; Contract.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
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.
CS 206 Introduction to Computer Science II 12 / 01 / 2008 Instructor: Michael Eckmann.
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 Section 1.2: Drawing a UFO Prof. Adam M. Wittenstein
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
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 #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Scratch Understanding some programming techniques using Scratch Resetting, Parallelism and Events.
Introduction to VBA. This is not Introduction to Excel We’re going to assume you have a basic level of familiarity with Excel If you don’t, or you need.
Adding Content To Your Faculty Page 1.Login 2.Create your Faculty Page 3.
1 CS 106 Computing Fundamentals II Chapter 17 “Introduction To VBA” Herbert G. Mayer, PSU CS status 6/30/2013 Initial content copied verbatim from CS 106.
Arbitrarily Long Data Structures: Lists and Recursion CMSC Introduction to Computer Programming October 4, 2002.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 11 Sept 27th, 2001 Fall Semester.
TeachScheme, ReachJava Adelphi University Tuesday afternoon July 13, 2010.
Scheme: Compound Data Chapter 6 of HTDP Ms. Knudtzon September 19.
Examining Two Pieces of Data CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative.
Classes, Objects, and Methods CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.1 © Mitchell Wand, This work is licensed under a Creative.
The Design Recipe using Classes CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.5 © Mitchell Wand, This work is licensed under a Creative.
Complete Dolch Sight Word List Preprimer through Third
1 Introduction to Computer Graphics – CGS-1586C Spring Quarter 2011 Instructor: Amanda Dickinson Tues/Thurs from 6:00PM to 7:50 PM.
Compound Data. Last Lecture Booleans Only two elements Symbols Not to be confused with variables Strings Notions of equality on values.
CS 206 Introduction to Computer Science II 02 / 13 / 2009 Instructor: Michael Eckmann.
Game Maker – Getting Started What is Game Maker?.
CS 206 Introduction to Computer Science II 04 / 22 / 2009 Instructor: Michael Eckmann.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 10 Sept 25th, 2001 Fall Semester.
Sight Word List.
Functional Programming Language 1 Scheme Language: part 2.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Drawing pictures … It’s not art, it’s fun.
A digital lesson about colour and pattern  2005 Pearson Publishing.
Lecture on Set! And Local CS 2135 Copyright Kathi Fisler, 2002 This material requires Advanced Language Level.
PROGRAMMING GRAPHICS DrScheme Drawing Tools A Unique Use of Technology for ALGEBRA EDUCATION E XPANDING Y OUR H ORISONS IN MATHEMATICS AND SCIENCE March.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 6 Sept 6th, 2001 Fall Semester.
CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 4 Aug. 30, 2001 Fall Semester.
CS 5JA Introduction to Java Graphics One of the powerful things about Java is that there is.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 13 October 4, 2001 Fall Semester.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Functions vs. Classes CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 16 October 18, 2001 Fall Semester.
Lecture Exercise (Wk4) CS1301 Introduction To Computer Programming (11-12 Semester B) Page 1 Question 2 (a)Complete the code.
Teaching Programming in Middle School TeachScheme! Anniversary Workshop Brown University, Providence, Rhode Island June 11-12, 2005 Pamela Ossorio, The.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Functional Programming Language 1 Scheme Language: part 3.
CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.2
UNIT 2 – LESSON 3 Encoding B&W Images.
Lesson 2-3 AP Computer Science Principles
CS 1321.
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.3
Color Values All colors in computer images are a combination of red, green and blue Each component is encoded as a number means the color is.
UNIT3 Colour.
Let's Play "What's the Question"
Lawrence Snyder University of Washington, Seattle
Basic Processing … Drawing pictures … It’s not art, it’s fun
The Iterative Design Recipe
Examining Two Pieces of Data
Presentation transcript:

CS 1321

CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 5 Sept 4th, 2001 Fall Semester

Today’s Menu I. Administrivia A. TURN IN YOUR ASSIGNMENT B. Note: WebWork is used for Hw5 II. Introduction to Compound Data (Section 6) A. Introduction B. Demonstration using Graphics! III.Creating your own Structures

Administrivia Homework 4... is now due.

Administrivia Homework 5 will be handed in using the WebWork system. Note the due date and time, on the assignment.

Administrivia Teachpacks. A few students had trouble with teachpacks. Please note: 1) You must install DrScheme completely. 2) You must read directions carefully.

Questions?

Everyone knows what this is…. 0 X y

0 X y So what’s this?

0 X y We can describe information about this location, such as its x & y coordinates. X=2 Y=5

0 X y So now we start to have many of these points in space. Visually we have no problems keeping track of information about individual points.

But what happens when we store this information in a computer? Do computers have little grids inside them on which they keep track of points? NO

So let’s say we store stuff textually X = 1 Y = 13 No problems yet, right?

But as our problem grows more complex… X = 1 Y = 13 X = 3 Y = 15 X = 4 Y = 2 X = 27 Y = 1 X = 2 Y = 16 X = 9 Y = 1 We’re still ok, right? We can just follow the X-Y pattern…

But what happens when… X = 1 X = 2 X = 3 X = 4 X = 9 X = 27 X-Values Y-Values Y = 1 Y = 2 Y = 13 Y = 15 Y = 16

Wouldn’t it be easier to group things together? (X = 1, Y = 13) (X = 3,Y = 15) (X = 4,Y = 2) (X = 27, Y = 1) (X = 2, Y = 16) (X = 9, Y = 1)

Structures The whole idea of structures is to group together data that belongs together (such as the x & y coordinates of a point in space). This gives us a single unit that we can shuttle back and forth between functions without fear of losing the meaning of our data.

Example: The Posn A posn is a scheme structure built into Beginning DrScheme. It contains two fields or locations within a posn where data is stored. These fields have names: x & y. So a posn just stores information about a position!

How do I make one? You call on a built-in function: (make-posn )

So How Do I Use it? Well, the two fields in a posn are called x & y, so oddly enough…. (posn-x ) & (posn-y )

So let’s write an Example that uses a posn structure * I’m not going to put in all the Design Recipe comments here. Structures do change what your Design Recipes look like, but we’ll get into that on Thursday.

distance-to-0 function (define (distance-to-0 in-posn) (sqrt (+ (square (posn-x in-posn)) (square (posn-y in-posn)))))

How about the distance between any two points? Recall: P2: (4,2) P1: (10,6)  Y =  X = X Y __________ Distance =  (  X) 2 + (  Y) 2 Wanted: Distance between points P1 and P2

Using posn Structures (incomplete use of template…) (define (distance dx dy) (sqrt (+ (* dx dx) (* dy dy)))) ;; Contract: between: posn posn -> number ;; Purpose: find the distance between two points ;; use sqrt( dx*dx + dy*dy) ;; Examples: ( 0 0 ) to ( ) -> 100 ;; ( 0 0 ) to ( ) -> 141 ;; Definition: (define (between a b) (distance (- (posn-x b) (posn-x a)) (- (posn-y b) (posn-y a))))

Built-in Drawing Tools (start ) ; open a canvas (draw-solid-line color) – and are posn’s –Color is a symbol 'white 'yellow 'red 'blue 'green 'black (draw-solid-rect color) – and are numbers giving the height and width (draw-circle color) – is a number giving the radius (draw-solid-disk color) (stop); close the current canvas

Draw a Simple Tree (define (drawTree x) (and (draw-solid-disk (make-posn ) 50 'green) (draw-solid-rect (make-posn ) 'black)))

Add Another Tree (define (drawTree x) (and (draw-solid-disk (make-posn ) 50 'green) (draw-solid-rect (make-posn ) 'black) (draw-solid-disk (make-posn ) 50 'green) (draw-solid-rect (make-posn ) 'black)))

Programming Principle Whenever you are tempted to copy and paste some code: (draw-solid-rect (make-posn ) 50 'green) (draw-solid-rect (make-posn ) 'black) Stop and think: "Is there a better way?" Let's abstract out the drawing of the tree from its location…

Draw a Re-Usable Tree ;; offset : posn posn -> posn ;; take an initial position p and offset delta; return a ;; new posn whose x and y components are the sums of the ;; x and y components of p and delta. (define (offset p delta) (make-posn (+ (posn-x p) (posn-x delta)) (+ (posn-y p) (posn-y delta)))) y x 50 (x – 10) (y + 50) ;; tree : posn -> drawing (define (tree p) (and (draw-solid-disk p 50 'green) (draw-solid-rect (offset p (make-posn )) 'black)))

Questions?

Making Your Own Structures So posns are pretty useful and all, but they’re kind of boring. Why not create our own structures? There are plenty of things out there that we could represent with structures….

People – First Name, Last Name, Age, Weight Buildings – Name, Address, Height, Residential or Business, Number of occupants CDs – Artist, Genre, Record Company, Number of Songs Or maybe even…

Embarrassing Photographs! Can you believe it? This is one of the other instructors!

Our Structure Should Store… The First Name of the Individual involved The Last Name of the Individual involved The Date the picture was taken And… The Embarrassment Level of that particular photograph

define-struct (define-struct ( … ))

We now have the ability to store information about badphotos. NOTE: We have NOT stored any information about any particular photo. All that we’ve done is create a kind of TEMPLATE for how we WILL store info about badphotos. (Hint: that’s foreshadowing for next lecture!)

define-struct buys us some stuff Whenever we define a new struct, we also automatically define a whole slew of functions that we can use to manipulate that new struct. Consider it a function bonus!!

CONSTRUCTOR: (make-badphoto ) * Doesn’t this look kind of similar to make-posn? ACCESSORS: (badphoto-first ) (badphoto-last ) (badphoto-date ) (badphoto-level ) Some function freebies!

Last but not least: PREDICATES: (badphoto? ) * Would it surprise you to know there was a (posn? …) function?

Let me give one of these badphotos a name Now, let’s access some data dan