Pic

object Pic

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.

Companion:
class
class Object
trait Matchable
class Any
Pic.type
Inherited
Keywords

Value members

Concrete methods

def apply(pathOrURL: String, anchor: Anchor): Pic

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).

Value parameters:
pathOrURL

a classpath-relative path or a URL string that starts with "http://" or "https://". Note that the O1Library project exports its pics folder, so the example images in that folder can be loaded using just the file name.

anchor

an anchor for the new Pic

Returns:

the loaded image (a bitmap)

def apply(pathOrURL: String): Pic

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).

Value parameters:
pathOrURL

a classpath-relative path or a URL string that starts with "http://" or "https://". Note that the O1Library project exports its pics folder, so the example images in that folder can be loaded using just the file name.

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.

Value parameters:
pathOrURL

a classpath-relative path or a URL string that starts with "http://" or "https://".

Returns:

the loaded image; None in case the attempt failed for any reason

def asOption(pathOrURL: String, anchor: Anchor): Option[Pic]

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.

Value parameters:
pathOrURL

a classpath-relative path or a URL string that starts with "http://" or "https://".

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

the loaded Pic (a bitmap); None in case the attempt failed for any reason

See also:
def asTry(pathOrURL: String, anchor: Anchor): Try[Pic]

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.

Value parameters:
pathOrURL

a classpath-relative path or a URL string that starts with "http://" or "https://".

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

the loaded Pic (a bitmap) or the error that caused the attempt to fail

See also:
def fromColors(width: Int, height: Int, colors: Seq[Color]): Pic

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.

Value parameters:
width

the width, in pixels, of the new Pic

height

the height, in pixels, of the new Pic

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

Returns:

the new Pic (a bitmap)

def generate(width: Int, height: Int, makeColor: (Int, Int) => Color): Pic

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.

Value parameters:
width

the width, in pixels, of the new Pic

height

the height, in pixels, of the new Pic

makeColor

a function that generate calls on every pixel location of the new Pic to produce the color at that location

Returns:

the generated Pic (a bitmap)

def hide(pic: Pic): Unit

Hides the window that has been created (with show) to display the given Pic. If there is no such window, does nothing.

Hides the window that has been created (with show) to display the given Pic. If there is no such window, does nothing.

See also:
def hideAll(): Unit

Hides any and all windows that have been created (with show) to display Pics.

Hides any and all windows that have been created (with show) to display Pics.

See also:
def show(pic: Pic, background: Color, border: Int): Unit

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).

Value parameters:
pic

the image to display; should have a height and width of at least one pixel

background

the color to appear behind the Pic in the frame (where the Pic is transparent)

border

the width of the simple black window frame, in pixels

See also:

Inherited methods

def circle(diameter: Double, color: Color, anchor: Anchor): Pic

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.

Value parameters:
diameter

the diameter of the circle, which also sets the width and height of the Pic

color

the circle’s color

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

a Pic of the circle (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def ellipse(width: Double, height: Double, color: Color, anchor: Anchor): Pic

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.

Value parameters:
width

the width of the ellipse and the Pic

height

the height of the ellipse and the Pic

color

the ellipse’s color

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

a Pic of the ellipse (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def emptyCanvas(width: Double, height: Double, color: Color): Pic

Creates a new Pic that portrays a filled rectangle and sets its Anchor at TopLeft.

Creates a new Pic that portrays a filled rectangle and sets its Anchor at TopLeft.

Value parameters:
width

the width of the rectangle and the Pic

height

the height of the rectangle and the Pic

color

the color of the rectangle and thus the only color visible in the Pic; if unspecified, defaults to White

Returns:

a Pic of the rectangle (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def line(from: Pos, to: Pos, color: Color): Pic

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.

Value parameters:
from

the line’s “starting point”; the Pic will anchor at the corresponding corner

to

the line’s “end point”

color

the color of the line

Returns:

a Pic of the line (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def polygon(points: Seq[Pos], color: Color, anchor: Anchor): Pic

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.

Value parameters:
points

the polygon’s corners (only their relative positioning matters)

color

the polygon’s color

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

a Pic of the rectangle (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def rectangle(width: Double, height: Double, color: Color, anchor: Anchor): Pic

Creates a new Pic that portrays a filled rectangle.

Creates a new Pic that portrays a filled rectangle.

Value parameters:
width

the width of the rectangle and the Pic

height

the height of the rectangle and the Pic

color

the color of the rectangle and thus the only color visible in the Pic

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

a Pic of the rectangle (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def rectangle(bounds: Bounds, color: Color): Pic

Creates a new Pic that portrays a filled rectangle. Sets its Anchor at TopLeft.

Creates a new Pic that portrays a filled rectangle. Sets its Anchor at TopLeft.

Value 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

Returns:

a Pic of the rectangle (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def square(side: Double, color: Color, anchor: Anchor): Pic

Creates a new Pic that portrays a filled square.

Creates a new Pic that portrays a filled square.

Value parameters:
side

the width and height of the square and the Pic

color

the color of the square and thus the only color visible in the Pic

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

a Pic of the square (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def star(width: Double, color: Color, anchor: Anchor): Pic

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.

Value parameters:
width

the width of the star, which determines the Pic’s dimensions

color

the star’s color

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

a Pic of the star (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def triangle(width: Double, height: Double, color: Color, anchor: Anchor): Pic

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.

Value parameters:
width

the width of the triangle’s base, which determines the width of the Pic, too

height

the height of the triangle, which determines the height of the Pic, too

color

the triangle’s color

anchor

an anchor for the new Pic; if unspecified, defaults to Center

Returns:

a Pic of the triangle (a vector graphic)

Inherited from:
ShapeAPI (hidden)

Givens