Description
Introduces design, creation, and manipulation of interactive applications and electronic media for communication purpose. Focuses on creating media, understanding media concepts, and manipulating the created media using basic programming concepts of control flow, functions, expressions and data types in the Python language. Students acquire a basic understanding for digital media formats, how to design, create such media using basic programming skills.
Image Portfolio
Following is the requirements for the Image portfolio
Rose Colored Glasses
Rose Colored Glasses
The function below takes any image, and provides a pink tint. it collects each pixel and increases the red value by 50 and reduces the others by 50.
def roseColoredGlasses():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
r = getRed(p)
b = getBlue(p)
g = getGreen(p)
setRed(p, r + 50)
setBlue(p, b - 50)
setGreen(p, g - 50)
repaint(pic)
Negative
The following function, gets the opposite value for each pixel, subtracting them from 255. That way we get the opposite color for each pixel on the image.
The following function, gets the opposite value for each pixel, subtracting them from 255. That way we get the opposite color for each pixel on the image.
def makeNegative():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
newColor = makeColor(255-getRed(p),255-getGreen(p),255-getBlue(p))
setColor(p, newColor)
repaint(pic)
Better black and white
The Better Black and White function weights the value of each pixel and returns a different one to make the image in black and white. We used the weighted values because of how the human eye looks at certain hues differently
The Better Black and White function weights the value of each pixel and returns a different one to make the image in black and white. We used the weighted values because of how the human eye looks at certain hues differently
def betterBnW():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
avg_color = avg_color = (getRed(p)*.299 + getGreen(p)*.587 + getBlue(p)*.114)
newColor = makeColor(avg_color,avg_color,avg_color)
setColor(p, newColor)
repaint(pic)
Bottom-to-top Mirror
The bottom function grabs the image of any dimension, and gets the bottom left pixel and changes the top left pixel to it. Then it repeats until it reaches the center. And goes through the entire domain of the image
The bottom function grabs the image of any dimension, and gets the bottom left pixel and changes the top left pixel to it. Then it repeats until it reaches the center. And goes through the entire domain of the image
def Bottom_to_Top():
pic = get_pic()
width = getWidth(pic)
height = getHeight(pic)
target = makeEmptyPicture(width,height)
target = pic
for x in range(0,width):
for y in range(0,height/2):
color=getColor(getPixel(pic, x, height-y-1))
setColor(getPixel(target, x, y),color)
show(target)
return target
Shrink
Might be hard to tell from the 2 images below. the quality on the right image may be lower but the function actually halves the size and pixels of the image
Might be hard to tell from the 2 images below. the quality on the right image may be lower but the function actually halves the size and pixels of the image
def shrinkPic():
pic = get_pic()
width = getWidth(pic)
height = getHeight(pic)
target = makeEmptyPicture(width/2+1,height/2+1)
for x in range(0,width):
for y in range(0,height):
#gathering all even pixels
if (x%2 == 0) and (y%2 == 0):
color=getColor(getPixel(pic, x, y))
setColor(getPixel(target, x/2, y/2),color)
show(target)
return target
Collage
This function grabs 9 images, modifies 5 of them and puts them in a canvas. The images all get resized into even height and width to create an even image.
This function grabs 9 images, modifies 5 of them and puts them in a canvas. The images all get resized into even height and width to create an even image.
def get_pic():
return makePicture(pickAFile())
def pyCopy(source, target, targetX, targetY):
width = getWidth(source)
height = getHeight(source)
for x in range(0,width):
for y in range(0,height):
color=getColor(getPixel(source, x, y))
setColor(getPixel(target, targetX+x, targetY+y),color)
show (target)
return target
#quad mirroring
def qmirror_pic(pic):
width = getWidth(pic)
height = getHeight(pic)
target = makeEmptyPicture(width,height)
for x in range(0,width/2):
for y in range(0,height/2):
color=getColor(getPixel(pic, x, y))
setColor(getPixel(target, x, y),color)
setColor(getPixel(target, width-x-1, height-y-1),color)
setColor(getPixel(target, x,height-y-1),color)
setColor(getPixel(target,width-x-1,y),color)
return target
#horizontal mirroring
def hmirror_pic(pic):
width = getWidth(pic)
height = getHeight(pic)
target = makeEmptyPicture(width,height)
for x in range(0,width):
for y in range(0,height/2):
color=getColor(getPixel(pic, x, y))
setColor(getPixel(target, x, y),color)
setColor(getPixel(target, x, height-y-1),color)
return target
#negative
def makeNegative(pic):
pixels = getPixels(pic)
for p in pixels:
newColor = makeColor(255-getRed(p),255-getGreen(p),255-getBlue(p))
setColor(p, newColor)
#repaint(pic)
return pic
#black and white
def betterBnW(pic):
pixels = getPixels(pic)
for p in pixels:
avg_color = (getRed(p)*.299 + getGreen(p)*.587 + getBlue(p)*.114)
newColor = makeColor(avg_color,avg_color,avg_color)
setColor(p, newColor)
#repaint(pic)
return pic
#rotate
def rotatePic(pic):
width = getWidth(pic)
height = getHeight(pic)
target = makeEmptyPicture(height,width)
for x in range(0,width):
for y in range(0,height):
color=getColor(getPixel(pic, x, y))
setColor(getPixel(target, y, width-x-1),color)
return target
#resize
def resize(pic):
width = getWidth(pic)
height = getHeight(pic)
target = makeEmptyPicture(850,1100)
percentWidth = width / 850.0
percentHeight = height / 1100.0
for x in range(0,849):
for y in range(0,1099):
color = getColor(getPixel(pic,int(x*percentWidth),int(y*percentHeight)))
setColor(getPixel(target, x, y),color)
return target
def makeCollage():
collage = makeEmptyPicture(2550,3300)
pic1 = get_pic()
pic2 = get_pic()
pic3 = get_pic()
pic4 = get_pic()
pic5 = get_pic()
pic6 = get_pic()
pic7 = get_pic()
pic8 = get_pic()
pic9 = get_pic()
pic1 = betterBnW(pic1)
pic3 = makeNegative(pic3)
pic5 = hmirror_pic(pic5)
pic7 = qmirror_pic(pic7)
pic9 = rotatePic(pic9)
pic1 = resize(pic1)
pic2 = resize(pic2)
pic3 = resize(pic3)
pic4 = resize(pic4)
pic5 = resize(pic5)
pic6 = resize(pic6)
pic7 = resize(pic7)
pic8 = resize(pic8)
pic9 = resize(pic9)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic1, x, y))
setColor(getPixel(collage, x, y),color)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic2, x, y))
setColor(getPixel(collage, x+849, y),color)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic3, x, y))
setColor(getPixel(collage, x+(849*2), y),color)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic4, x, y))
setColor(getPixel(collage, x, y+1099),color)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic5, x, y))
setColor(getPixel(collage, x+849, y+1099),color)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic6, x, y))
setColor(getPixel(collage, x+(849*2), y+1099),color)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic7, x, y))
setColor(getPixel(collage, x, y+(1099*2)),color)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic8, x, y))
setColor(getPixel(collage, x+849, y+(1099*2)),color)
for x in range(0,849):
for y in range(0,1099):
color=getColor(getPixel(pic9, x, y))
setColor(getPixel(collage, x+(849*2), y+(1099*2)),color)
show (collage)
return collage
Red-eye Reduction
The following function grabs an image with the selected region and looks for the similar red color you get when taking a flash picture. Then it turns the eyes into a more natural dark color.
The following function grabs an image with the selected region and looks for the similar red color you get when taking a flash picture. Then it turns the eyes into a more natural dark color.
def red_eye_correction():
pic = get_pic()
red_eye = makeColor(200,32,21)
natural_black = makeColor(28, 13, 6)
for x in range(53, 296):
for y in range(207, 276):
px = getPixel(pic, x, y)
color = getColor(px)
if distance(color, red_eye) < 100.0:
setColor(px, natural_black)
show(pic)
return pic
Color Art-i-fy
The following function grabs the ranges of the pixels' colors and depending on where it lands it will select specific dictated ranges.
The following function grabs the ranges of the pixels' colors and depending on where it lands it will select specific dictated ranges.
def Artify():
pic = get_pic()
width = getWidth(pic)
height = getHeight(pic)
for x in range(0, width):
for y in range(0, height):
px = getPixel(pic, x, y)
red = getRed(px)
if( red < 64):
setRed(px, 31)
elif( red > 63 and red < 128):
setRed(px, 95)
elif( red > 127 and red < 192):
setRed(px, 159)
elif( red > 192 and red < 256):
setRed(px, 223)
green = getGreen(px)
if( green < 64):
setGreen(px, 31)
elif( green > 63 and green < 128):
setGreen(px, 95)
elif( green > 127 and green < 192):
setGreen(px, 159)
elif( green > 192 and green < 256):
setGreen(px, 223)
blue = getBlue(px)
if( blue < 64):
setBlue(px, 31)
elif( blue > 63 and blue < 128):
setBlue(px, 95)
elif( blue > 127 and blue < 192):
setBlue(px, 159)
elif( blue > 192 and blue < 256):
setBlue(px, 223)
show(pic)
return pic
Green screen
This is the function my team has had the most fun with. Our faces are on astronauts and we have been imposing our picture in different space backgrounds. It goes through and if the background matches the green, it will grab the pixel of whatever image we want and places that instead
This is the function my team has had the most fun with. Our faces are on astronauts and we have been imposing our picture in different space backgrounds. It goes through and if the background matches the green, it will grab the pixel of whatever image we want and places that instead
def chromakey():
green_pic = get_pic()
background_pic = get_pic()
background_green = makeColor(61,255,15)
width = getWidth(green_pic)
height = getHeight(green_pic)
for x in range(0, width):
for y in range(0, height):
px = getPixel(green_pic, x, y)
color = getColor(px)
background_px = getPixel(background_pic, x, y)
background_color = getColor(background_px)
if distance(color, background_green) < 130.0:
setColor(px, background_color)
show(green_pic)
return green_pic
Homemade St. Patrick's Day Card
We also used the same image to create our St. Patrick's Card from space. Like I said, we have had too much fun with that image.
We also used the same image to create our St. Patrick's Card from space. Like I said, we have had too much fun with that image.
def get_pic():
return makePicture(pickAFile())
def pyCopy(source, target, targetX, targetY):
width = getWidth(source)
height = getHeight(source)
for x in range(0,width):
for y in range(0,height):
color=getColor(getPixel(source, x, y))
setColor(getPixel(target, targetX+x, targetY+y),color)
#show (target)
#writeTempPic(target)
return target
def mirror(pic):
width = getWidth(pic)
height = getHeight(pic)
mirror = makeEmptyPicture(width, height)
for x in range(0, width):
for y in range(0, height):
p = getPixel(pic, x, y)
red = getRed(p)
green = getGreen(p)
blue = getBlue(p)
mp = getPixel(mirror, width-x-1, y)
setRed(mp, red)
setGreen(mp, green)
setBlue(mp, blue)
return mirror
def chromakey(green_pic, background_pic):
background_green = makeColor(61,255,15)
width = getWidth(green_pic)
height = getHeight(green_pic)
for x in range(0, width):
for y in range(0, height):
px = getPixel(green_pic, x, y)
color = getColor(px)
background_px = getPixel(background_pic, x, y)
background_color = getColor(background_px)
if distance(color, background_green) < 80.0:
setColor(px, background_color)
return green_pic
def card():
green_screen = get_pic()
background = get_pic()
logo = get_pic()
header1 = "Happy St."
header2 = "Patrick's Day..."
footer = "From Team 4"
paddy_green = makeColor(0, 102, 0)
chromakey(green_screen, background)
import java.awt.Font as Font
myFont = makeStyle("Comic Sans", Font.BOLD, 80)
addTextWithStyle(green_screen, 229, 104, header1, myFont, black)
addTextWithStyle(green_screen, 225, 100, header1, myFont, white)
addTextWithStyle(green_screen, 140, 200, header2, myFont, white)
addTextWithStyle(green_screen, 136, 196, header2, myFont, paddy_green)
addTextWithStyle(green_screen, 140, 900, footer, myFont, black)
addTextWithStyle(green_screen, 144, 904, footer, myFont, white)
pyCopy(logo, green_screen, 122, 315)
pyCopy(logo, green_screen, 320, 200)
mirror_logo = mirror(logo)
pyCopy(mirror_logo, green_screen, 539, 323)
show(green_screen)
Line Drawing
Lastly, this is not part of any past lab but a whole new project altogether. With the provided instructions we were suppose to go pixel by pixel in an image and check to right side and bottom pixel. If the right side pixel and the bottom pixel's colors' difference with the main pixel match an arbitrary weighted value, then the function turns that pixel to black, otherwise to white. That way we end up with an image similar to that of a sketch or a line art. Depending on how much we weight the value it will make it "heavier" or "lighter" on the strokes of the lines.
Lastly, this is not part of any past lab but a whole new project altogether. With the provided instructions we were suppose to go pixel by pixel in an image and check to right side and bottom pixel. If the right side pixel and the bottom pixel's colors' difference with the main pixel match an arbitrary weighted value, then the function turns that pixel to black, otherwise to white. That way we end up with an image similar to that of a sketch or a line art. Depending on how much we weight the value it will make it "heavier" or "lighter" on the strokes of the lines.
def get_pic():
return makePicture(pickAFile())
def betterBnW(pic):
pixels = getPixels(pic)
for p in pixels:
avg_color = (getRed(p)*.299 + getGreen(p)*.587 + getBlue(p)*.114)
newColor = makeColor(avg_color,avg_color,avg_color)
setColor(p, newColor)
return pic
def lineDrawing(weight):
pic = get_pic()
width = getWidth(pic)
height = getHeight(pic)
for x in range(0, width-1):
for y in range(0, height-1):
#p = pixel
p = getPixel(pic, x, y)
#pix = pixel color
pix = getRed(p)
rp= getPixel(pic, x+1, y)
rpix = getRed(rp)
dp = getPixel(pic, x, y+1)
dpix = getRed(dp)
right_distance = abs(pix - rpix)
bottom_distance = abs(pix - dpix)
if right_distance > weight and bottom_distance > weight:
setColor(p, black)
else:
setColor(p, white)
show(pic)