Here is our code with all the filters added to complete GUI.
#GUI GLITCH TEAM, December 2018
#Danny Anderson, Molli Nava, Katie Dawe, Evan Gustafson
import gui
from gui import *
#For RGB Shift
import random
#For Weather API
import urllib
import simplejson as json
#Picture
picture = None
filePath = None
#
#
#
#
def setUp():
global filePath
setUpMediaPaths()
window = Display("GUI Glitch Photo Editor", 332, 667)
window.add(Icon(filePath + 'GlitchLogoBG.png'), 0, 0)
exposure = Icon(filePath + 'DoubleExposure.png')
exposure.onMouseClick(exposureFunction)
window.add(exposure, 25, 225)
rgbShift = Icon(filePath + 'rgbShift.png')
rgbShift.onMouseClick(rgbShiftFunction)
window.add(rgbShift, 25, 305)
weatherColor = Icon(filePath + 'WeatherColor.png')
weatherColor.onMouseClick(weatherFunction)
window.add(weatherColor, 25, 385)
corrupt = Icon(filePath + 'CorruptImage.png')
corrupt.onMouseClick(corruptFunction)
window.add(corrupt, 25, 465)
sectionSwap = Icon(filePath + 'SectionSwap.png')
sectionSwap.onMouseClick(swapFunction)
window.add(sectionSwap, 25, 545)
#
#
#
#
def exposureFunction(x,y):
# Double Exposure
# In order for this to work, the two pictures uploaded must be EXACTLY the same size
# I mean, same aspect ratio AND same pixel length on each side
# Stretch goal: make this code work if the pictures are not exactly the same size
def doubleExposure():
choose1 = pickAFile()
choose2 = pickAFile()
pic1 = makePicture(choose1)
pic2 = makePicture(choose2)
canvas = makeEmptyPicture(getWidth(pic1), getHeight(pic1))
#copy columns
overlap = getWidth(pic1)
sourceX = 0
for targetX in range(0,getWidth(pic1)):
sourceY = 0
for targetY in range(0,getHeight(pic2)):
pic1Pixel = getPixel(pic1,sourceX,sourceY)
pic2Pixel = getPixel(pic2, sourceX, sourceY)
newRed = 0.50*getRed(pic1Pixel)+0.50*getRed(pic2Pixel)
newGreen = 0.50*getGreen(pic1Pixel)+0.50*getGreen(pic2Pixel)
newBlue = 0.50*getBlue(pic1Pixel)+0.50*getBlue(pic2Pixel)
color = makeColor(newRed,newGreen,newBlue)
setColor(getPixel(canvas,targetX,targetY),color)
sourceY = sourceY + 1
sourceX = sourceX + 1
show(canvas)
return(canvas)
doubleExposure()
#
#
#
#
def rgbShiftFunction(x,y):
filePath = pickAFile()
picture = makePicture(filePath)
width = picture.getWidth()
height = picture.getHeight()
redImg = []
blueImg = []
greenImg = []
#Description: This code take an image and shifts the RGB channels in different directions.
# Leave Red in place
# Shift Blue up/left
# Shift Green down/right
for x in range(width):
redImg.append([])
blueImg.append([])
greenImg.append([])
for y in range(height):
redImg[x].append([])
blueImg[x].append([])
greenImg[x].append([])
for x in range(width):
for y in range(height):
pixel = getPixel(picture, x, y)
redImg[x][y] = getRed(pixel)
greenImg[x][y] = getGreen(pixel)
blueImg[x][y] = getBlue(pixel)
xShift1 = random.randint(0,100)
yShift1 = random.randint(0,100)
xShift2 = random.randint(0,100)
yShift2 = random.randint(0,100)
for x in range(width):
for y in range(height):
rPixel = redImg[x][y]
bPixel = blueImg[x-xShift1][y-yShift1]
gPixel = greenImg[x - xShift2][y - yShift2]
newR = rPixel
newG = gPixel
newB = bPixel
color = makeColor(newR, newG, newB)
setColor(getPixel(picture, x, y), color)
show(picture)
#
#
#
#
def weatherFunction(x,y):
filePath = pickAFile()
#API WEATHER GLITCH
#Description: This is the starting point for creating our API weather-based glitch.
#It currently uses a yahoo url to grab the current temperature and prints out that value, which we can then use to alter our photographs.
url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22boulder%2C%20co%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
response = urllib.urlopen(url)
data = json.loads(response.read())
print data['query']['results']['channel']['item']['condition']['temp']
temperature = data['query']['results']['channel']['item']['condition']['temp']
print int(temperature)
def tempShift():
temperature = int(data['query']['results']['channel']['item']['condition']['temp'])
condition = data['query']['results']['channel']['item']['condition']['text']
picture = makePicture(filePath)
if temperature < 10:
for p in getPixels(picture):
red = getRed(p)
green = getGreen(p)
blue = getBlue(p)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(p, negColor)
setRed(p,getRed(p)*1.2)
setGreen(p,getGreen(p)/1.2)
setBlue(p,getBlue(p)*9)
elif temperature in range (11,20):
for p in getPixels(picture):
red = getRed(p)
green = getGreen(p)
blue = getBlue(p)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(p, negColor)
setRed(p,getRed(p)*1.3)
setGreen(p,getGreen(p)*1.2)
setBlue(p,getBlue(p)*6)
elif temperature in range (21,30):
for p in getPixels(picture):
red = getRed(p)
green = getGreen(p)
blue = getBlue(p)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(p, negColor)
setRed(p,getRed(p)*1)
setGreen(p,getGreen(p)*1.2)
setBlue(p,getBlue(p)*4)
elif temperature > 30:
for p in getPixels(picture):
red = getRed(p)
green = getGreen(p)
blue = getBlue(p)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(p, negColor)
setRed(p,getRed(p)*4)
setGreen(p,getGreen(p)*1.3)
setBlue(p,getBlue(p)*1)
show(picture)
tempShift()
#
#
#
#
def corruptFunction(x,y):
#Picture
picture = makePicture(pickAFile())
width = picture.getWidth()
height = picture.getHeight()
redImg = []
blueImg = []
greenImg = []
#Description: This code take an image and shifts the RGB channels in different directions.
# Leave Red in place
# Shift Blue up/left
# Shift Green down/right
for x in range(width):
redImg.append([])
blueImg.append([])
greenImg.append([])
for y in range(height):
redImg[x].append([])
blueImg[x].append([])
greenImg[x].append([])
for x in range(width):
for y in range(height):
pixel = getPixel(picture, x, y)
redImg[x][y] = getRed(pixel)
greenImg[x][y] = getGreen(pixel)
blueImg[x][y] = getBlue(pixel)
for x in range(width):
for y in range(height):
xShift1 = random.randint(1,100)
yShift1 = random.randint(1,100)
xShift2 = random.randint(1,100)
yShift2 = random.randint(1,100)
rPixel = redImg[x][y]
bPixel = blueImg[x - xShift1][y - yShift1]
gPixel = greenImg[x - xShift2][y - yShift2]
newR = rPixel
newG = gPixel
newB = bPixel
color = makeColor(newR, newG, newB)
setColor(getPixel(picture, x, y), color)
explore(picture)
#
#
#
#
def swapFunction(x,y):
picture = makePicture(pickAFile())
def mirrorUpHalf():
pixels=getPixels(picture)
target = (len(pixels)/4) - 1
for index in range(0,len(pixels)/2):
pixel1=pixels[index]
color1=getColor(pixel1)
pixel2=pixels[target]
setColor(pixel2,color1)
target=target-1
mirrorUpHalf()
show(picture)
#
#
#
#
def setUpMediaPaths():
global filePath
showInformation("Please select the folder where your media is located.")
filePath = pickAFolder()
setUp()
