The primary purpose of this companion object of class Pic
is to provide methods for creating new Pic instances: (apply, generate, circle, etc. There is also a small selection of related utility methods.
This object has an alias in the top-level package o1, so it’s accessible to students simply via import o1.*
. The shape-creating methods of this object (such as circle
) are also available as functions in package o1.
Attributes
Members list
Value members
Concrete methods
Takes an image file path or URL as a string, loads image data from that location, and constructs an anchored Pic from that data. Throws an error if the file doesn’t exist or could not be accessed (cf. asTry, asOption).
Takes an image file path or URL as a string, loads image data from that location, and constructs an anchored Pic from that data. Throws an error if the file doesn’t exist or could not be accessed (cf. asTry, asOption).
Parameters
- anchor
-
an anchor for the new
Pic
- pathOrURL
-
a classpath-relative path or a URL string that starts with
"http://"
or"https://"
. Note that the O1Library project exports itspics
folder, so the example images in that folder can be loaded using just the file name.
Attributes
- Returns
-
the loaded image (a bitmap)
Takes an image file path or URL as a string, loads image data from that location, and constructs a Pic from that data. Anchors the Pic
at its center. Throws an error if the file doesn’t exist or could not be accessed (cf. asTry, asOption).
Takes an image file path or URL as a string, loads image data from that location, and constructs a Pic from that data. Anchors the Pic
at its center. Throws an error if the file doesn’t exist or could not be accessed (cf. asTry, asOption).
Parameters
- pathOrURL
-
a classpath-relative path or a URL string that starts with
"http://"
or"https://"
. Note that the O1Library project exports itspics
folder, so the example images in that folder can be loaded using just the file name.
Attributes
- Returns
-
the loaded image (a bitmap)
Takes an image file path or URL as a string and attempts to load image data from that location and construct a BufferedImage from that data. Note that this method does not construct a Pic at all.
Takes an image file path or URL as a string and attempts to load image data from that location and construct a BufferedImage from that data. Note that this method does not construct a Pic at all.
Parameters
- pathOrURL
-
a classpath-relative path or a URL string that starts with
"http://"
or"https://"
.
Attributes
- Returns
-
the loaded image;
None
in case the attempt failed for any reason
Takes an image file path or URL as a string and attempts to load image data from that location and construct a Pic from that data.
Takes an image file path or URL as a string and attempts to load image data from that location and construct a Pic from that data.
Parameters
- anchor
-
an anchor for the new
Pic
; if unspecified, defaults to Center - pathOrURL
-
a classpath-relative path or a URL string that starts with
"http://"
or"https://"
.
Attributes
- Returns
-
the loaded Pic (a bitmap);
None
in case the attempt failed for any reason - See also
Takes an image file path or URL as a string and attempts to load image data from that location and construct a Pic from that data.
Takes an image file path or URL as a string and attempts to load image data from that location and construct a Pic from that data.
Parameters
- anchor
-
an anchor for the new
Pic
; if unspecified, defaults to Center - pathOrURL
-
a classpath-relative path or a URL string that starts with
"http://"
or"https://"
.
Attributes
- Returns
-
the loaded Pic (a bitmap) or the error that caused the attempt to fail
- See also
Creates a new Pic by setting colors of each individual pixel according to the colors
list.
Creates a new Pic by setting colors of each individual pixel according to the colors
list.
Parameters
- colors
-
a sequence of colors, one per pixel, starting from the upper-left corner and continuing to the right and line-by-line towards the bottom
- height
-
the height, in pixels, of the new
Pic
- width
-
the width, in pixels, of the new
Pic
Attributes
- Returns
-
the new Pic (a bitmap)
Creates a new Pic by applying the given pixel-generating function to each pair coordinates within the new image.
Creates a new Pic by applying the given pixel-generating function to each pair coordinates within the new image.
Parameters
- height
-
the height, in pixels, of the new
Pic
- makeColor
-
a function that
generate
calls on every pixel location of the newPic
to produce the color at that location - width
-
the width, in pixels, of the new
Pic
Attributes
- Returns
-
the generated Pic (a bitmap)
Displays the given Pic in a minimalistic GUI window. Calling this method repeatedly on the same Pic doesn’t display multiple windows but reuses the existing one. This method is meant only for experimentation and debugging; not for GUI construction (cf. views).
Displays the given Pic in a minimalistic GUI window. Calling this method repeatedly on the same Pic doesn’t display multiple windows but reuses the existing one. This method is meant only for experimentation and debugging; not for GUI construction (cf. views).
Parameters
- background
-
the color to appear behind the
Pic
in the frame (where thePic
is transparent) - border
-
the width of the simple black window frame, in pixels
- pic
-
the image to display; should have a height and width of at least one pixel
Attributes
- See also
Inherited methods
Creates a new Pic that portrays a filled circle. The background is fully transparent.
Creates a new Pic that portrays a filled circle. The background is fully transparent.
Parameters
- anchor
-
an anchor for the new Pic; if unspecified, defaults to Center
- color
-
the circle’s color
- diameter
-
the diameter of the circle, which also sets the width and height of the Pic
Attributes
- Returns
-
a Pic of the circle (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Creates a new Pic that portrays an ellipse. The background is fully transparent.
Creates a new Pic that portrays an ellipse. The background is fully transparent.
Parameters
- anchor
-
an anchor for the new Pic; if unspecified, defaults to Center
- color
-
the ellipse’s color
- height
-
the height of the ellipse and the Pic
- width
-
the width of the ellipse and the Pic
Attributes
- Returns
-
a Pic of the ellipse (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Parameters
- color
-
the color of the rectangle and thus the only color visible in the Pic; if unspecified, defaults to
White
- height
-
the height of the rectangle and the Pic
- width
-
the width of the rectangle and the Pic
Attributes
- Returns
-
a Pic of the rectangle (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Creates a new Pic that portrays a thin line. The line is specified in terms of two Pos objects: imagine drawing a line between the two points on a plane and then cropping the plane to just the part that contains the line.
Creates a new Pic that portrays a thin line. The line is specified in terms of two Pos objects: imagine drawing a line between the two points on a plane and then cropping the plane to just the part that contains the line.
The line always runs from one corner of the resulting Pic to another. The Anchor of the Pic is at one of the four corners: the one that’s closest to from
.
The background is fully transparent.
Parameters
- color
-
the color of the line
- from
-
the line’s “starting point”; the Pic will anchor at the corresponding corner
- to
-
the line’s “end point”
Attributes
- Returns
-
a Pic of the line (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Creates a new Pic that portrays a filled polygon. The picture is just large enough to contain the polygon; its background is fully transparent.
Creates a new Pic that portrays a filled polygon. The picture is just large enough to contain the polygon; its background is fully transparent.
Parameters
- anchor
-
an anchor for the new Pic; if unspecified, defaults to Center
- color
-
the polygon’s color
- points
-
the polygon’s corners (only their relative positioning matters)
Attributes
- Returns
-
a Pic of the rectangle (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Creates a new Pic that portrays a filled rectangle.
Creates a new Pic that portrays a filled rectangle.
Parameters
- anchor
-
an anchor for the new Pic; if unspecified, defaults to Center
- color
-
the color of the rectangle and thus the only color visible in the Pic
- height
-
the height of the rectangle and the Pic
- width
-
the width of the rectangle and the Pic
Attributes
- Returns
-
a Pic of the rectangle (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Parameters
- bounds
-
the width and height of the rectangle and the Pic
- color
-
the color of the rectangle and thus the only color visible in the Pic
Attributes
- Returns
-
a Pic of the rectangle (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Creates a new Pic that portrays a filled square.
Creates a new Pic that portrays a filled square.
Parameters
- anchor
-
an anchor for the new Pic; if unspecified, defaults to Center
- color
-
the color of the square and thus the only color visible in the Pic
- side
-
the width and height of the square and the Pic
Attributes
- Returns
-
a Pic of the square (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Creates a new Pic that portrays a five-pointed star. The background is fully transparent.
Creates a new Pic that portrays a five-pointed star. The background is fully transparent.
Parameters
- anchor
-
an anchor for the new Pic; if unspecified, defaults to Center
- color
-
the star’s color
- width
-
the width of the star, which determines the Pic’s dimensions
Attributes
- Returns
-
a Pic of the star (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)
Creates a new Pic that portrays an isosceles triangle. The triangle’s base is at the bottom of the image, and its apex is at the top center. The background is fully transparent.
Creates a new Pic that portrays an isosceles triangle. The triangle’s base is at the bottom of the image, and its apex is at the top center. The background is fully transparent.
Parameters
- anchor
-
an anchor for the new Pic; if unspecified, defaults to Center
- color
-
the triangle’s color
- height
-
the height of the triangle, which determines the height of the Pic, too
- width
-
the width of the triangle’s base, which determines the width of the Pic, too
Attributes
- Returns
-
a Pic of the triangle (a vector graphic)
- Inherited from:
- ShapeAPI (hidden)