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

object Pic extends ShapeAPI

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.

Linear Supertypes
ShapeAPI, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Pic
  2. ShapeAPI
  3. AnyRef
  4. 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 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.

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

    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)

    Annotations
    @inline()
  5. 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.

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

    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)

    Annotations
    @inline()
  6. def asImage(pathOrURL: String): Option[BufferedImage]

    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.

    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.

    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

  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def asOption(pathOrURL: String, anchor: Anchor = Center): 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.

    pathOrURL

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

    anchor

    an anchor for the new Pic

    returns

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

    See also

    asTry

  9. def asTry(pathOrURL: String, anchor: Anchor = Center): 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.

    pathOrURL

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

    anchor

    an anchor for the new Pic

    returns

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

    See also

    asOption

  10. def circle(diameter: Double, color: Color, anchor: Anchor = Center): Pic

    Creates a new Pic that portrays a filled circle.

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

    diameter

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

    color

    the color of the circle

    anchor

    an anchor for the new Pic

    returns

    a Pic of the circle (a vector graphic)

    Definition Classes
    ShapeAPI
  11. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  12. def ellipse(width: Double, height: Double, color: Color, anchor: Anchor = Center): Pic

    Creates a new Pic that portrays an ellipse.

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

    width

    the width of the ellipse and the Pic

    height

    the height of the ellipse and the Pic

    color

    the color of the ellipse

    anchor

    an anchor for the new Pic

    returns

    a Pic of the ellipse (a vector graphic)

    Definition Classes
    ShapeAPI
  13. def emptyCanvas(width: Double, height: Double, color: Color = colors.White): 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.

    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

    returns

    a Pic of the rectangle (a vector graphic)

    Definition Classes
    ShapeAPI
  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  16. 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.

    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)

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

    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)

  18. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  19. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  20. def hide(pic: Pic): Unit

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

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

    See also

    show, hideAll

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

    show, hide

  22. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  23. def line(from: Pos, to: Pos, color: Color): Pic

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

    from

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

    to

    the “end point” of the line

    color

    the color of the line

    returns

    a Pic of the line (a vector graphic)

    Definition Classes
    ShapeAPI
  24. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  26. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  27. def polygon(points: Seq[Pos], color: Color, anchor: Anchor = Center): Pic

    Creates a new Pic that portrays a filled polygon.

    Creates a new Pic that portrays a filled polygon. The picture is just large enough to contain the polygon; its background is fully transparent.

    points

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

    color

    the polygon’s color

    anchor

    an anchor for the new Pic

    returns

    a Pic of the rectangle (a vector graphic)

    Definition Classes
    ShapeAPI
  28. def rectangle(bounds: Bounds, color: Color): Pic

    Creates a new Pic that portrays a filled rectangle.

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

    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)

    Definition Classes
    ShapeAPI
  29. def rectangle(width: Double, height: Double, color: Color, anchor: Anchor = Center): Pic

    Creates a new Pic that portrays a filled rectangle.

    Creates a new Pic that portrays a filled rectangle.

    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

    returns

    a Pic of the rectangle (a vector graphic)

    Definition Classes
    ShapeAPI
  30. def show(pic: Pic, background: Color, border: Int): Unit

    Displays the given Pic in a minimalistic GUI window.

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

    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

    hide

    Pic.show

  31. def square(side: Double, color: Color, anchor: Anchor = Center): Pic

    Creates a new Pic that portrays a filled square.

    Creates a new Pic that portrays a filled square.

    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

    returns

    a Pic of the square (a vector graphic)

    Definition Classes
    ShapeAPI
  32. def star(width: Double, color: Color, anchor: Anchor = Center): Pic

    Creates a new Pic that portrays a five-pointed star.

    Creates a new Pic that portrays a five-pointed star. The background is fully transparent.

    width

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

    color

    the color of the star

    anchor

    an anchor for the new Pic

    returns

    a Pic of the star (a vector graphic)

    Definition Classes
    ShapeAPI
  33. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  34. def toString: String
    Definition Classes
    AnyRef → Any
  35. def triangle(width: Double, height: Double, color: Color, anchor: Anchor = Center): Pic

    Creates a new Pic that portrays an isosceles triangle.

    Creates a new Pic that portrays an isosceles triangle. The triangle’s base is at the bottom of the image and the apex is at the top center. The background is fully transparent.

    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 color of the triangle

    anchor

    an anchor for the new Pic

    returns

    a Pic of the triangle (a vector graphic)

    Definition Classes
    ShapeAPI
  36. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  37. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  38. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

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 ShapeAPI

Inherited from AnyRef

Inherited from Any

Ungrouped