Computation as an Expressive Medium

Slides:



Advertisements
Similar presentations
ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
Advertisements

What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
Sep 26, Fall 2006IAT 800 Lecture 6 Methods and Classes.
Pointers. Topics Pointers Pointer Arithmetic Pointers and Arrays.
Object References. Objects An array is a collection of values, all of the same type An object is a collection of values, which may be of different types.
Oct 17, Fall 2006IAT 800 ArrayList, Text, and more Image Manipulation.
Introduction to Objects A way to create our own types.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
CSC 142 J(part 1) 1 CSC 142 The ArrayList class [Reading: chapter 10]
Computation as an Expressive Medium Lab 3: (Methods and) Classes Jason Alderman.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
ArrayList By Neil Butcher. What is the difference between an ArrayList and an Array? An ArrayList is in many ways similar to an array, but has a few subtle.
Computation as an Expressive Medium Lab 2: Polygons, Transformations, and Arrays Evan.
Arrays as pointers and other stuff COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
LCC 6310 Computation as an Expressive Medium Lecture 6.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Lecture 9: Lists MIT-AITI Kenya © 2005 MIT-Africa Internet Technology Initiative In this lecture we will learn…. ArrayList – These are re-sizeable.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Week 6 - Friday.  What did we talk about last time?  Loop examples.
The ArrayList Data Structure The Most Important Things to Review.
Java I/O Basics MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh Bajaj,
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Fundamental Programming Fundamental Programming Data Processing and Expressions.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
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.
IAT 265 Lecture 7 Objects and ArrayList. May 19, 2016IAT 2652 Outline  Programming concepts –Super and this –Java SDK classes Lists Reading the Java.
FOP: Multi-Screen Apps
Array in C# Array in C# RIHS Arshad Khan
Computer Organization and Design Pointers, Arrays and Strings in C
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Introduction to Computer Science / Procedural – 67130
Testing and Debugging.
LCC 6310 Computation as an Expressive Medium
Impress presentation for 1st Level of Secondary Education Students which objective is to learn how to use Impress to make different presentations. Presentation.
Arrays in C.
Pointers and References
Computation as an Expressive Medium
void Pointers Lesson xx
Pointers in C Good morning Ladies and Gentlemen. Welcome to this talk on “Pointers in C”
Writing Methods AP Computer Science A.
Polymorphism.
CS 302 Week 8 Jim Williams, PhD.
Week 9 – Lesson 1 Arrays – Character Strings
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
Teaching London Computing
Arrays in Java What, why and how Copyright Curt Hill.
ArrayLists.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Grouped Data Arrays, and Array Lists.
Who Am I Really? Your Name Here.
int [] scores = new int [10];
Arrays.
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
CSE 143 Lecture 5 References and Linked Nodes
CS150 Introduction to Computer Science 1
Winter 2019 CMPE212 4/7/2019 CMPE212 – Reminders
Data Structures & Algorithms
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
LCC 6310 Computation as an Expressive Medium
Lecture 6 Methods and Classes
Manipulating Pictures, Arrays, and Loops
Computation as an Expressive Medium
Introduction to Python
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
you get to solve puzzles!
Insertion Sort.
Lecture 6 Methods, Classes, Inheritance
Week 7 - Monday CS 121.
Presentation transcript:

Computation as an Expressive Medium Lab 5: ArrayList, Text, and more Image Manipulation Jason Alderman

Goooooooooooood Morning Go over ArrayLists again. (You will love them. You will.) ArrayLists + Polygons = PURE FUN. More Image stuff. Some words on Strings (Not today, unless you really want it.) Extra time for Project 2 and one-on-one questions.

First, a clarification… Yesterday I was a little unsure of the slides: I was wrong! (The slides were RIGHT of course!) Legal statement: Rocket r3 = new ArmedRocket(50, 60, 0); This is CORRECT because ArmedRocket can fulfill all the functionality of Rocket (and then some!) But this is illegal ArmedRocket r4 = new Rocket(50, 60, 0); This is NOT RIGHT because Rocket does not have all the functionality of ArmedRocket! (What happens if you try to refer to a missile firing? Rocket has no missiles. ERROR! DOES NOT COMPUTE!!)

ArrayLists ArrayLists are our friends… but also our worst enemies! (Don’t let that scare you away! Come back!) Pros: Are great if you don’t know how many things are going to go into the array. Automatically resizes when you add to a full ArrayList. Cons: Only stores objects, not primitive variables (int, float…). Need to make objects from those. Only returns things of the Object type. Need to explicitly cast back to the type you put in there.

ArrayLists Remember, an ArrayList is just like an array: If we decide we need to add another element to the array, we need to make a NEW, bigger array, and copy all the elements into it. What a pain!

ArrayLists ArrayLists do this for us! We don’t even have to declare a size when we first create it, only deciding how many elements we’ll have when we actually add them. ArrayList a = new ArrayList(); a.add(Object o) – adds an object at next index. a.get(int i) – returns object at i index.* a.size() – returns number of indices in the ArrayList. * What I said yesterday was INCORRECT: a.get(3) is RIGHT, a[3] is WRONG for an ArrayList.

Simple Example - ArrayList Let’s make a little class called Point, which simply stores an X and Y value associated with a point on the screen. class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; }

Simple Example - ArrayList Why do this? Let’s make an ArrayList of Points so we don’t need two arrays of x and y points. ArrayList pointList = new ArrayList(); pointList.add(new Point(45, 50)); pointList.add(new Point(79, 23)); // let’s draw a circle at our second point. Point p2 = (Point)pointList.get(1); ellipse(p2.x, p2.y, 50, 50);

Simple Example - ArrayList We could extend this so that every time we click, that point gets added to our ArrayList. void mouseReleased() { pointList.add(new Point(mouseX, mouseY)); }

Simple Example - ArrayList We could then do anything with these points as they accumulate. Here’s an example: void draw() { background(255); if(pointList.size() > 1) { beginShape(POLYGON); for(int i = 0; i < pointList.size(); i++) { Point p1 = (Point)pointList.get(i); vertex(p1.x, p1.y); } endShape(); Every time we click, the polygon will re-draw, using the new point we’ve added.

Left To Do We talked about ArrayLists Now we’ll look at some examples of image manipulation. Moreover, let’s have time for Project 2 and its inherent questions. (No funny today. Sorry.)