RU beehive logo ITEC dept promo banner
ITEC 109
2014spring
ibarland

homeinfolabsexamshws
D2LMediaSamples/breeze (snow day)tutor/PIs

lab25
a function processing a picture

We finished last time, seeing how to modify a row of 5 (specific) pixels in an image:

pict0 = makePicture( "pathToSomeFile.jpg" )   # you can call pickAFile(), to find the full path

show(pict0)
explore(pict0)

px = getPixelAt(pict0, 20, 10)
setRed(px,255)
setBlue(px,255)
px = getPixelAt(pict0, 20, 11)
setRed(px,255)
setBlue(px,255)
px = getPixelAt(pict0, 20, 12)
setRed(px,255)
setBlue(px,255)
px = getPixelAt(pict0, 20, 13)
setRed(px,255)
setBlue(px,255)
px = getPixelAt(pict0, 20, 14)
setRed(px,255)
setBlue(px,255)

repaint(pict0)
We'll say that we “enpurple” a pixel, when we max out its red and blue components as above. (Enpurpling a black pixel makes it purple; if there is any green in a pixel then enpurpling it makes it a lighter purple; enpurpling a white pixel leaves it white — the lightest purple!)

Today's tasks: We won't check these off today, but will check them off in the next class.

We will see soon, how to use a loop to avoid the yucky repeated code we had back in stripeAtX10.


1Well, it will take in any picture-object which is at least 21x15, if we are changing pixel (20,14).      

2 In python, it can be technically legal to talk about a function without calling it — after all, really “repaint” is just a variable-name which happens to hold a function, and you can have a variable-name on a line by itself, even if that's not very helpful. For advanced programmers, having functions be values (which can be stored in a variable, like any value) is incredibly useful. But as beginners, mentioning a function without calling it is pretty much never what we want to do!      

homeinfolabsexamshws
D2LMediaSamples/breeze (snow day)tutor/PIs


©2014, Ian Barland, Radford University
Last modified 2014.Mar.28 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme