The media Module

The media module. This contains global convenience functions for manipulating PyGraphics objects, and imports all the supporting modules fully.

Pictures currently support the following formats: JPEG, BMP, GIF, TIFF, IM, MSP, PNG, PCX, and PPM.

Sounds support is self-contained in sound_media.py, and must be imported separately.

media.add_line(pic, x1, y1, x2, y2, col)

Draw a line of Color col from (x1, y1) to (x2, y2) on Picture pic.

media.add_oval(pic, x, y, w, h, col)

Draw an empty oval of Color col, width w, and height h on Picture pic. The upper left corner of the oval is at (x, y).

media.add_oval_filled(pic, x, y, w, h, col)

Draw a filled oval of Color col, width w, and height h on Picture pic. The upper left corner of the oval is at (x, y).

media.add_polygon(pic, point_list, col)

Draw an empty polygon of Color col with corners for every vertex in list point_list on Picture pic.

Note: point_list is a list containing vertices xy coordinates (ex. [x1,y1,x2,y2,x3,y3]) It should contain at least three coordinate pairs.

media.add_polygon_filled(pic, point_list, col)

Draw an empty polygon of Color col with corners for every vertex in list point_list on Picture pic.

Note: point_list is a list containing vertices xy coordinates (ex. [x1,y1,x2,y2,x3,y3]) It should contain at least three coordinate pairs.

media.add_rect(pic, x, y, w, h, col)

Draw an empty rectangle of Color col, width w, and height h on Picture pic. The upper left corner of the rectangle is at (x, y).

media.add_rect_filled(pic, x, y, w, h, col)

Draw a filled rectangle of Color col, width w, and height h on Picture pic. The upper left corner of the rectangle is at (x, y).

media.add_text(pic, x, y, s, col)

Draw str s in Color col on Picture pic starting at (x, y).

media.choose_color()

Prompt user to pick a color. Return a RGB Color object.

media.choose_file()

Prompt user to pick a file. Return the path to that file.

media.choose_folder()

Prompt user to pick a folder. Return the path to that folder.

media.choose_save_filename()

Prompt user to pick a directory and filename. Return the path to the new file.

media.close(pic)

Close Picture pic’s display.

media.close_inspect(obj)

Close an open inspector window for object obj. Works on Sound and Picture objects.

media.copy(obj)

Return a deep copy of object obj. Works on Color, Sound, and Picture objects.

media.create_color(r, g, b)

Return a Color object with RGB values r, g, and b.

media.create_picture(w, h, col=Color(255, 255, 255))

Return a Picture w pixels wide and h pixels high. Default Color col is white.

media.crop(pic, x1, y1, x2, y2)

Crop Picture pic so that only pixels inside the rectangular region with upper-left coordinates (x1, y1) and lower-right coordinates (x2, y2) remain. The new upper-left coordinate is (0, 0).

media.crop_picture(pic, x1, y1, x2, y2)

Crop Picture pic so that only pixels inside the rectangular region with upper-left coordinates (x1, y1) and lower-right coordinates (x2, y2) remain. The new upper-left coordinate is (0, 0).

media.darken(col)

Darken Color col by 35%.

media.distance(col1, col2)

Return the Euclidean distance between the RGB values of Color col1 and Color col2.

media.get_blue(pix)

Return the blue value of Pixel pix.

media.get_color(pix)

Return the Color object with Pixel pix’s RGB values.

media.get_green(pix)

Return the green value of Pixel pix.

media.get_height(pic)

Return how many pixels high Picture pic is.

media.get_pixel(pic, x, y)

Return the Pixel object at the coordinates (x, y) in Picture pic.

media.get_pixels(pic)

Return a list of Picture pic’s Pixels from top to bottom, left to right.

media.get_red(pix)

Return the red value of Pixel pix.

media.get_width(pic)

Return how many pixels wide Picture pic is.

media.get_x(pix)

Return the x coordinate of Pixel pix.

media.get_y(pix)

Return the y coordinate of Pixel pix.

media.inspect(obj)

Inspect object obj. Works on Sound and Picture objects.

media.lighten(col)

Lighten Color col by 35%.

media.load_picture(filename)

Return a Picture object from filename filename.

media.save(obj)

Write media.py object obj back to its previous file.

media.save_as(obj, filename=None)

Prompt user to pick a directory and filename then write media.py object obj to that filename. Requires that file format is specified in filename by extensions.

media.say(text)

Display text to the user in a GUI window.

media.set_blue(pix, b)

Set the blue value of Pixel pix to b.

media.set_color(pix, col)

Set the RGB values of Pixel pix to those of Color col.

media.set_green(pix, g)

Set the green value of Pixel pix to g.

media.set_red(pix, r)

Set the red value of Pixel pix to r.

media.show(pic)

Display Picture pic in separate window.

media.show_external(pic)

Display Picture pic in an external application. The specific application depends on the operating system.

media.update(pic)

Update Picture pic’s display window.

Previous topic

Welcome to the PyGraphics User documentation

Next topic

The picture Module

This Page