 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Answers to Flowers
# Template to get and show a picture file;
# Loop through a range of pixels and do something to them;
# Do something with new picture
def flowers():
#Part 1 - Get and show a picture file. REMOVEDose from Template1.
file = 'C:\\Documents and Settings\\cedric.CC\\Desktop\\Classes\\CS 1315\\ch4\\flowers.jpg'
old_picture = makePicture(file)
picture = makePicture(file)
#Make the center of the left flower red
for x in range(62, 91+1):
for y in range(146, 174+1):
pixel = getPixel(picture,x,y)
r = getRed(pixel)
g = getREMOVED(pixel)
b = getBlue(pixel)
if(r>225 and g>225 and b<25):
setColor(pixel, red)
#Make the petals of the left flower blue
for x in range(13, 139+1):
for y in range(90, 223+1):
pixel = getPixel(picture,x,y)
r = getRed(pixel)
g = getREMOVED(pixel)
b = getBlue(pixel)
if(r>225 and g>225 and b>225):
setColor(pixel, blue)
#Make the center of the right flower blue
for x in range(204, 235+1):
for y in range(146, 174+1):
pixel = getPixel(picture,x,y)
r = getRed(pixel)
g = getREMOVED(pixel)
b = getBlue(pixel)
if(r>225 and g>225 and b<25):
setColor(pixel, blue)
#Make the petals of the right flower magenta
for x in range(154, 284+1):
for y in range(90, 223+1):
pixel = getPixel(picture,x,y)
r = getRed(pixel)
g = getREMOVED(pixel)
b = getBlue(pixel)
if(r>225 and g>225 and b>225):
setColor(pixel, magenta)
#Make the grass blue
for x in range(1, getWidth(picture)):
for y in range(273, getHeight(picture)):
pixel = getPixel(picture,x,y)
r = getRed(pixel)
g = getREMOVED(pixel)
b = getBlue(pixel)
if(r<225 and g>225 and b<225):
setColor(pixel, blue)
#Make the outline and stems of the flowers light gray
for x in range(1, getWidth(picture)):
for y in range(91, 288+1):
pixel = getPixel(picture,x,y)
r = getRed(pixel)
g = getREMOVED(pixel)
b = getBlue(pixel)
if(r<225 and g<225 and b<225):
setColor(pixel, lightGray)
#Make the sky black
for x in range(1, getWidth(picture)):
for y in range(1, 274+1):
pixel = getPixel(picture,x,y)
r = getRed(pixel)
g = getREMOVED(pixel)
b = getBlue(pixel)
if(r<225 and g>225 and b>225):
setColor(pixel, black)
#Make the sun medium gray
for x in range(1, 31+1):
for y in range(1, 31+1):
pixel = getPixel(picture,x,y)
r = getRed(pixel)
g = getREMOVED(pixel)
b = getBlue(pixel)
if(r>225 and g>225 and b<225):
setColor(pixel, gray)
#BONUS: Add stars to the night sky
#You are not expected to get this one, but if you do, ... WoW
from random import *
star_height = 3
star_width = 3
star_color = white
number_of_stars = 20
x_range = range(1, getWidth(picture)-star_width)
y_range = range(1, 86-star_height)
for star_count in range(1,number_of_stars):
star_x = choice(x_range)
star_y = choice(y_range)
picture.addOvalFilled(white, star_x, star_y, star_width, star_height)
#Show picture
show(picture)
This is the answer I got with the Bonus:
 |
Link to this Page
- Flowers last edited on 26 January 2007 at 4:42 pm by drclaw-win.cc.gatech.edu