Pic

o1.gui.Pic
See thePic companion class
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.

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Pic.type

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 its pics 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 its pics 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 new Pic to produce the color at that location

width

the width, in pixels, of the new Pic

Attributes

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.

Attributes

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.

Attributes

See also

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 the Pic 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 an arcing line. The line is specified in terms of an ellipse: it has a starting point and a length along an (otherwise invisible) elliptical curve. The background is fully transparent.

Creates a new Pic that portrays an arcing line. The line is specified in terms of an ellipse: it has a starting point and a length along an (otherwise invisible) elliptical curve. The background is fully transparent.

Parameters

anchor

an anchor for the new Pic; if unspecified, defaults to Center, i.e., the center of the ellipse

fill

an optional fill style for the ellipse segment; if unspecified, there is no fill, just the arc

height

the height of the ellipse that defines the arc; this also becomes the height of the resulting image

lengthDegrees

the length of the arc (e.g., 10 degrees means a small part of the ellipse and 180 degrees means half an ellipse)

startDegrees

the position along the ellipse where the arc starts (e.g., 0 degrees means at the rightmost point, 90 degrees at the top, and 270 degrees at the bottom)

style

the stroke style of the line (color, width, etc.)

width

the width of the ellipse that defines the arc; this also becomes the width of the resulting image

Attributes

Returns

a Pic of the arc (a vector graphic)

Inherited from:
ShapeAPI (hidden)

Creates a new Pic that portrays an arcing line. The line is specified in terms of an ellipse: it has a starting point and a length along an (otherwise invisible) elliptical curve. The background is fully transparent. This version of arc specifies the line style in terms of color and thickness. The anchor of the image is at the center of the defining ellipse.

Creates a new Pic that portrays an arcing line. The line is specified in terms of an ellipse: it has a starting point and a length along an (otherwise invisible) elliptical curve. The background is fully transparent. This version of arc specifies the line style in terms of color and thickness. The anchor of the image is at the center of the defining ellipse.

Parameters

color

the color of the arc

height

the height of the ellipse that defines the arc; this also becomes the height of the resulting image

lengthDegrees

the length of the arc (e.g., 10 degrees means a small part of the ellipse and 180 degrees means half an ellipse)

startDegrees

the position along the ellipse where the arc starts (e.g., 0 degrees means at the rightmost point, 90 degrees at the top, and 270 degrees at the bottom)

thickness

the width of the arc

width

the width of the ellipse that defines the arc; this also becomes the width of the resulting image

Attributes

Returns

a Pic of the arc (a vector graphic)

Inherited from:
ShapeAPI (hidden)

Creates a new Pic that portrays a circle. The background is fully transparent.

Creates a new Pic that portrays a circle. The background is fully transparent.

Parameters

anchor

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

diameter

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

fill

the circle’s color or some other fill style (such as a gradient)

outline

the style of the circle’s outline; if unspecified, defaults to no outline (Line.None)

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

fill

the ellipse’s color or some other fill style (such as a gradient)

height

the height of the ellipse and the Pic

outline

the style of the ellipse’s outline; if unspecified, defaults to no outline (Line.None)

width

the width of the ellipse and the Pic

Attributes

Returns

a Pic of the ellipse (a vector graphic)

Inherited from:
ShapeAPI (hidden)

Creates a new Pic that portrays a filled, single-color rectangle and sets its Anchor at TopLeft.

Creates a new Pic that portrays a filled, single-color rectangle and sets its Anchor at TopLeft.

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 an equilateral 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 equilateral 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

fill

the triangle’s color or some other fill style (such as a gradient)

outline

the style of the triangle’s outline; if unspecified, defaults to no outline (Line.None)

side

the length of the triangle’s each side, which determines the width of the Pic, too

Attributes

Returns

a Pic of the triangle (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

fill

the triangle’s color or some other fill style (such as a gradient)

height

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

outline

the style of the triangle’s outline; if unspecified, defaults to no outline (Line.None)

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)

Creates a new Pic that portrays a 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 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.

This version of line specifies the line style as a color and a width. The line ends are round. Calling line(pos1, pos2, Blue, 3) is equivalent to calling line(pos1, pos2, Stroke(Blue, 3, Line.Cap.Round)).

Parameters

color

the color of the line

from

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

thickness

the line’s width in pixels; defaults to `1.0``

to

the line’s “end point”

Attributes

Returns

a Pic of the line (a vector graphic)

Inherited from:
ShapeAPI (hidden)
def line(from: Pos, to: Pos, style: Stroke): Pic

Creates a new Pic that portrays a 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 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

from

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

style

the stroke style of the line (color, width, etc.)

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

fill

the polygon’s color or some other fill style (such as a gradient)

outline

the style of the polygon’s outline; if unspecified, defaults to no outline (Line.None)

points

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

Attributes

Returns

a Pic of the polygon (a vector graphic)

Inherited from:
ShapeAPI (hidden)

Creates a new Pic that portrays a rectangle.

Creates a new Pic that portrays a rectangle.

Parameters

anchor

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

fill

the rectangle’s color or some other fill style (such as a gradient)

height

the height of the rectangle and the Pic

outline

the style of the rectangle’s outline; if unspecified, defaults to no outline (Line.None)

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

Creates a new Pic that portrays a square.

Parameters

anchor

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

fill

the square’s color or some other fill style (such as a gradient)

outline

the style of the square’s outline; if unspecified, defaults to no outline (Line.None)

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

fill

the star’s color or some other fill style (such as a gradient)

outline

the style of the star’s outline; if unspecified, defaults to no outline (Line.None)

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 contains the given text. The picture is just large enough to contain the text; its background is fully transparent.

Creates a new Pic that contains the given text. The picture is just large enough to contain the text; its background is fully transparent.

Parameters

anchor

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

content

the text to display in the picture

fill

the text’s color or some other fill style (such as a gradient); if unspecified, defaults to colors.Black

font

the name of a font family or specific font (e.g., "Serif", "SansSerif", "Times New Roman" or "Times New Roman Italic"); the font must be installed on the computer (the tools in o1.gui.font can check what is installed) or a default font will be used instead

outline

a styling for character outlines; if unspecified, defaults to no outline (Line.None)

size

the font size

Attributes

Returns

a Pic of the text (a vector graphic)

Inherited from:
ShapeAPI (hidden)

Concrete fields

val empty: Pic

An image with no content.

An image with no content.

Attributes

Givens

Givens