Icon

Icon objects contain external images (.jpg or .png).  They are created using the following functions:

Function Description
Icon(filename) Imports an image from the given filename (e.g. “mona-lisa.jpg” or “mona-lisa.jpg”).
Icon(filename, width) Imports an image from the given filename and resizes it (proportionally) using the provided width (in pixels).
Icon(filename, width, height) Imports an image from the given filename and resizes (stretches) it using the provided width and height (in pixels).

Once an Icon has been created, it may be added to a Display specifying where to place its top-left corner point.

icon1 = Icon("mona-lisa.jpg")
d.add(icon1, 50, 50)

Icons objects have the following functions:

Function Description
icon1.getWidth() Returns the width (in pixels).
icon1.getHeight() Returns the height (in pixels).
icon1.setSize(width, height) Changes/stretches the width and height (in pixels).
icon1.rotate(angle) Rotates the image angle degrees.
icon1.crop(x, y, width, height) Crops the image starting from point x, y up to width and height (from the point x, y).
icon1.getPixel(col, row) Returns this pixel’s RGB values (a list, e.g., [255, 0, 0]), where col is the image column, and row is the image row.  The image origin (0, 0) is at top left.
icon1.setPixel(col, row, RGBlist) Sets this pixel’s RGB values, e.g., [255, 0, 0], where col is the image column, and row is the image row.  The image origin (0, 0) is at top left.
icon1.getPixels() Returns all the pixels in this image in a list of rows. Each row is a list of pixels for that row. Each pixel is a list of RGB values, e.g., [255, 0, 0]. I.e., the image’s top-left pixel is at index [0][0].
icon1.setPixels(pixels) Sets all the pixels in this image, where pixels in a list of rows. Each row is a list of pixels for that row. Each pixel is a list of RGB values, e.g., [255, 0, 0]. I.e., the image’s top-left pixel is at index [0][0].

Finally, similarly to other graphics objects, you may use the following functions:

Function Description
icon1.getX() Returns the x coordinate (in pixels).
icon1.getY() Returns the y coordinate (in pixels).
icon1.setX(x) Sets the x coordinate (in pixels).
icon1.setY(y) Sets the y coordinate (in pixels).
icon1.encloses(other) Returns True if icon1 encloses other graphics object.
icon1.intersects(other) Returns True if icon1 intersects other graphics object.
icon1.getPosition() Returns the position as an (x, y) tuple.  This is the top-left corner of the box that encloses the icon.
icon1.setPosition(x, y) Sets the position to x, y.  This is the top-left corner of the box that encloses the icon.