Thanks to office hours and Mckenzie, our RGB glitch has been solved and the API-altered image makes more sense.
After spending quite a bit of time brainstorming with Mckenzie, we figured out a much simpler way to execute the separation of the RGB channels of an image. We separated out the different color channels of an image, blended the pixels like the example in the book, and offset the different colors by changing their x and y values.
This is the new code:
#RGB SHIFT GLITCH
#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):
rPixel = redImg[x][y]
bPixel = blueImg[x-50][y-50]
gPixel = greenImg[x - 100][y - 100]
newR = rPixel
newG = gPixel
newB = bPixel
color = makeColor(newR, newG, newB)
setColor(getPixel(picture, x, y), color)
explore(picture)
Examples of images I’ve glitched:
Mckenzie also explained how to go about altering an image using current temperature data. This is just the beginning of that, pulling in our specific data and value we want to use:
import urllib import simplejson as json #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']
