![]() |
![]() |
|
home—info—labs—exams—hws
—D2L—MediaSamples/—breeze (snow day)—tutor/PIs
# swatch: int, int -> image # Create a Picture (of size `width`x`height`) # whose color varies left-to-right. # def swatch( width, height ): result = makeEmptyPicture(width,height) show(result) # Just so we can watch progress for x in range(width): paintStripe(result,x, 0,0,x) repaint(result) # watch the progress return result # paintStripe: Picture, int, int, int, int -> None # Modify `aPict` so that column# `columnNum` has the color (`r`,`g,`b`). # def paintStripe( aPict, columnNum, r, g, b ): for rowNum in range(getHeight(aPict)): px = getPixel(aPict, columnNum, rowNum) setRed( px, r ) setGreen( px, g ) setBlue( px, b ) return None |
# pattern: int,int -> Picture # Return (and, show) a picture of a geometric pattern. # def pattern(width,height): rslt = makeEmptyPicture(width,height) show(rslt) for x in range(width): for y in range(height): px = getPixelAt(rslt,x,y) setRed( px, (x+y)/5%256) setGreen(px, 3*(x+y)/5%256) setBlue( px, 4*(x+y)/5%256) repaint(rslt) return rslt |
home—info—labs—exams—hws
—D2L—MediaSamples/—breeze (snow day)—tutor/PIs
©2014, Ian Barland, Radford University Last modified 2014.Apr.19 (Sat) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |