Computer Science I Arrays. Parallel structures. Classwork/Homework: Build your own bouncing things.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

 Functions breakdown: Functions purpose Modularity Declaring and defining a function Calling a function Parameter passing Returning a value Reusability.
Image Processing … computing with and about data, … where "data" includes the values and relative locations of the colors that make up an image.
Structure.
Lesson Four: More of the Same
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
1 Array Knowledge Understand the execute technique of array Skill Can write application program using one and two dimensional array.
General Computer Science for Engineers CISC 106 Lecture 34 Dr. John Cavazos Computer and Information Sciences 05/13/2009.
Loops We have been using loops since week 2, our void draw(){ } is a loop A few drawbacks of draw() –It is endless –There is only one draw() –It updates.
CS2420: Lecture 8 Vladimir Kulyukin Computer Science Department Utah State University.
Lesson Three: Organization
Wednesday, 11/6/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/6/02  QUESTIONS?? – HW # 4 due Monday  Today:  Return HW #3  Arrays (Chap. 10)  Reading:
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
Introducing Arrays We will often need to store collections of information –a list of names to sort –a list of values to compute averages, standard deviation,
Programming Games Simulated ballistic motion: cannon ball. Classwork: Final day for midterm project and all projects for first part of class. Homework:
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
Arrays & Structures II Chapter 9. 2 Organizing Heterogeneous Data  Arrays allow a programmer to organize values of the same type  Homogeneous data 
1 Numbering Is Helpful the pages of a book (chapters and sections too) days of a month years small collections-often use distinct names days of the week.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Arrays. An array is a collection “The Dinner offers an array of choices.” In computer programming, an array is a collection of variables of the same data.
Objects. The Heart of the Matter - The "Black Box" Object-oriented software is all about objects. An object is a "black box" which receives and sends.
Introducing Arrays in C. PURPOSE: Storing multiple data items under the same name Example:  Salaries of 10 employees  Percentage of marks of my dear.
Computer Science I Classes and objects Classwork/Homework: Examine and modify my examples. Make your own.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
Computer Science I Looping. User input. Classwork/Homework: Incorporate looping & user input into a sketch.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
Arrays.
Introduction to Computing Concepts Note Set 21. Arrays Declaring Initializing Accessing Using with Loops Sending to methods.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
Arrays (Chapter 5)‏ Definition Applications One-Dimensional –Declaration –Initialization –Use Multidimensional.
Computer Science I Looking at code: "Where did Prof. Shablinsky go" Classwork/homework: midterm projects.
Computer Science I More class examples. Paths. Jigsaw. Tolerance. Classwork/homework: Your class project. Post proposal for midterm project.
Computer Science I Slingshot example. ProcessingJS example. Review for midterm quiz. Classwork/Homework: study for midterm. Work on midterm project.
Computer Science I Libraries. Sound. Saving frames as images. Classwork/Homework: Make sketch using sound. Add saving frames.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
Arrays. Example Write a program to keep track of all students’ scores on quiz 1. Need a list of everyone’s score Declare 14 double variables? What about.
Arrays. Arrays are objects that help us organize large amounts of information.
Review Objects – data fields – constructors – Methods Classes.
Arrays. 2 Why do we care (about arrays)? What if you have a whole bunch of cars (or aliens or balls or ???) bouncing around the screen? How do we keep.
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
Functions. 2 Modularity What is a function? A named block of code Sometimes called a ‘module’, ‘method’ or a ‘procedure’ Some examples that you know are:
Computer Science I Adding a timing feature. Classwork/Homework: finish final project. Prepare for review for final. Post on programming topic.
Classwork: Examine and enhance falling drop(s) or make your own.
C++ Arrays.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Chapter 10 Algorithms.
Chapter 8 Arrays Objectives
CS150 Introduction to Computer Science 1
int [] scores = new int [10];
Chapter 10 Algorithms.
Topics discussed in this section:
Lecture 7: Introduction to Processing
Arrays Topics Definition of a Data Structure Definition of an Array
Programming for Art: Images
INC 161 , CPE 100 Computer Programming
Chapter 8 Arrays Objectives
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Chapter 10 Algorithms.
Arrays Topics Definition of a Data Structure Definition of an Array
Chapter 9 Arrays.
Presentation transcript:

Computer Science I Arrays. Parallel structures. Classwork/Homework: Build your own bouncing things.

Arrays … are ordered collections of things. Specific datatype. Variables need to be declared: int[] scores; This declares scores to be an array variable, each element an int. Or int[] scores = new int[5]; or int[] scores = {78,80,7};

Arrays Elements in the array are accessed or set using an index. The indexing starts from 0 and goes to one less than the number. scores[0] = 100;... = scores[2];

Typical example Calculate average. int sum = 0; float average; for (int i=0;i<scores.length;i++) { sum = sum + scores[i]; } average = sum/scores.length;

Example: Bouncing balls Build on bouncing ball (it could be bouncing thing). Want each ball to have distinct – Diameter – Starting x and y positions – Starting dx and dy (that is, speeds) Use technique called parallel structures. Use for-loop in draw function.

Global variables float[] bxs = {width/2,width/4, width *.75}; float[] bys = {width/2, width/3, width/6}; float[] dxs = { 3,2,1}; float[] dys = {3,1,2}; int[] balldiams = {20,40,60};

The setup function void setup() { size(900,600); }

The draw function void draw(){ background(0); //erase window for (int i=0;i<bxs.length;i++) // loop over items { ellipse(bxs[i],bys[i],balldiams[i], balldiams[i]); bxs[i] = bxs[i]+dxs[i]; if ((bxs[i]>=width)||(bxs[i]<=0)) {dxs[i] = -dxs[i];} bys[i] = bys[i] + dys[i]; if ((bys[i]>=height)||(bys[i]<=0)) {dys[i] = -dys[i];} } //end for loop }

Classwork Make bouncing things or some other application making use of arrays. For a bouncing balls sketch, – How about adding color? – Make ball slow down or speed up when hitting wall Change specific dxs or dyx element – Incorporate user input

Preview: Making and traveling path Show 5/drawingrev.html 5/drawingrev.html And 5/movingpictures.html 5/movingpictures.html Will explain simple version with circles.

Homework Start planning midterm project. NEXT WEEK: classes