Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Test 2 Review- Spring 2008

Pictures


EXAMPLE QUESTION: When a weather forecast is produced using chromakey, with the meteorologist standing in front of a green screen, what would happen if the meteorologist wore green clothes?

EXAMPLE QUESTION: Below is the code that we discussed in class to illustrate chromakey:
def testChromakey():
   colbertFile = getMediaPath("colbert-greenscreen.jpg")
   colbertPic = makePicture(colbertFile)
   weatherFile = getMediaPath("Weather_map.jpg")
   weatherPic = makePicture(weatherFile)

   show(weatherPic)
   bgColor = makeColor(80, 180, 80)
   chromakey(colbertPic, weatherPic, bgColor)
   repaint(weatherPic)


def chromakey(fgPic, bgPic, refColor):
   threshold = 120
   offset = getHeight(bgPic) - getHeight(fgPic)
   for fgPixel in getPixels(fgPic):
     if distance(getColor(fgPixel), refColor) > threshold:
       x = getX(fgPixel)
       y = getY(fgPixel)
       bgPixel = getPixel(bgPic, x , y + offset)
       setColor(bgPixel, getColor(fgPixel))



(a) Describe what happens to weatherPic if you reduce the value of threshold:
(b) Describe what happens to weatherPic if you increase the value of threshold:
(c) Given that this program has the desired effect, why is bgColor defined as having the RGB values (80, 180, 80)? Where do these numbers come from?


EXAMPLE QUESTION: What are the effects on pic of running the following functions? Do not refer to pixels in your answer. Instead, use a word or phrase that describes the overall effect on the picture.
def mystery1(pic):
   for currentPixel in getPixels(pic):
     setRed(currentPixel, getRed(currentPixel)/2)
     setGreen(currentPixel, getGreen(currentPixel)/2)
     setBlue(currentPixel, getBlue(currentPixel)/2)

def mystery2(pic):
   for currentPixel in getPixels(pic):
     setRed(currentPixel, 255-getRed(currentPixel))
     setGreen(currentPixel, 255-getGreen(currentPixel))
     setBlue(currentPixel, 255-getBlue(currentPixel))

def mystery3(pic):
   for pix in getPixels(pic):
     mysteryQuantity = (getRed(pix)+getGreen(pix)+getBlue(pix))/3
     setRed(currentPixel, mysteryQuantity)
     setGreen(currentPixel, mysteryQuantity)
     setBlue(currentPixel, mysteryQuantity)


EXAMPLE QUESTION: One form of color blindness is red-green color- blindness. Create a program that generates something like what it's like to see with red-green color-blindness. Write a function redGreenOut which takes a picture as input. For each pixel, set the red and the green values of that pixel to the average of the red and green values. (Hint: You may find mystery3 above a useful starting point for writing code).


Movies


EXAMPLE QUESTION: Consider the code given below, and sketch the frames that are produced when the code is run using the following call. Sketch what is displayed in each frame. (Don’t worry too much about exact accuracy in sizes and positions. Just bear in mind that 25 is one quarter of 100.):

makeTestMovie()

You can assume that writeFrame() is defined to write the frame into an appropriately named and numbered JPG file.
def makeTestMovie():
		for frameNumber in range(1,5):
			frame = makeEmptyPicture(100, 100)
			x = 25 * (4 - frameNumber)
			y = 25 * (frameNumber – 1)
			addRectFilled(frame, x,  y, 25, 25,  black)
			writeFrame(frame, frameNumber)



EXAMPLE QUESTION: Answer the questions based on the function below.
1 def mystery():
2  width = 10
3  rate = 20
4  canvasWidth = 200
5  canvasHeight = 100
6  x = 1
7  y = canvasHeight/2
8  for frameNumber in range(1, 21):
9    canvas = makeEmptyPicture(canvasWidth, canvasHeight)
10   if (frameNumber * rate + 10) < getWidth(canvas):
11      addRectFilled(canvas, x, y, width, width, orange)
12      x = x + rate
13   else:
14      print "Yay"
15      addRectFilled(canvas, x, y, width, width, orange)
16      x = x - rate
17   writeFrame(canvas, frameNumber)



1) When do the frames get written? (Select ONE):
a. All of them get written at the end.
b. One is written each time the program goes through the loop.
c. They don’t get written at all.
d. Only one frame ever gets written: the last one.

2) Assuming that all the frames get written correctly, what does the movie show? (Select ONE):
a. A moving orange square
b. An orange line that grows longer
c. An orange square that grows in size
d. A checkerboard of orange squares

3) How many times does the “if” (line 10) get evaluated?

4) How many times does the block under the “else” (lines 14-15) get executed?

Sound Theory


Other...


Anything that is covered up to Wednesday, February 27th is fair game for the exam.

Questions?

Link to this Page