![]() |
![]() |
|
home—info—labs—exams—hws
—D2L—MediaSamples/—breeze (snow day)—tutor/PIs
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) |
Today's tasks: We won't check these off today, but will check them off in the next class.
# stripeAt20x10 : Picture -> None # Modify `aPict` by enpurpling pixels (20,10), (20,11), (20,12), ..., (20,14). # def stripeAt20x10( aPict ): px = getPixelAt( aPict,20, 10) setRed(px,255) ⋮ repaint( aPict ) return |
pitfall: A common problem is to end your function just with “repaint ” rather than “repaint(aPict) ” . I wish JES reported an error if you just mention a function's name without calling it2, but it doesn't.
We will see soon, how to use a loop to avoid the yucky repeated code we had back in
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 “
home—info—labs—exams—hws
—D2L—MediaSamples/—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 ibarland ![]() |
![]() |