Table of Contents > Understanding Pictures in JES > Picture Functions in JES
Picture Functions in JES

This is a list of functions that you may find useful when you are creating programs to manipulate or create pictures in JES. Remember, these functions are part of a special library, and are not available in other Jython programming environments.
addLine addLine(picture, color, startX, startY, endX, endY):
picture: the picture you want to draw the line on
color: the color you want to draw in
startX: the x position you want the line to start
startY: the y position you want the line to start
endX: the x position you want the line to end
endY: the y position you want the line to end
Takes a picture, a starting (x, y) position (two numbers), and an ending (x, y) position (two more numbers, four total) and draws a black line from the starting point to the ending point in the picture.
addOval
addOval(picture, color, startX, startY, width, height):
picture: the picture you want to draw the rectangle on
color: the color you want to draw in
startX: the x-coordinate of the upper left-hand corner of the rectangle
startY: the y-coordinate of the upper left-hand corner of the rectangle
width: the width of the rectangle
height: the height of the rectangle
Takes a picture, a starting (x, y) position (two numbers), and a width and height (two more numbers, four total) then draws an oval in outline of the given width and height with the position (x, y) as the upper left corner.
addOvalFilled
addOvalFilled(picture, color, startX, startY, width, height):
picture: the picture you want to draw the rectangle on
color: the color you want to draw in
startX: the x-coordinate of the upper left-hand corner of the rectangle
startY: the y-coordinate of the upper left-hand corner of the rectangle
width: the width of the rectangle
height: the height of the rectangle
Takes a picture, a starting (x, y) position (two numbers), and a width and height (two more numbers, four total) then draws a filled oval of the given width and height with the position (x, y) as the upper left corner.
addRect
addRect(picture, color, startX, startY, width, height):
picture: the picture you want to draw the rectangle on
color: the color you want to draw in
startX: the x-coordinate of the upper left-hand corner of the rectangle
startY: the y-coordinate of the upper left-hand corner of the rectangle
width: the width of the rectangle
height: the height of the rectangle
Takes a picture, a starting (x, y) position (two numbers), and a width and height (two more numbers, four total) then draws a rectangle in outline of the given width and height with the position (x, y) as the upper left corner.
addRectFilled addRectFilled(picture, color, startX, startY, width, height):
picture: the picture you want to draw the rectangle on
color: the color you want to draw in
startX: the x-coordinate of the upper left-hand corner of the rectangle
startY: the y-coordinate of the upper left-hand corner of the rectangle
width: the width of the rectangle
height: the height of the rectangle
Takes a picture, a starting (x, y) position (two numbers), and a width and height (two more numbers, four total) then draws a filled rectangle of the given width, height and color with the position (x, y) as the upper left corner.
addText addText(picture, color, xpos, ypos, text):
picture: the picture you want to add the text to
color: the color you want to draw in
xpos: the x-coordinate where you want to start writing the text
ypos: the y-coordinate where you want to start writing the text
text: s string containing the text you want written
Takes a picture, an x position and a y position (two numbers), and some text as a string, which will get drawn into the picture, in the specified color.
distance distance(color1, color2):
color1: the first color you want compared
color2: the second color you want compared
Takes two Color objects and returns a single number representing the distance between the colors. The red, green, and blue values of the colors are taken as a point in (x, y, z) space, and the cartesian distance is computed.
getColor getColor(pixel):
pixel: the pixel you want to extract the color from
returns: a color, the color from the pixel
Takes a Pixel and returns the Color object at that pixel.
getRed getRed(pixel):
pixel: the pixel you want to get the amount of red from
returns: the red value of the pixel
Takes a Pixel object and returns the value (between 0 and 255) of the amount of redness in that pixel.
getGreen getGreen(pixel):
pixel: the pixel you want to get the amount of green from
returns: the green value of the pixel
Takes a Pixel object and returns the value (between 0 and 255) of the amount of greenness in that pixel.
getBlue getBlue(pixel):
pixel: the pixel you want to get the amount of blue from
returns: the blue value of the pixel
Takes a Pixel object and returns the value (between 0 and 255) of the amount of blueness in that pixel.
getHeight getHeight(picture):
picture: the picture you want to get the height of
returns: the height of the picture
Takes a picture as input and returns its length in the number of pixels top-to-bottom in the picture.
getPixels getPixels(picture):
picture: the picture you want to get the pixels from
returns: a list of all the pixels in the picture
Takes a picture as input and returns the sequence of Pixel objects in the picture.
getAllPixels getAllPixels(picture):
picture: the picture you want to get the pixels from
returns: a list of all the pixels in the picture
Takes a picture as input and returns the sequence of Pixel objects in the picture. This is another name for "getPixels".
getPixel getPixel(picture, xpos, ypos):
picture: the picture you want to get the pixel from
xpos: the x-coordinate of the pixel you want
ypos: the y-coordinate of the pixel you want
Takes a picture, an x position and a y position (two numbers), and returns the Pixel object at that point in the picture.
getWidth getWidth(picture):
picture: the picture you want to get the width of
returns: the width of the picture
Takes a picture as input and returns its length in the number of pixels left-to-right in the picture.
getX getX(pixel):
pixel: the pixel you want to find the x-coordinate of
returns: the x-coordinate of the pixel Takes in a pixel object and returns the x position of where that pixel is in the picture.
getY getY(pixel):
pixel: the pixel you want to find the y-coordinate of
returns: the y-coordinate of the pixel Takes in a pixel object and returns the y position of where that pixel is in the picture.
makeColor makeColor(red, green, blue):
red: the amount of red you want in the color
green: the amount of green you want in the color
blue: the amount of blue you want in the picture
returns: the color made from the inputs
Takes three inputs: For the red, green, and blue components (in order), then returns a color object.
makeDarker makeDarker(color):
color: the color you want to darken
returns: the new, darker color
Takes a color and returns a slightly darker version of the original color.
makeLighter makeLighter(color):
color: the color you want to lighten
returns: the new, lighter color
Takes a color and returns a slightly lighter version of the original color.
makeEmptyPicture makeEmptyPicture(width, height):
width: the width of the empty picture
height: height of the empty picture
returns: a new picture object, with all the pixels set to black
Makes a new "empty" picture and returns it to you. width and height must be between 0 and 10000.
makePicture makePicture(path):
path: the name of the file you want to open as a picture
returns: a picture object made from the file
Takes a filename as input, reads the file, and creates a picture from it. Returns the picture.
pickAColor pickAColor():
returns: the color selected in the picker
Takes no input, but puts up a color picker. Find the color you want, and the function will return the Color object of what you picked.
pickAFile pickAFile():
returns: a string containing the path to the file selected in the file picker
Lets the user pick a file and returns the complete path name as a string. No input.
setColor setColor(pixel, color):
pixel: the pixel you want to set the color of
color: the color you want to set the pixel to
Takes in a pixel and a color, and sets the pixel to the provided color.
repaint repaint(picture):
picture: the picture you want to repaint
Repaints the picture if it has been opened in a window from show(picture).
setRed setRed(pixel, redValue):
pixel: the pixel you want to set the red value in.
redValue: a number (0 - 254) for the new red value of the pixel
Takes in a Pixel object and a value (between 0 and 254) and sets the redness of that pixel to the given value.
setGreen setGreen(pixel, greenValue):
pixel: the pixel you want to set the green value in.
greenValue: a number (0 - 254) for the new green value of the pixel
Takes in a Pixel object and a value (between 0 and 254) and sets the greenness of that pixel to the given value.
setBlue setBlue(pixel, blueValue):
pixel: the pixel you want to set the blue value in.
blueValue: a number (0 - 254) for the new blue value of the pixel
Takes in a Pixel object and a value (between 0 and 254) and sets the blueness of that pixel to the given value.
show show(picture):
picture: the picture you want to see
Shows the picture provided as input.
writePictureTo writePictureTo(picture, path):
picture: the picture you want to be written out to a file
path: the path to the file you want the picture written to
Takes a picture and a file name (string) as input, then writes the picture to the file as a JPEG. (Be sure to end the filename in ".jpg" for the operating system to understand it well.)


jump to top