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
  • CompassDir
  • Grid
  • GridPos
c

o1.grid

Grid

abstract class Grid[Element] extends AnyRef

The class Grid represents rectangular grids that contain elements of a particular kind. Each element in a grid is located at a unique pair of coordinates, represented as a GridPos.

X coordinates run from 0 to width-1, y coordinates from 0 to height-1. (0,0) corresponds to the upper left corner of the grid.

There are different kinds of grids: the type of element that a grid contains is defined by a type parameter. For instance Grid[Square] is a grid where each pair of x and y coordinates contains a Square object, and Grid[House] is a grid containing House objects.

A Grid is mutable: it is possible to replace an element at a particular GridPos with another. (Depending on the element type, the elements may be individually mutable, too.) The width and height of a grid never change, however.

Upon creation, a Grid initializes itself by calling initialElements, which produces an initial state for the grid.

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

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

Instance Constructors

  1. new Grid(width: Int, height: Int)

    width

    the number of elements in each row of the grid

    height

    the number of elements in each column of the grid

Abstract Value Members

  1. abstract def initialElements: Seq[Element]

    Generates the elements that initially occupy the grid.

    Generates the elements that initially occupy the grid. This method is automatically invoked by every Grid object upon creation. Subclasses should implement this method as appropriate for the particular sort of grid desired.

    Note that since this method produces the initial contents of the Grid, it gets called during initialization before the Grid actually has any elements as content. Therefore, subclass implementations of this method must not depend on the state of the new Grid (by calling neighbors or elementAt, for instance) or attempt to modify the Grid (with update, for instance).

    This method is meant for initialization purposes only. To access all the elements of an already-initialized Grid, call allElements instead.

    returns

    a collection of size width times height that contains the initial grid elements. The first element in the collection will appear at GridPos (0,0), the second at (1,0), and so on, filling in the first row before continuing on the second row at (1,0).

Concrete 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 allElements: Vector[Element]

    Returns a collection of all the elements currently in the grid.

  5. def allPositions: Vector[GridPos]

    Returns a collection of all the locations on the grid.

  6. def apply(location: GridPos): Element

    Returns the element at the given pair of coordinates.

    Returns the element at the given pair of coordinates. (This does the same as elementAt.)

    location

    a location on the grid (must be within range)

  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  9. def contains(location: GridPos): Boolean

    Determines whether the grid contains the given pair of coordinates.

    Determines whether the grid contains the given pair of coordinates. For instance,a grid with a width and height of 5 will contain (0, 0) and (4, 4) but not (-1, -1), (4, 5) or (5, 4).

  10. def elementAt(location: GridPos): Element

    Returns the element at the given pair of coordinates.

    Returns the element at the given pair of coordinates. (This does the same as apply.)

    location

    a location on the grid (must be within range)

  11. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  13. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  15. val height: Int
  16. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  17. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. def neighbors(middleLoc: GridPos, includeDiagonals: Boolean): Vector[Element]

    Returns a vector of all the neighboring elements of the indicated element.

    Returns a vector of all the neighboring elements of the indicated element. Depending on the value of the second parameter, either only the four neighbors in cardinal compass directions (north, east, south, west) are considered, or the four diagonals as well.

    Note that an element that is at the edge of the grid has fewer neighbors than one in the middle. For instance, the element at (0, 0) of a 5-by-5 grid has only three neighbors, diagonals included.

    middleLoc

    the location between the neighbors

    includeDiagonals

    true if diagonal neighbors also count (resulting in up to eight neighbors), false if only cardinal directions count (resulting in up to four)

  19. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  20. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  21. val size: Int

    the number of elements in this grid, in total.

    the number of elements in this grid, in total. (Equals width times height.)

  22. def swap(location1: GridPos, location2: GridPos): Unit

    Swaps the elements at two given locations on the grid, which must be within range.

  23. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  24. def toString: String
    Definition Classes
    AnyRef → Any
  25. def update(location: GridPos, newElement: Element): Unit

    Modifies the grid by replacing the existing element at the given location with the new element.

    Modifies the grid by replacing the existing element at the given location with the new element.

    location

    a location on the grid (must be within range)

    newElement

    the new element that replaces the old one at location

  26. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  27. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  28. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  29. val width: Int

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 AnyRef

Inherited from Any

Ungrouped