![]() ![]() |
| |||||||||
| Hotspots: Slides and Code TA Corner Comments? Announcements FAQ Static Webspace | ||||||||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
A | def blueOneHundred(picture):
for x in range(1,100):
for y in range(1,100):
pixel = getPixel(picture,x,y)
setBlue(pixel,100) |
B | def removeBlue(picture):
for p in getPixels(picture):
if getBlue(p) > 0:
setBlue(p,100) |
C | def noBlue(picture):
blue = makeColor(0,0,100)
for p in getPixels(picture):
color = getColor(p)
if distance(color,blue) > 100:
setBlue(p,0) |
D | def byeByeBlue(picture):
for p in getPixels(picture):
if getBlue(p) > 100:
setBlue(p,0) |
Weighted color values (as opposed to the typical 33.33% each):Hint: you'll probably have something in your code like luminance = r * .3 + g * .59 + b * .11
- Red → 30%
- Green → 59%
- Blue → 11%
| If the luminance is... | Print out the statment... |
| Less then 10 | That's going to be awfully dark |
| Greater than or equal to 10 or less than or equal to 50 | A little dark. |
| Between 50 and 200 | Looks like a good range |
| Greater than or equal to 200 and less than 250 | Getting kinda bright. |
| Over or equal to 250 | AHHH! MY EYES! |
| >>> someFunction(2, 'fred') |
def testme(p,q,r):
if q > 50:
print r
value = 10
for i in range(1,p):
print "Everybody"
value = value - 1
print value
print r |
| >>> testme(5, 51, "Homestar Rocks!") |
| If the pay is... | Charge a tax of... |
| Less then 100 | 25% |
| Greater than or equal to 100 and less than 200 | 30% |
| Greater than or equal to 200 and less than 300 | 35% |
| Greater than or equal to 300 and less than 400 | 45% |
| 400 or over | 50% |
def newFunction(a, b, c):
print a
list1 = range(1,5)
value = 0
for x in list1:
print b
value = value +1
print c
print value |
| >>> newFunction("I", "you", "walrus") |
A | def mirrorTemple():
source = makePicture(getMediaPath("temple.jpg"))
mirrorpoint = getWidth(source) / 2
lengthToCopy = mirrorpoint - 14
for x in range(1, lengthToCopy):
for y in range(28, 98):
p = getPixel(source, mirrorpoint - x, y)
p2 = getPixel(source, mirrorpoint + x, y)
setColor(p2, getColor(p))
show(source)
return source |
B | def mirrorTemple():
source = makePicture(getMediaPath("temple.jpg"))
mirrorpoint = getWidth(source) / 2
lengthToCopy = mirrorpoint - 14
for x in range(1, lengthToCopy):
for y in range(28, 98):
p = getPixel(source, mirrorpoint - x, y)
p2 = getPixel(source, mirrorpoint + x, y)
setColor(p, getColor(p2))
show(source)
return source |
C | def mirrorVertical(source):
mirrorpoint = int(getWidth(source) / 2)
for y in range(1, getHeight(source) + 1):
for xOffset in range(1, mirrorpoint):
pright = getPixel(source, xOffset + mirrorpoint, y)
pleft = getPixel(source, mirrorpoint - xOffset, y)
c = getColor(pleft)
setColor(pright, c) |
D |
def mirrorVertical(source):
mirrorpoint = int(getWidth(source) / 2)
for y in range(1, getHeight(source) + 1):
for xOffset in range(1,mirrorpoint):
pright = getPixel(source, xOffset + mirrorpoint, y)
pleft = getPixel(source, mirrorpoint - xOffset, y)
c = getColor(pright)
setColor(pleft, c) |
E | def mirrorVertical(source):
mirrorpoint = 20
for y in range(1, getHeight(source) + 1):
for xOffset in range(1, mirrorpoint):
pright = getPixel(source, xOffset + mirrorpoint, y)
pleft = getPixel(source, mirrorpoint - xOffset, y)
c = getColor(pleft)
setColor(pright,c) |
def scaleAndCrop(ratio):
pic = makePicture(getMediaPath("food.jpg"))
canvas = makePicture(getMediaPath("640x480.jpg"))
sourceX = 50
for targetX in range(300, 300 + int((110 - 50) * ratio)):
sourceY = 70
for targetY in range(200, 200 + int((123 - 70) * ratio)):
print "Copying from", sourceX, sourceY, "to", targetX, targetY
color = getColor(getPixel(pic, int(sourceX), int(sourceY)))
setColor(getPixel(canvas, targetX, targetY), color)
sourceY = sourceY + (1.0 / ratio)
sourceX = sourceX + (1.0 / ratio)
show(canvas)
return canvas
|
scaleAndCrop(.5)
scaleAndCrop(2.0)
scaleAndCrop(1.5)
| >>> setRed(p, 300) >>> print getRed(p) |
| >>> print 5 / 2 |
| >>> print 5 / 2.0 |
| >>> getPixels(pic) |
| >>> 4 < 2 |
| >>> setColor(p, white) >>> setRed(p, 0) >>> setBlue(p, getRed(p)) |
def tomato(pictureA, pictureB):
for x in range(1, getWidth(pictureB) + 1):
for y in range(1, getHeight(pictureB) + 1):
targetPixel = getPixel(pictureA, x, y)
sourcePixel = getPixel(pictureB, x, y)
color = getColor(sourcePixel)
setColor(targetPixel, color)
|
def cucumber(picture):
for p in getPixels(picture):
color = getColor(p)
if distance(color, white) < distance(color, black):
setColor(p, white)
else:
setColor(p, black)
|
def hashbrowns(number):
foo = 0
for i in range(number + 1)
foo = foo + i
return foo
|
def nothingPolitical(picture):
for xoffset in range(1, getWidth(picture) / 2):
for y in range(1, getHeight(picture) + 1):
liberal = getPixel(picture, xoffset, y)
conservative = getPixel(picture, getWidth(picture) - xoffset, y)
colorA = getColor(liberal)
colorB = getColor(conservative)
setColor(liberal, colorB)
setColor(conservative, colorA)
|