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 grid

    This package contains tools for working with grid-like two-dimensional structures.

    This package contains tools for working with grid-like two-dimensional structures.

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

    Definition Classes
    o1
  • 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._.

  • 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._.

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

  • Animation
  • Color
  • DefaultFrameSettings
  • Dialog
  • Escapable
  • Pic
  • SimpleFrame
  • TerminatesOnClose
  • View
  • immutable
  • mutable
  • package sound

    Please see one of the two subpackages:

    Please see one of the two subpackages:

    • o1.sound.midi for MIDI sound described in terms of notes, instruments, and other directives
    • o1.sound.sampled for working with recorded sound samples.
    Definition Classes
    o1
  • package util

    The package o1.util contains miscellaneous tools that are used internally by some of the given programs in O1 for added convenience.

    The package o1.util contains miscellaneous tools that are used internally by some of the given programs in O1 for added convenience.

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

    This documentation lists only some of the tools in the package. The listed tools are largely a mix of:

    • functions for simple I/O from files and URLs;
    • aliases for easy access (via import o1.util._) to some of the tools from scala.util; and
    • implicit classes that add a few convenience methods to selected types from the Scala API.
    Definition Classes
    o1
  • package world

    This package contains tools for locations and movement in two-dimensional space.

    This package contains tools for locations and movement in two-dimensional space.

    The tools in this package have aliases in the top-level package o1, so they are accessible to students simply via import o1._.

    The subpackage o1.world.objects contains additional tools for representing entities that reside within two-dimensional spaces.

    Definition Classes
    o1
p

o1

gui

package gui

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.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. gui
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Package Members

  1. 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._.

  2. 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._.

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

Type Members

  1. type Anchor = world.objects.Anchor

    The Anchor type represents anchoring points of two-dimensional elements (such as Pics) within other such elements; it is an alias for the class of the same name in o1.world.objects.

  2. class Animation extends AnyRef

    An Animation object has an iterable sequence of Pics which it can show in a separate window (a simple View).

  3. type Bounds = world.Bounds

    The Bounds type represents rectangular boundaries on a two-dimensional plane; it is an alias for the class of the same name in o1.world.

  4. final class Color extends AnyRef

    Each instance of this class represents a color.

    Each instance of this class represents a color. The class uses the RGB color scheme: each color is a combination of a red, green, and blue components; there’s also a fourth component of opacity. Color objects are immutable.

    You don’t instantiate Color directly; instead, you create Colorss with the methods on the Color companion object (e.g. Color(200, 150, 255)) or use one of the named color constants in o1.gui.colors. There are also a few methods in this class that returns new Color objects defined in terms of existing ones (e.g., lighter, edit).

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

  5. trait DefaultFrameSettings extends Frame

    Give this convenience trait to a Swing GUI frame to place it at (200, 200) and set it as unresizeable.

  6. trait Escapable extends Frame

    Give this convenience trait to a Swing GUI frame to make it close when the Escape key is pressed.

  7. type HasAnchor = world.objects.HasAnchor

    A supertype for two-dimensional elements that have an anchoring point; this is an alias for the class of the same name in o1.world.objects.

  8. type Key = scala.swing.event.Key

    The Key type represents keys on the keyboard; it is an alias for the corresponding type in Scala’s Swing GUI library

  9. final class Pic extends HasAnchor

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

    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.
  10. type Pos = world.Pos

    The Pos type represents locations on a two-dimensional plane; it is an alias for the class of the same name in o1.world.

  11. class SimpleFrame extends Frame with DefaultFrameSettings

    Inherit this class to obtain a Swing GUI frame that has the DefaultFrameSettings and the given title.

  12. trait TerminatesOnClose extends Window

    Give this convenience trait to a Swing GUI frame to make it terminate the application when closed.

Value Members

  1. val Anchor: world.objects.Anchor.type

    The Anchor type represents anchoring points of two-dimensional elements (such as Pics) within other such elements; it is an alias for the class of the same name in o1.world.objects.

  2. val Bounds: world.Bounds.type

    The Bounds type represents rectangular boundaries on a two-dimensional plane; it is an alias for the class of the same name in o1.world.

  3. val Key: scala.swing.event.Key.type

    The Key type represents keys on the keyboard; it is an alias for the corresponding type in Scala’s Swing GUI library

  4. val Pos: world.Pos.type

    The Pos type represents locations on a two-dimensional plane; it is an alias for the class of the same name in o1.world.

  5. var isInTestMode: Boolean
  6. object Animation

    This companion object of class Animation provides a couple of convenience methods (show, generate) for starting animations and an enumeration (AtEnd) for use with the class.

  7. object Color

    This companion object of class Color provides methods for creating new Color objects.

    This companion object of class Color provides methods for creating new Color objects. There is also a small selection of related utility methods and constants.

    For many constants of type Color that represent different preset colors, see o1.gui.colors.

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

  8. object Dialog

    This object provides convenience methods for displaying messages and reading user input via simple Swing dialogs.

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

    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.

  10. object View
  11. object immutable

    This package contains a version of Views that is not much used in O1: views to immutable domain models.

    This package contains a version of Views that is not much used in O1: views to immutable domain models. In O1, the other implementation in o1.gui.mutable is more relevant.

  12. object mutable

    This package contains the version of Views that we primarily use in O1: views to mutable domain models.

    This package contains the version of Views that we primarily use in O1: views to mutable domain models.

    The top-level package o1 provides an alias to the ViewFrame class in this package, so it is available to students as View simply by importing o1._.

    There is an alternative implementation of Views in o1.gui.immutable.

Inherited from AnyRef

Inherited from Any

Ungrouped