Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

JES Dictionary - Picture Manipulation Commands




getColorpixel = getPixel(somePicture, 132,597)
thatParticularColor = getColor(pixel)

If you want to use the color values of a Pixel Object without necessarily doing anything fancy to the red, green, and blue values individually (like say for instance, you wanted to copy one pixel's color to another pixel as opposed to increase the blue in a picture) you can use getColor. getColor takes in a Pixel Object and returns a Color Object. A Color Object is an entity that has an encapsulated red, green, and blue value.


Uploaded Image: getColor.png
Confusions & Insights:






getPixelpixel = getPixel(mySuperCoolPicture, 34, 42)

getPixel plucks one singular pixel from a picture and returns it as a Pixel Object. It takes in a Picture Object that you want to get the pixel from, and a set of coordinates, x and y respectively.

The purpose of creating a Pixel Object from a picture and a set of coordinates is other picture manipulating functions in JES take in a Pixel Object. Things like getBlue which takes in a Pixel Object and returns the numerical amount of blue in it.


Uploaded Image: getPixel.png
Confusions & Insights:






getPixelsfor pixel in getPixels(mySuperCoolPicture):
  #something you want to do to every pixel goes here.

getPixels takes in a Picture Object as input and returns one GIANT list of Pixel Objects. This is especially useful to combine with a for loop which requires a list to do operations on. Using for and getPixels in combination with each other you can quickly modify all the pixels in a picture.

The key thing to remember is that getPixels returns a LIST OF PIXEL OBJECTS.


Uploaded Image: getPixels.png
Confusions & Insights:






getRed, getGreen, getBluepixel = getPixel(mySuperCoolPicture, 34, 42)
amount_of_green = getGreen(pixel)
print amount_of_green
#you should see a number between 0 and 255

Once you have a Pixel Object, you can extract the NUMERICAL amount of red, green, or blue in it. This is useful for doing intelligent operations on the color values, such as increasing/decreasing a certain color or even more advanced stuff such as increasing/decreasing contrast or chromakey.


Uploaded Image: getRed.png
Confusions & Insights:

do you have to put getPixel and getGreen? or would it work just as fine if I put getGreen and not getPixel? I am confused b/c sometimes it works if i dont have getPixel but sometimes it doesnt.

The bottom line is you need to pass getGreen a pixel object. You can either manually pick out a pixel with getPixel or you can embed it in a for loop that gets its pixels from getPixels. Either way it'll work.





getWidth, getHeighta = getWidth(picture)
b = getHeight(picture)
print "This picture has a total of", (a * b), "pixels."

getWidth and getHeight take in a Picture Object and simply return an integer indicating how many pixels wide or tall the picture is.

This is useful for for loops when you want to do something for every row in a picture or something along those lines.



Uploaded Image: getWidth.png
Uploaded Image: getHeight.png
Confusions & Insights:






getX, getYpixel = getPixel(mySuperCoolPicture, 34, 42)
x = getX(pixel)
print x
#you'll see 34

Just like fetching the red, green, or blue value from a pixel, you can also extract the x-coordinate of a Pixel Object in its originating picture. You won't see us use much of this in this class.


Uploaded Image: getX.png
Uploaded Image: getY.png
Confusions & Insights:






makeColorhotPink = makeColor(255, 51, 133)
setColor(somePixel, hotPink)

Using 3 lines to set a color may seem a bit tedious with setRed, setGreen, and setBlue. If you already know your 3 color values, you can create a Color Object, a self-contained entity that has 3 color values for the red, green, and blue. To do that, we use makeColor. Another important reason to create Color Objects is that certain JES functions MUST take in a Color Object as input, like setColor and some of the cool drawing tools we'll show you later in this course.



Uploaded Image: makeColor.png
Confusions & Insights:






makeEmptyPictureblankPicture = makeEmptyPicture(199, 99)
# blankPicture is now actually an empty black picture that's 200 pixels by 100 pixels.

Tired of using a pre-made JPEG like 640x480.jpg for a canvas? You can generate a Picture Object from within JES. makeEmptyPicture takes in a width and a height and returns a Picture Object that is filled with black pixels.


Uploaded Image: makeEmptyPicture.png

NOTE: certain versions of JES have a glitch. Rather than creating an empty picture with the width and height you give it, it'll create a picture with the width you give it + 1 and a height you give it +1. See above example with 199 and 99.


Confusions & Insights:






makePicturepicture = makePicture(r"C:\Pictures\emu.jpg")

makePicture takes in a string (which should be a path to a picture on your computer) and returns a Picture Object which is the actual picture.

Typically you use set some variable equal to the returned value, like above. That way you can refer back to the picture later by just typing the variable name.

What's the benefit of turning a path into a Picture Object? When you do that, you're able to call other methods and functions on the picture like getWidth and getPixels and writePictureTo.


Uploaded Image: makePicture.png
Confusions & Insights:






repaintshow(myCoolPicture)
#Make changes to myCoolPicture
repaint(myCoolPicture)

repaint simply takes a picture that you've already shown using show and updates it with any changes you've made to it since the time you showed it.


Uploaded Image: repaint.png
Confusions & Insights:






setRed, setGreen, setBluesetRed(pixel, 125)
setGreen(pixel, 154)
setBlue(pixel, 58)
print "That pixel is now Vomit Green"

setRed, setGreen, setBlue take in a Pixel Object and an INTEGER value between 0 and 255 inclusive. They will change the corresponding color value in that Pixel Object to that value. If you try to change it to something that isn't a decimal, then it will round DOWN. If you give it a number greater than 255, it'll subtract 256 from your number until it's within the acceptable range. Likewise if you give it a number less than 0, then it'll add 256 until it's within the acceptable range.



Uploaded Image: setRed.png
Confusions & Insights:






setColorsetColor(pixel, gray)
print "That pixel is now gray"

setColor simply takes in a Pixel Object and a Color Object and sets the color of that pixel to the new color. In the above example we are turning the Pixel Object represented by the variable pixel to the pre-defined color gray. To set a color of a pixel using setColor to something other than a pre-defined color, you can create the custom Color Object by using makeColor.



Uploaded Image: setColor.png
Confusions & Insights:






showshow(myCoolPicture)

show takes in a picture object and creates a little pop-up screen with the picture in it. If you make changes to the picture and you want the pop-up to update to reflect the new changes, use repaint


Uploaded Image: show.png
Confusions & Insights:

I've noticed that some people simply use the function show() again rather than repaint(), and it still updates the picture. For example:
show(picture)
greyscale(picture)
show(picture) #with show() here rather than repaint(), assuming the greyscale() function changes the values of the pixels in picture
What's the major difference between the two?





writePictureTowritePictureTo(myCoolPicture, r"C:\some path on my hard drive\llamas.jpg")

writePictureTo takes a Picture Object and a path on your hard drive in the form of a string, and it'll create a JPEG file there of that picture. The path has both a folder path and a file name. If you do not include a specific filename that ends with something.jpg then Odd Things can happen. If you do not specify a folder path (like if you just said writePictureTo(picture, "something.jpg") Odd Things can also happen, so make sure you have both.



Uploaded Image: writePictureTo.png

You may be saying "That's a lie! It doesn't return nothing, it returns a JPEG file, right?"

Wrong!

This function performs an action on your hard drive, but it doesn't return anything back to JES. That means you can't do stuff like...

someVariable = writePictureTo(somepicture, r"Some path")

What would be stored into someVariable? Nothing! But the JPEG will be written to the hard drive.


Confusions & Insights:





Links to this Page