Lecture-16

advertisement
Creative Commons Attribution
Non-Commercial Share Alike License
• http://creativecommons.org/licenses/by-ncsa/3.0/
• Original Developer: Beth Simon, 2009
bsimon@cs.ucsd.edu
CSE8A Lecture 16
• Read next class: read pg 202-207 and
CHAPTER 8: 252-265
• Get your clicker back up front!
• Midterm! BRING RED SCANTRON!
– Covers material through today
– Review session with Leo Tues 7-8:30pm location TBD
– Sample midterm posted by tomorrow 7am:
• Use learning goals to know what I care about
• Redo: clicker questions, quizzes, lab quizzes, (75-80% ish Multi
choice
• Be able to WRITE CODE ON PAPER (like your PSAs)
– 35 min individual (90%), 15 min group (10%)
By the end of today’s class you should
be able to…
• LG34: Compare and contrast two solutions to a problem using for
loops and if statements
• LG35: Be able to identify which pixels you want to check for
chromakey
Honorable
Mentions:
Best of Show
Quiz 4 Review/Midterm Review
• How would you call and display the flipped
Picture?
Picture changed = new Picture(p);
p.mystery(changed);
Picture changed = new Picture();
changed.show();
p.mystery(changed);
changed.show();
Picture changed = new Picture(p);
changed.mystery(p);
Picture changed = new Picture();
changed.show();
changed.mystery(p);
changed.show();
REVIEW
In Lab 5: How many
times is the red line below executed?
public void makeConvict()
{
for (int x = 0; x < this.getWidth(); x++)
{
for (int y = 0; y < this.getHeight(); y++)
{
Pixel currentPix = this.getPixel(x,y);
if ( (currentPix.getGreen() > 200) && (y%2==0))
{
currentPix.setColor(Color.BLACK);
}
else if( (currentPix.getGreen() > 200) && y%2 == 1)
{
currentPix.setColor(Color.WHITE);
}
}
}
}
A.
B.
C.
D.
E.
width * height / 2
width * height
width * height * 2
width * height * 1.5
Depends on the color of the Pixels in the picture
In Lab 5: How many
times is the red line below executed?
public void makeConvict()
{
for (int x = 0; x < this.getWidth(); x++)
{
for (int y = 0; y < this.getHeight(); y++)
{
Pixel currentPix = this.getPixel(x,y);
if ( (currentPix.getGreen() > 200) && (y%2==0))
{
currentPix.setColor(Color.BLACK);
}
else if( (currentPix.getGreen() > 200) && y%2 == 1)
{
currentPix.setColor(Color.WHITE);
}
}
}
}
A.
B.
C.
D.
E.
width * height / 2
width * height
width * height * 2
width * height * 1.5
Depends on the color of the Pixels in the picture
In Lab 5:
Which of these statements is true?
public void makeConvict()
{
for (int x = 0; x < this.getWidth(); x++)
{
for (int y = 0; y < this.getHeight(); y++)
{
Pixel currentPix = this.getPixel(x,y);
if ( (currentPix.getGreen() > 200) && (y%2==0))
{
currentPix.setColor(Color.BLACK);
}
else if( (currentPix.getGreen() > 200) && y%2 == 1)
{
currentPix.setColor(Color.WHITE);
} A. The red line of code is executed the same number
}
}
B.
}
C.
D.
of times
as the purple line of code
The red line of code is executed more times than the purple
line of code
The red line of code is executed fewer times than the
purple line of code
The relationship depends on the specific Picture that this
code is run on
Original make convict bird:
• If it’s a green pixel AND it’s an even
indexed row, make it black
• Else If it’s a green pixel AND it’s an odd
indexed row, make it white
Better version:
Test Common Element Once
Take advantage of “mutually exclusive”
• If it’s a green pixel
– If it’s an even indexed row, make it black
– Else make it white
Download