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. “apple.jpg” or “apple.png”).
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.

Additionally, you may use the following functions:

Function Description
icon1.getWidth() Returns the width of icon1 (in pixels).
icon1.getHeight() Returns the height of icon1 (in pixels).
icon1.setSize(width, height) Changes/stretches the width and height of icon1 (in pixels).
icon1.setWidth(width) Sets the width of icon1 (in pixels).
icon1.setHeight(height) Sets the height of icon1 (in pixels).
icon1.getPixel(col, row) Returns this pixel’s RGB values (a list, e.g., [255, 0, 0]), where col is the icon column, and row is the icon row.  The icon 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 icon column, and row is the icon row.  The icon origin (0, 0) is at top left.
icon1.getPixels() Returns a 2D list of pixels (a list of rows). Each row is a list of pixels. Each pixel is a list of RGB values, e.g., [255, 0, 0].
icon1.setPixels(pixels) Sets the icon to display the provided 2D list of pixels – use same format as icon1.getPixels().
icon1.rotate(angle) Rotates the icon by angle degrees.
icon1.crop(x, y, width, height) Crops the icon starting from point x, y up to width and height (from the point x, y).

Finally, 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(width) Sets the y coordinate (in pixels).
icon1.getPosition() Returns the position as an (x, y) tuple.
icon1.setPosition(x, y) Sets the position to x, y.
icon1.encloses(other) Returns True if icon1 encloses other (may be any Widget or Graphics object).
icon1.intersects(other) Returns True if icon1 intersects other (may be any Widget or Graphics object).