CSE 113 - PowerPoint PPT Presentation

About This Presentation
Title:

CSE 113

Description:

... to do is repeat the process of getting a pixel and changing its color. ... Putting them together allows us to go through all the rows and columns in the picture. ... – PowerPoint PPT presentation

Number of Views:10
Avg rating:3.0/5.0
Slides: 10
Provided by: cseBu
Learn more at: https://cse.buffalo.edu
Category:
Tags: cse | coloring

less

Transcript and Presenter's Notes

Title: CSE 113


1
CSE 113
  • Week 5
  • February 11 - 15, 2008

2
Announcements
  • Module 2 due 2/15
  • Exam 3 is on 2/15
  • Module 3 due 2/22
  • Exam 4 is on 2/25
  • Module 4 due 2/29

3
Highlights
  • What if we wanted to change all of the pixels in
    a picture to black?
  • We need to access all of the pixels of the
    picture one at a time and then change their color
    to black.

4
Highlights
  • We cant do this simply by inputting each
    coordinate of the pixels and changing them,
    because it only works for certain images, not all
    images.
  • What we want to do is repeat the process of
    getting a pixel and changing its color.

5
Highlights
  • We need a way to help us repeat.
  • Repetition is a key element of computation.
  • One way to have a program repeat is to add a loop
    to our program.
  • The loop we will look at first is a for-loop

6
Highlights
  • The for-loop is a counting loop, so much of the
    syntax needed helps us to set up the counting of
    how many times the loop should repeat.
  • For-loop syntax
  • for(initialization test increment)
  • //loop body

7
Highlights
  • initialization
  • Create a variable that is our loop counter and
    give it a starting value
  • test
  • Test to tell us when to stop the counting
  • increment
  • Increments the counter after each time the loop
    body is executed

8
Highlights
  • We can start a count with the first pixel in a
    row/column and continue counting until the end of
    the row or column
  • Remember that we can tell the width and height of
    a picture by calling the appropriate methods on it

9
Highlights
  • In order to go through all the pixels (width x
    height), we will need a system of two loops, one
    that loops through the columns, and the other
    that loops through the rows.
  • Putting them together allows us to go through all
    the rows and columns in the picture.
Write a Comment
User Comments (0)
About PowerShow.com