Packages

  • package root
    Definition Classes
    root
  • package o1

    O1Library is a toolkit designed for the course Programming 1 (a.k.a. O1) at Aalto University.

    O1Library is a toolkit designed for the course Programming 1 (a.k.a. O1) at Aalto University. It contains an assortment of tools; most prominently, it provides a framework for simple graphical programming and utilities for playing sound.

    This is the front page of O1Library’s documentation. However, this is probably not the best place to start learning about O1Library as a student. That’s because the relevant content of this library is introduced bit by bit in the chapters of O1’s custom ebook alongside the associated programming concepts and assignments.

    You may still find this documentation useful as a reference. You can also find some optional content here that you may wish to try.

    This front page lists the content available in the top-level package called simply o1. These tools are available with the simple command import o1._ in your Scala programs. Some of them you’ll use a lot; some of them you won’t necessarily need at all.

    The tools listed here are actually implemented in a number of subpackages (o1.gui, o1.sound, etc.); what you see here are just “shortcut aliases” to those actual implementations. The aliases are here to make that convenient import command work and to provide you with this list of links to some of the more commonly used tools in O1Library. The subpackages also contain additional content not listed here.

    O1Library has been developed by Aleksi Lukkarinen and Juha Sorva. Several of the key components in o1.gui and o1.world are built upon Aleksi’s Scala Media Computation Library. Some parts of O1Library draw inspiration from the “teachpacks” of the Racket programming language.

    We are grateful to Riku Autio, Joonatan Honkamaa, Juhani Numminen, Leo Varis, Veera Kahva, and anonymous students for bug reports and fixes. We thank Otto Seppälä for helpful discussions.

    Definition Classes
    root
  • package gui

    This package contains tools for building simple GUIs.

    This package contains tools for building simple GUIs. The toolkit is particularly well suited to constructing GUIs that display information as 2D images and/or geometric shapes. It is not designed for demanding graphical needs that call for high efficiency. Some of the tools in this package are built on the Swing GUI library, and the two libraries can be used in combination.

    Some of the types in this package have aliases in the top-level package o1, so they are accessible to students simply via import o1._. Some of the package contents are not available in the top-level package or included in this documentation.

    Please note: One of this package’s key components (views) comes in multiple varieties, which which are defined in the subpackages o1.gui.mutable and o1.gui.immutable and not listed below. The View that is most commonly used in O1 (and aliased as o1.View in the top-level package) is o1.gui.mutable.ViewFrame.

    Definition Classes
    o1
  • package colors

    This package contains Color constants.

    This package contains Color constants. They cover all the colors listed in the W3C’s CSS Color Module specification (July 5th, 2017); there are some additional ones as well.

    All the colors are fully opaque, except Transparent, which is fully transparent.

    The contents of this package are aliased in the top-level package o1 so that they are accessible to students simply via import o1._.

    Definition Classes
    gui
  • package event

    This package exists in order to provide aliases to event classes in Swing and to add some methods to Swing’s InputEvent via o1.gui.event.ConvenientInputEvent.

    This package exists in order to provide aliases to event classes in Swing and to add some methods to Swing’s InputEvent via o1.gui.event.ConvenientInputEvent.

    The contents of this package are aliased in the top-level package o1, so that they are accessible to students simply via* import o1._.

    Definition Classes
    gui
  • package layout

    The package o1.gui.layout contains utilities that make it more convenient to lay out components in simple GridBagPanels from Scala's Swing library.

    The package o1.gui.layout contains utilities that make it more convenient to lay out components in simple GridBagPanels from Scala's Swing library. These utilities are used internally by some of the given GUIs in O1.

    NOTE TO STUDENTS: In this course, you don't need to understand how this package works or can be used.

    Definition Classes
    gui
  • Animation
  • Color
  • DefaultFrameSettings
  • Dialog
  • Escapable
  • Pic
  • SimpleFrame
  • TerminatesOnClose
  • View
  • immutable
  • mutable

final class Pic extends HasAnchor

Each instance of this class represents a picture: an immutable two-dimensional image.

You don’t instantiate Pic directly; instead, you create Pics with the methods on the Pic companion object. For instance, you can:

  • load existing images: Pic("mypic.png") or Pic("http://address.of/mypic.png")),
  • create Pics of shapes (e.g., circle(150, Red) or star(100, Black)); or
  • generate the pixels of a Pic with a function.

Moreover, many of the methods of a Pic object create and return new Pics that represent combinations or transformations of existing Pics.

This class has an alias in the top-level package o1, so it’s accessible to students simply via import o1._.

The examples below illustrate a few of the methods (assuming the above import):

val background = rectangle(400, 300, Red)
val rotatedSquare = square(50, Blue).clockwise(30)
val squareAgainstBg = background.place(rotatedSquare, Pos(100, 100))
squareAgainstBg.show()

val ladybug = Pic("ladybug.png").scaleTo(100).flipHorizontal
val combination = circle(100, Red).leftOf(ladybug)
val part = combination.crop(Pos(10, 10), 180, 80)
val negative = part.transformColors( _.negative )
negative.show()

Some of the methods of a Pic that use Pos objects or plain x and y coordinates to indicate positions within the Pic (e.g., place and crop above). All these methods consider the origo to be at the top left-hand corner or the Pic, with x values increasing downwards and y values rightwards. The coordinates are in pixels.

Each image has an anchor that defines where it connects to other Pics. By default, the anchor is Center; for example, the place method call above puts the center of the square at Pos(100, 100) within the background.

Here is a of the main types of operations as methods on a Pic, and examples of each type:

  • Combining Pics by positioning them relative to each other: above, below, leftOf, rightOf, onto, against, place.
  • Rotations (*): clockwise, counterclockwise
  • Changing size (*): scaleBy, scaleTo
  • Selecting and moving pixels (**): crop, shift, flipHOrizontal, flipVertical
  • Examining and manipulating individual pixels (**): pixelColor, transformXY, transformColors, combine
  • Convenience methods for experimentation and debugging: show, hide.

Notes on implementation and efficiency:

Internally, a Pic stores its contents either as vector-based graphics, as a bitmap (raster), or as a combination of the two. By design, that internal representation is meant to be largely opaque to the user of the Pic class: students in O1 working on O1’s standard assignments generally shouldn’t need to know or care about it. Nevertheless, whether a particular Pic is stored in vector or bitmap form does have very substantial effect on efficiency in some contexts; Pic, like the rest of O1Library, is not designed for high-performance graphics.

Some users of this class may wish to know the following:

  • Pics start out in either vector form or bitmap form, depending on which method created them. Specifically, the shape-creating methods (like rectangle and circle). produce Pics in vector form.
  • No operation on a Pic ever changes an already rasterized bitmap into vector graphics. (An operation such as leftOf can produce an Pic that is stored as a combination of a vector graphic and a bitmap.)
  • Some operations always produce a rasterized Pic. These are marked with a double asterisk (**) in the list above. Some operations sometimes produce rasterized Pics but may retain the vector-based representation in simple cases. These are marked with a single asterisk (*).
  • You can call freeze to force rasterization.
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Pic
  2. HasAnchor
  3. HasSize
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def above(lowerPic: Pic, retainAnchor: Boolean = false): Pic

    Combines this Pic and the given one so that this Pic appears immediately above the other Pic.

    Combines this Pic and the given one so that this Pic appears immediately above the other Pic. The combined Pic will be large enough to fit both originals.

    lowerPic

    the Pic that is below this Pic in the combination

    retainAnchor

    true means that the anchor of the combination should be equally far from the top left-hand corner as this Pic’s anchor is; false (the default) means that the combination should follow the same general anchoring policy has this Pic (e.g., to anchor from its center)

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    below, leftOf, rightOf, columnOf

  5. def absoluteAnchor: Anchor

    An Anchor.Absolute that points to the same spot in the Pic that the Pic’s current anchor does.

    An Anchor.Absolute that points to the same spot in the Pic that the Pic’s current anchor does.

    Annotations
    @inline()
  6. def against(background: Pic, atIts: Anchor = Center): Pic

    Combines this Pic and the given one so that the other Pic serves as a background and this Pic appears in front of it but not beyond its borders.

    Combines this Pic and the given one so that the other Pic serves as a background and this Pic appears in front of it but not beyond its borders. The visible part of the combined Pic is the size of the background Pic. In the combination, some or even none of this Pic is visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of this Pic that don’t fit against the background are left out. (The left-out parts are still part of the Pic’s data but not visible; only the part within the framing background image will be shown when the Pic is rendered onscreen.) This version of against anchors this Pic at its default anchor to an anchor in the background.

    background

    a Pic that serves as a background for this one and determines the size of the visible part of the resulting image

    atIts

    the point within background that this Pic’s anchor is positioned at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    onto which does the same but doesn’t leave out the “hanging” parts of the foreground image

    place, which does the same but switches the order of the two Pics

  7. def against(background: Pic, my: Anchor, atIts: Anchor): Pic

    Combines this Pic and the given one so that the other Pic serves as a background and this Pic appears in front of it but not beyond its borders.

    Combines this Pic and the given one so that the other Pic serves as a background and this Pic appears in front of it but not beyond its borders. The visible part of the combined Pic is the size of the background Pic. In the combination, some or even none of this Pic is visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of this Pic that don’t fit against the background are left out. (The left-out parts are still part of the Pic’s data but not visible; only the part within the framing background image will be shown when the Pic is rendered onscreen.) This version of against uses the given Anchors instead of the default anchor of either of the original Pics.

    background

    a Pic that serves as a background for this one and determines the size of the visible part of the resulting image

    my

    the point within this Pic that will be placed at the given coordinates

    atIts

    the point within background that this Pic is positioned at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    onto which does the same but doesn’t leave out the “hanging” parts of the foreground image

    place, which does the same but switches the order of the two Pics

  8. def against(background: Pic, my: Anchor, at: world.Pos): Pic

    Combines this Pic and the given one so that the other Pic serves as a background and this Pic appears in front of it but not beyond its borders.

    Combines this Pic and the given one so that the other Pic serves as a background and this Pic appears in front of it but not beyond its borders. The visible part of the combined Pic is the size of the background Pic. In the combination, some or even none of this Pic is visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of this Pic that don’t fit against the background are left out. (The left-out parts are still part of the Pic’s data but not visible; only the part within the framing background image will be shown when the Pic is rendered onscreen.) This version of against uses the given Anchor instead of this Pics default anchor and places it at a specific Pos in the background.

    background

    a Pic that serves as a background for this one and determines the size of the visible part of the resulting image

    my

    the point within this Pic that will be placed at the given coordinates

    at

    the point within background that this Pic is positioned at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    onto which does the same but doesn’t leave out the “hanging” parts of the foreground image

    place which does the same but switches the order of the two Pics

  9. def against(background: Pic, at: world.Pos): Pic

    Combines this Pic and the given one so that the other Pic serves as a background and this Pic appears in front of it but not beyond its borders.

    Combines this Pic and the given one so that the other Pic serves as a background and this Pic appears in front of it but not beyond its borders. The visible part of the combined Pic is the size of the background Pic. In the combination, some or even none of this Pic is visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of this Pic that don’t fit against the background are left out. (The left-out parts are still part of the Pic’s data but not visible; only the part within the framing background image will be shown when the Pic is rendered onscreen.) This version of against anchors this Pic at its default anchor to a specific Pos in the background.

    background

    a Pic that serves as a background for this one and determines the size of the visible part of the resulting image

    at

    the point within background that this Pic’s anchor is positioned at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    onto, which does the same but doesn’t leave out the “hanging” parts of the foreground image

    place, which does the same but switches the order of the two Pics

  10. def alternatingColumn(another: Pic, number: Int): Pic

    Combines copies of this Pic and another Pic so that they alternate in a vertical column (starting with this Pic).

    Combines copies of this Pic and another Pic so that they alternate in a vertical column (starting with this Pic). The combined Pic will be large enough to fit all the copies.

    number

    the total number of Pic\s in the column (e.g., 6 means the result has three copies of each Pic)

    Annotations
    @inline()
    See also

    above, below, columnOf, alternatingRow

  11. def alternatingRow(another: Pic, number: Int): Pic

    Combines copies of this Pic and another Pic so that they alternate in a horizontal row (starting with this Pic).

    Combines copies of this Pic and another Pic so that they alternate in a horizontal row (starting with this Pic). The combined Pic will be large enough to fit all the copies.

    number

    the total number of Pic\s in the row (e.g., 6 means the result has three copies of each Pic)

    Annotations
    @inline()
    See also

    leftOf, rightOf, rowOf, alternatingColumn

  12. val anchor: Anchor

    the object’s anchoring point

    the object’s anchoring point

    Definition Classes
    PicHasAnchor
  13. def anchorAt(anchor: Anchor): Pic

    Anchors the Pic at the given position.

    Anchors the Pic at the given position.

    anchor

    a new anchoring position

    returns

    a new Pic that’s identical to the original but anchored at the given position

    Annotations
    @inline()
  14. def apply(pixelPos: world.Pos): Color

    Returns the color of the pixel at the given coordinates within the image.

    Returns the color of the pixel at the given coordinates within the image. (This is equivalent to calling pixelColor.)

    N.B. This is inefficient on a Pic that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing the Pic first.

    Annotations
    @inline()
  15. def apply(pixelX: Int, pixelY: Int): Color

    Returns the color of the pixel at the given coordinates within the image.

    Returns the color of the pixel at the given coordinates within the image. (This is equivalent to calling pixelColor.)

    N.B. This is inefficient on a Pic that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing the Pic first.

    Annotations
    @inline()
  16. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  17. def below(abovePic: Pic, retainAnchor: Boolean = false): Pic

    Combines this Pic and the given one so that this Pic appears immediately below the other Pic.

    Combines this Pic and the given one so that this Pic appears immediately below the other Pic. The combined Pic will be large enough to fit both originals.

    abovePic

    the Pic that is above this Pic in the combination

    retainAnchor

    true means that the anchor of the combination should be equally far from the top left-hand corner as this Pic’s anchor is; false (the default) means that the combination should follow the same general anchoring policy has this Pic (e.g., to anchor from its center)

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    above, leftOf, rightOf, columnOf

  18. def centerFromTopLeft: world.Pos

    the location of this object’s center: the average point between its edges, expressed in coordinates relative to the object’s top left-hand corner

    the location of this object’s center: the average point between its edges, expressed in coordinates relative to the object’s top left-hand corner

    Definition Classes
    HasSize
  19. def clockwise(degrees: Double = 90.0): Pic

    Creates version of this Pic that’s rotated clockwise around its center.

    Creates version of this Pic that’s rotated clockwise around its center. The resulting image is sized so that the entire contents of the original Pic are visible; any empty space in the corners is Transparent.

    degrees

    the amount of clockwise rotation, in degrees

    returns

    a new Pic that is a rotated version of this one; it will usually be a bitmap, but some simple vector-based Pics may retain their vector form

    Annotations
    @inline()
  20. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  21. def columnOf(number: Int): Pic

    Combines copies of this Pic so that they appear in a vertical column.

    Combines copies of this Pic so that they appear in a vertical column. The combined Pic will be large enough to fit all the copies.

    number

    the number of copies in the column (e.g., 3 means the result has three identical images)

    Annotations
    @inline()
    See also

    above, below, rowOf, alternatingColumn

  22. def combine(another: Pic, determinePixel: (Color, Color) => Color): Pic

    Creates a new Pic by combining this Pic with the given one on a pixel-by-pixel basis.

    Creates a new Pic by combining this Pic with the given one on a pixel-by-pixel basis. For each pair of pixel coordinates in the two original Pics, combine calls the given function to compute the color of the corresponding pixel in the new Pic. The new Pic’s width equals the lesser of the two originals’ widths; the same goes for height.

    determinePixel

    a function generates a pixel for the combination, given two pixel colors from the same location in the originals

    returns

    the new (bitmap) image obtained by calling determinePixel and putting together the outputs

    Annotations
    @inline()
  23. def contains(pixel: world.Pos): Boolean

    Determines if the given Pos is within this Pic’s borders.

    Determines if the given Pos is within this Pic’s borders. For that to be the case, the Pos object’s x needs to be between zero (inclusive) and this Pic’s width (exclusive) and its y needs to be betewen zero (inclusive) and this Pic’s height (exclusive).

  24. def counterclockwise(degrees: Double = 90.0): Pic

    Creates version of this Pic that’s rotated counterclockwise around its center.

    Creates version of this Pic that’s rotated counterclockwise around its center. The resulting image is sized so that the entire contents of the original Pic are visible; any empty space in the corners is Transparent.

    degrees

    the amount of counterclockwise rotation, in degrees

    returns

    a new Pic that is a rotated version of this one; it will usually be a bitmap, but some simple vector-based Pics may retain their vector form

    Annotations
    @inline()
  25. def crop(x: Double, y: Double, width: Double, height: Double): Pic

    Returns a partial Pic of a rectangular area within this Pic.

    Returns a partial Pic of a rectangular area within this Pic.

    x

    the x coordinate of left edge of the cropping frame within this Pic

    y

    the y coordinate of top edge of the cropping frame within this Pic

    width

    the width of the cropping frame

    height

    the height of the cropping frame

    returns

    a new Pic (a bitmap) that contains a part of the original

    Annotations
    @inline()
  26. def crop(topLeft: world.Pos, width: Double, height: Double): Pic

    Returns a partial Pic of a rectangular area within this Pic.

    Returns a partial Pic of a rectangular area within this Pic.

    topLeft

    the top-left corner of the cropping frame within this Pic

    width

    the width of the cropping frame

    height

    the height of the cropping frame

    returns

    a new Pic (a bitmap) that contains a part of the original

    Annotations
    @inline()
  27. def crop(topLeft: world.Pos, bottomRight: world.Pos): Pic

    Returns a partial Pic of a rectangular area within this Pic.

    Returns a partial Pic of a rectangular area within this Pic.

    topLeft

    the top-left corner of the cropping frame within this Pic

    bottomRight

    the bottom-right corner of the cropping frame within this Pic

    returns

    a new Pic (a bitmap) that contains a part of the original

    Annotations
    @inline()
  28. def crop(boundary: world.Bounds): Pic

    Returns a partial Pic of a rectangular area within this Pic.

    Returns a partial Pic of a rectangular area within this Pic.

    boundary

    the cropping frame within this Pic

    returns

    a new Pic (a bitmap) that contains a part of the original

    Annotations
    @inline()
  29. lazy val dimensions: (Double, Double)

    The width and height of the Pic as a tuple.

  30. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  31. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  32. def flipDiagonal: Pic

    Creates mirrored version of this Pic: what’s in each corner of the original is in the opposite corner of the resulting Pic.

    Creates mirrored version of this Pic: what’s in each corner of the original is in the opposite corner of the resulting Pic.

    returns

    a new Pic (a bitmap) that is a flipped version of this one

    Annotations
    @inline()
  33. def flipHorizontal: Pic

    Creates mirrored version of this Pic: what’s on the left in the original is on the right in the resulting Pic and vice versa.

    Creates mirrored version of this Pic: what’s on the left in the original is on the right in the resulting Pic and vice versa.

    returns

    a new Pic (a bitmap) that is a flipped version of this one

    Annotations
    @inline()
  34. def flipVertical: Pic

    Creates mirrored version of this Pic: what’s at the top in the original is at the bottom in the resulting Pic and vice versa.

    Creates mirrored version of this Pic: what’s at the top in the original is at the bottom in the resulting Pic and vice versa.

    returns

    a new Pic (a bitmap) that is a flipped version of this one

    Annotations
    @inline()
  35. def freeze: Pic

    Forces rasterization of any vector graphics in this Pics internal representation into bitmap form.

    Forces rasterization of any vector graphics in this Pics internal representation into bitmap form. See the introduction to this class for more information.

    returns

    the same picture, stored entirely in bitmap form

    Annotations
    @inline()
    See also

    isBitmap

  36. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  37. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  38. lazy val height: Double

    The height of the Pic in pixels.

    The height of the Pic in pixels.

    Definition Classes
    PicHasSize
  39. def hide(): Unit

    Hides the window that has been created (with show) to display the Pic.

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

    Students may alternatively use the hide(pic) variant in the top-level package o1.

    Annotations
    @inline()
    See also

    show, Pic.hide

  40. lazy val history: List[String]

    A list of method names used for creating this Pic.

    A list of method names used for creating this Pic. Only the most recently applied methods are listed (up to historyLength. This method may be useful for demonstrative purposes, debugging, and/or automatic assessment.

  41. val historyLength: Int

    A limit on the number of historical method calls that are tracked by the Pic and available through history.

    A limit on the number of historical method calls that are tracked by the Pic and available through history. Defaults to 10. Can be changed via withHistoryLength.

  42. def internalAnchorPos: world.Pos

    Returns the Pos of the anchoring point within this object, expressed as coordinates relative to the object’s top left-hand corner.

    Returns the Pos of the anchoring point within this object, expressed as coordinates relative to the object’s top left-hand corner.

    Definition Classes
    HasAnchor
  43. def internalAnchorX: Double

    Returns the x coordinate of the anchoring point within this object, relative to the object’s left edge.

    Returns the x coordinate of the anchoring point within this object, relative to the object’s left edge.

    Definition Classes
    HasAnchor
  44. def internalAnchorY: Double

    Returns the y coordinate of the anchoring point within this object, relative to the object’s top edge.

    Returns the y coordinate of the anchoring point within this object, relative to the object’s top edge.

    Definition Classes
    HasAnchor
  45. def isBitmap: Boolean

    Indicates whether this Pic is internally stored as a bitmap raster.

    Indicates whether this Pic is internally stored as a bitmap raster. See the introduction to this class for more information.

    returns

    true if the entire Pic is rasterized as a bitmap; false if the Pic’s internal representation uses any vector graphics

    Annotations
    @inline()
    See also

    freeze

  46. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  47. def leftOf(rightPic: Pic, retainAnchor: Boolean = false): Pic

    Combines this Pic and the given one so that this Pic appears immediately to the left the other Pic.

    Combines this Pic and the given one so that this Pic appears immediately to the left the other Pic. The combined Pic will be large enough to fit both originals.

    rightPic

    the Pic that is to the right of this Pic in the combination

    retainAnchor

    true means that the anchor of the combination should be equally far from the top left-hand corner as this Pic’s anchor is; false (the default) means that the combination should follow the same general anchoring policy has this Pic (e.g., to anchor from its center)

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    above, below, rightOf, rowOf

  48. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  49. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  50. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  51. def onto(backPic: Pic, my: Anchor, at: world.Pos): Pic

    Combines this Pic and the given one so that this Pic appears in front of the other Pic at specific coordinates.

    Combines this Pic and the given one so that this Pic appears in front of the other Pic at specific coordinates. The combined Pic will be larger than either of the two originals unless this Pic fits completely in front of the other one. This version of onto uses the given Anchor instead of this Pics default anchor.

    backPic

    the Pic that is behind this one in the combination

    my

    the point within this Pic that will be placed at the given coordinates

    at

    the point within backPic that this Pic is positioned at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    against, which does the same but leaves out any “hanging” parts of the foreground image

  52. def onto(backPic: Pic, at: world.Pos): Pic

    Combines this Pic and the given one so that this Pic appears in front of the other Pic at specific coordinates.

    Combines this Pic and the given one so that this Pic appears in front of the other Pic at specific coordinates. The combined Pic will be larger than either of the two originals unless this Pic fits completely in front of the other one. This version of onto anchors this Pic at its default anchor.

    backPic

    the Pic that is behind this one in the combination

    at

    the point within backPic that this Pic’s anchor is positioned at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    against, which does the same but leaves out any “hanging” parts of the foreground image

  53. def onto(backPic: Pic, atIts: Anchor = Center): Pic

    Combines this Pic and the given one so that this Pic appears in front of the other Pic.

    Combines this Pic and the given one so that this Pic appears in front of the other Pic. The combined Pic will be larger than either of the two originals unless this Pic fits completely in front of the other one. This version of onto anchors this Pic from its default anchor to an anchor in the other image.

    backPic

    the Pic that is behind this one in the combination

    atIts

    the point within backPic that this Pic’s anchor is positioned at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    against, which does the same but leaves out any “hanging” parts of the foreground image

  54. def onto(backPic: Pic, my: Anchor, atIts: Anchor): Pic

    Combines this Pic and the given one so that this Pic appears in front of the other Pic.

    Combines this Pic and the given one so that this Pic appears in front of the other Pic. The combined Pic will be larger than either of the two originals unless this Pic fits completely in front of the other one. This version of onto uses the given Anchors instead of the default anchor of either of the original Pics.

    backPic

    the Pic that is behind this one in the combination

    my

    the point within this Pic that will be placed at atIts

    atIts

    the point within backPic that this Pic is positioned at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    against, which does the same but leaves out any “hanging” parts of the foreground image

  55. def pixelColor(x: Double, y: Double): Color

    Returns the color of the pixel at the given coordinates within the image.

    Returns the color of the pixel at the given coordinates within the image.

    N.B. This is inefficient on a Pic that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing the Pic first.

    Annotations
    @inline()
  56. def pixelColor(x: Int, y: Int): Color

    Returns the color of the pixel at the given position within the image.

    Returns the color of the pixel at the given position within the image.

    N.B. This is inefficient on a Pic that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing the Pic first.

    Annotations
    @inline()
  57. def pixelColor(pos: world.Pos): Color

    Returns the color of the pixel at the given position within the image.

    Returns the color of the pixel at the given position within the image.

    N.B. This is inefficient on a Pic that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing the Pic first.

    Annotations
    @inline()
  58. def pixelsNear(pos: world.Pos, range: Double): Seq[Color]

    Returns the colors of the pixels in this Pic that are “near” a given Pos.

    Returns the colors of the pixels in this Pic that are “near” a given Pos. A pixel counts as being near if it’s located at a Pos whose distance from the given Pos is less than or equal to the given range. This includes the pixel at the given Pos (if there is one).

    pos

    a position whose nearby pixels in this Pic will be returned

    range

    the maximum distance of a returned pixel from pos (must be non-negative)

    returns

    a collection of the pixel colors, in arbitrary order

  59. def place(foregroundPics: (Pic, world.Pos)*): Pic

    Combines this Pic and the given ones so that this Pic serves as a background and the other Pics appear in front but not beyond this Pic’s borders.

    Combines this Pic and the given ones so that this Pic serves as a background and the other Pics appear in front but not beyond this Pic’s borders. The visible part of the combined Pic is the size of this background Pic. This is equivalent to calling place(Pic,Pos) repeatedly.

    foregroundPics

    tuples containing: the Pics that will be placed against this background and the points within this Pic where their default anchors will be placed

    returns

    the combined Pic

    Annotations
    @inline()
  60. def place(foregroundPics: Iterable[(Pic, world.Pos)]): Pic

    Combines this Pic and the given ones so that this Pic serves as a background and the other Pics appear in front but not beyond this Pic’s borders.

    Combines this Pic and the given ones so that this Pic serves as a background and the other Pics appear in front but not beyond this Pic’s borders. The visible part of the combined Pic is the size of this background Pic. This is equivalent to calling place(Pic,Pos) repeatedly.

    foregroundPics

    tuples containing: the Pics that will be placed against this background and the points within this Pic where their default anchors will be placed

    returns

    the combined Pic

    Annotations
    @inline()
  61. def place(foregroundPicAndPos: (Pic, world.Pos)): Pic

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders.

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders. The visible part of the combined Pic is the size of this background Pic. Some or even none of the other Pic is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the other Pic that don’t fit against this background are left out. (The left-out parts are still part of this Pic’s data but not visible; only the part within this framing background image will be shown when the Pic is rendered onscreen.) This version of place anchors the other Pic at its default anchor to a specific Pos in this background.

    foregroundPicAndPos

    a tuple containing: the Pic that will be placed against this background and the point within this Pic that foreground’s anchor will be placed at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    place, which does the same but without the tuple

  62. def place(foreground: Pic, atMy: Anchor): Pic

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders.

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders. The visible part of the combined Pic is the size of this background Pic. Some or even none of the other Pic is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the other Pic that don’t fit against this background are left out. (The left-out parts are still part of this Pic’s data but not visible; only the part within this framing background image will be shown when the Pic is rendered onscreen.) This version of place anchors the other Pic at its default anchor to a specified anchor in this background.

    foreground

    the Pic that will be placed against this background

    atMy

    the point within this Pic that foreground’s anchor will be placed at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    place, which does the same but switches the order of the two Pics

  63. def place(foreground: Pic, at: world.Pos): Pic

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders.

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders. The visible part of the combined Pic is the size of this background Pic. Some or even none of the other Pic is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the other Pic that don’t fit against this background are left out. (The left-out parts are still part of this Pic’s data but not visible; only the part within this framing background image will be shown when the Pic is rendered onscreen.) This version of place anchors the other Pic at its default anchor to a specific Pos in this background.

    foreground

    the Pic that will be placed against this background

    at

    the point within this Pic that foreground’s anchor will be placed at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    place, which does the same but switches the order of the two Pics

  64. def place(foreground: Pic, its: Anchor, atMy: Anchor): Pic

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders.

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders. The visible part of the combined Pic is the size of this background Pic. Some or even none of the other Pic is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the other Pic that don’t fit against this background are left out. (The left-out parts are still part of this Pic’s data but not visible; only the part within this framing background image will be shown when the Pic is rendered onscreen.) This version of place uses the given Anchors instead of the default anchor of either of the original Pics.

    foreground

    the Pic that will be placed against this background

    its

    the point within foreground that will be placed at the given coordinates

    atMy

    the point within this Pic that foreground will be placed at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    place, which does the same but switches the order of the two Pics

  65. def place(foreground: Pic, its: Anchor, at: world.Pos): Pic

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders.

    Combines this Pic and the given one so that this Pic serves as a background and the other Pic appears in front but not beyond this Pic’s borders. The visible part of the combined Pic is the size of this background Pic. Some or even none of the other Pic is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the other Pic that don’t fit against this background are left out. (The left-out parts are still part of this Pic’s data but not visible; only the part within this framing background image will be shown when the Pic is rendered onscreen.) This version of place uses the given Anchor instead of the other Pics default anchor and places it at a specific Pos in this background.

    foreground

    the Pic that will be placed against this background

    its

    the point within foreground that will be placed at the given coordinates

    at

    the point within this Pic that foreground will be placed at

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    place which does the same but switches the order of the two Pics

  66. def placeCopies(foregroundPic: Pic, at: Iterable[world.Pos]): Pic

    Combines this Pic and copies of the given one so that this Pic serves as a background and the copies of the other Pics appear in front but not beyond this Pic’s borders.

    Combines this Pic and copies of the given one so that this Pic serves as a background and the copies of the other Pics appear in front but not beyond this Pic’s borders. The visible part of the combined Pic is the size of this background Pic. This is equivalent calling place(Pic,Pos) repeatedly, passing in the same foreground image each time.

    foregroundPic

    the Pics whose copies will be placed against this background

    at

    the points within this Pic where the default anchors of the copies should be placed

    returns

    the combined Pic

    Annotations
    @inline()
  67. def rightOf(leftPic: Pic, retainAnchor: Boolean = false): Pic

    Combines this Pic and the given one so that this Pic appears immediately to the right the other Pic.

    Combines this Pic and the given one so that this Pic appears immediately to the right the other Pic. The combined Pic will be large enough to fit both originals.

    leftPic

    the Pic that is to the left of this Pic in the combination

    retainAnchor

    true means that the anchor of the combination should be equally far from the top left-hand corner as this Pic’s anchor is; false (the default) means that the combination should follow the same general anchoring policy has this Pic (e.g., to anchor from its center)

    returns

    the combined Pic

    Annotations
    @inline()
    See also

    above, below, leftOf, rowOf

  68. def rowOf(number: Int): Pic

    Combines copies of this Pic so that they appear in a horizontal row.

    Combines copies of this Pic so that they appear in a horizontal row. The combined Pic will be large enough to fit all the copies.

    number

    the number of copies in the row (e.g., 3 means the result has three identical images)

    Annotations
    @inline()
    See also

    leftOf, rightOf, columnOf, alternatingRow

  69. def save(path: String): Boolean

    Saves the Pic in the given file in PNG format.

    Saves the Pic in the given file in PNG format.

    path

    an absolute local path or a path relative to the working directory

    returns

    true if the saving was successful and false if no file was created because there was no bitmap to save

    Annotations
    @inline()
  70. def scaleBy(factor: Double): Pic

    Creates a version of this Pic that is larger or smaller as per the given multiplier.

    Creates a version of this Pic that is larger or smaller as per the given multiplier. A value between 0 and 1 produces a smaller Pic, a value above 1 a larger one. Retains the aspect ratio of the original image.

    factor

    the ratio between the sizes of the result and the original

    returns

    a new Pic that is a scaled version of this one; it will usually be a bitmap, but some simple vector-based Pics may retain their vector form

    Annotations
    @inline()
  71. def scaleTo(sizingPic: Pic): Pic

    Creates a scaled version of this Pic that has the dimensions of the given Pic.

    Creates a scaled version of this Pic that has the dimensions of the given Pic. The aspect ratio of the resulting image may be different from the original’s.

    sizingPic

    a Pic whose width and height are given to the scaled Pic

    returns

    a new Pic that is a scaled version of this one; it will usually be a bitmap, but some simple vector-based Pics may retain their vector form

    Annotations
    @inline()
  72. def scaleTo(targetSize: Double): Pic

    Creates a scaled version of this Pic that has the given size and is rectangular.

    Creates a scaled version of this Pic that has the given size and is rectangular. If the original Pic isn’t rectangular, the aspect ratio of the result will be different.

    targetSize

    the width and height of the output image

    returns

    a new Pic that is a scaled version of this one; it will usually be a bitmap, but some simple vector-based Pics may retain their vector form

    Annotations
    @inline()
  73. def scaleTo(targetWidth: Double, targetHeight: Double): Pic

    Creates a scaled version of this Pic that has the given dimensions.

    Creates a scaled version of this Pic that has the given dimensions. The aspect ratio of the resulting image may be different from the original’s.

    targetWidth

    the width of the output image

    targetHeight

    the height of the output image

    returns

    a new Pic that is a scaled version of this one; it will usually be a bitmap, but some simple vector-based Pics may retain their vector form

    Annotations
    @inline()
  74. def shiftDown(offset: Double): Pic

    Shifts each pixel within the Pic downwards by the given amount.

    Shifts each pixel within the Pic downwards by the given amount. Retains the size of the image: any pixels that would go beyond the bottom edge of the Pic instead wrap around to the top.

    offset

    the number of pixels the image shifts down

    returns

    a new Pic (a bitmap) that contains a shifted version of the original

    Annotations
    @inline()
  75. def shiftLeft(offset: Double): Pic

    Shifts each pixel within the Pic to the left by the given amount.

    Shifts each pixel within the Pic to the left by the given amount. Retains the size of the image: any pixels that would go beyond the left edge of the Pic instead wrap around to the right-hand side.

    offset

    the number of pixels the image shifts to the left

    returns

    a new Pic (a bitmap) that contains a shifted version of the original

    Annotations
    @inline()
  76. def shiftRight(offset: Double): Pic

    Shifts each pixel within the Pic to the right by the given amount.

    Shifts each pixel within the Pic to the right by the given amount. Retains the size of the image: any pixels that would go beyond the right edge of the Pic instead wrap around to the left-hand side.

    offset

    the number of pixels the image shifts to the right

    returns

    a new Pic (a bitmap) that contains a shifted version of the original

    Annotations
    @inline()
  77. def shiftUp(offset: Double): Pic

    Shifts each pixel within the Pic upwards by the given amount.

    Shifts each pixel within the Pic upwards by the given amount. Retains the size of the image: any pixels that would go beyond the top edge of the Pic instead wrap around to the bottom.

    offset

    the number of pixels the image shifts up

    returns

    a new Pic (a bitmap) that contains a shifted version of the original

    Annotations
    @inline()
  78. def show(background: Color = colors.White, border: Int = 1): Unit

    Displays this Pic in a minimalistic GUI window.

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

    Students may alternatively use the show(pic) variant in the top-level package o1.

    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

    Annotations
    @inline()
    See also

    hide

    Pic.show

  79. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  80. lazy val toIcon: Option[Icon]

    This Pic converted to a Swing Icon).

  81. lazy val toImage: Option[BufferedImage]

    This Pic converted to a Java AWT BufferedImage (for use in Swing GUIs).

  82. def toString: String

    Returns a very simple string description of this Pic.

    Returns a very simple string description of this Pic. Examples:

    • "ladybug.png"
    • circle-shape
    • "ladybug.png" (transformed)
    • circle-shape (transformed)
    • combined pic
    Definition Classes
    Pic → AnyRef → Any
    Annotations
    @inline()
  83. def transformColors(transformer: (Color) => Color): Pic

    Applies the given operation to each pixel in the Pic to generate a different Pic.

    Applies the given operation to each pixel in the Pic to generate a different Pic. That is, every color in the image will be replaced by another color in the generated image, as specified by the given function.

    transformer

    a function that transformColors calls on every pixel in the image to map its color to a new one

    returns

    the new (bitmap) image obtained by calling transformer and putting together the outputs

    Annotations
    @inline()
  84. def transformXY(newColorAt: (Int, Int) => Color): Pic

    Applies the given operation to each position in the Pic to generate a different Pic.

    Applies the given operation to each position in the Pic to generate a different Pic.

    newColorAt

    a function that transformXY calls repeatedly to determine the pixels of the transformed Pic

    returns

    the new (bitmap) image obtained by calling newColorAt and putting together the outputs

    Annotations
    @inline()
  85. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  86. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  87. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  88. lazy val width: Double

    The width of the Pic in pixels.

    The width of the Pic in pixels.

    Definition Classes
    PicHasSize
  89. def withHistoryLength(maxLength: Int): Pic

    Sets a new limit to the history length on the Pic.

    Sets a new limit to the history length on the Pic.

    maxLength

    a new historyLength (>= 0)

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from world.objects.HasSize

Inherited from AnyRef

Inherited from Any

Ungrouped