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 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
  • package objects

    This package contains tools for representing objects that exist in two-dimensional space.

    This package contains tools for representing objects that exist in two-dimensional space. In particular, it defines:

    • the Anchor type: an anchor is the point where an object connects to its environment; and
    • a number of traits (HasPos, HasVelocity, etc.) the classes of an application can mix in to gain access to various convenience methods.

    NOTE TO STUDENTS: In this course, you don't need to understand how this package works or can be used. That being said, some students may wish to experiment with some of its contents. Many of the traits in this package have aliases in the top-level package o1, so they are accessible to students simply via import o1._.

    Definition Classes
    world
  • Bounds
  • Direction
  • Pos
  • Velocity

sealed case class Direction extends Product with Serializable

Each instance of this class represents a direction on a two-dimensional plane. A direction consists of two components: dx and dy, each of which is a number between -1.0 and +1.0 (inclusive). dx indicates the degree to which the x coordinate changes when moving in that direction; dy is the same for the y coordinate. The x coordinate increases rightwards and y downwards.

For example, moving straight rightwards can be thought of a moving in a Direction with a dx of +1.0 and a dy of 0.0; by comparison, the upward direction would have a dx of 0.0 and a dy of -1.0. . Diagonals have non-zero values for both dx and dy.

The dx and dy of any Direction always sum up to (roughly) 1.0, with the exception of the special value NoDirection which represents the lack of a direction and as zero for both components. (In this, a Direction is different than a Velocity, which is a combination of a direction of movement and a speed.)

You don’t instantiate Direction directly; instead, you create Directions with the methods on the companion object. Among other things, you can:

  • construct a direction from two differences between coordinates, as in Direction.fromDeltas(-100, 50); or
  • create a direction that corresponds to a given angle, as in Direction.fromDegrees(60) and Direction.fromRadians(-scala.math.Pi / 4).

Some of the methods of a Direction object also create and return new Directions, as does the directionOf method on Pos objects. Moreover, the companion object of this class has a few predefined Direction constants: Up, Down, Left, Right, and NoDirection.

Direction objects are immutable.

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

Linear Supertypes
Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Direction
  2. Serializable
  3. Product
  4. Equals
  5. AnyRef
  6. 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. def +(another: Direction): Direction

    Returns a direction that is, clockwise, removed from this direction by a number of degrees specified by the given direction.

    Returns a direction that is, clockwise, removed from this direction by a number of degrees specified by the given direction. Calling dir1 + dir2 is equivalent to calling dir1.counterclockwise(dir2.toDegrees)

  4. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clockwise(degrees: Double): Direction

    Returns a direction that is removed from this direction by the given number of degrees clockwise.

    Returns a direction that is removed from this direction by the given number of degrees clockwise. For instance, clockwise(90) produces a direction at a right angle to the original.

  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  8. def counterclockwise(degrees: Double): Direction

    Returns a direction that is removed from this direction by the given number of degrees counterclockwise.

    Returns a direction that is removed from this direction by the given number of degrees counterclockwise. For instance, counterclockwise(90) produces a direction at a right angle to the original.

  9. val dx: Double
  10. val dy: Double
  11. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  13. def isDownward: Boolean

    Returns true if this direction is a clearly downward one (with a dy over zero) or at least non-upward (with a dy of exactly zero).

    Returns true if this direction is a clearly downward one (with a dy over zero) or at least non-upward (with a dy of exactly zero). Only returns false if dy is less than zero.

  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. def isLeftward: Boolean

    Returns true if this direction is a clearly leftward one (with a dx under zero) or at least non-rightward (with a dx of exactly zero).

    Returns true if this direction is a clearly leftward one (with a dx under zero) or at least non-rightward (with a dx of exactly zero). Only returns false if dx is over zero.

  16. def isRightward: Boolean

    Returns true if this direction is a clearly rightward one (with a dx over zero) or at least non-leftward (with a dx of exactly zero).

    Returns true if this direction is a clearly rightward one (with a dx over zero) or at least non-leftward (with a dx of exactly zero). Only returns false if dx is less than zero.

  17. def isUpward: Boolean

    Returns true if this direction is a clearly upward one (with a dy under zero) or at least non-downward (with a dy of exactly zero).

    Returns true if this direction is a clearly upward one (with a dy under zero) or at least non-downward (with a dy of exactly zero). Only returns false if dy is over zero.

  18. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  19. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  20. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  21. def opposite: Direction

    Returns a direction that has the opposite dx and the opposite dy as this one.

  22. def productElementNames: Iterator[String]
    Definition Classes
    Product
  23. def roughly: String

    Returns a String description of the Direction; e.g., "dx=1.00,dy=0.00".

    Returns a String description of the Direction; e.g., "dx=1.00,dy=0.00". Uses two decimals for each coordinate.

  24. def sharesQuadrant(another: Direction): Boolean

    Determines whether this direction and the given one point towards the same quarter of the unit circle.

    Determines whether this direction and the given one point towards the same quarter of the unit circle. That is, determines whether the two directions’ dx have same sign as the other and whether their dys also have the same signs. Zero values count as both positive and negative for this purpose.

  25. def switchX: Direction

    Returns a direction that has the opposite dx as this one and the same dy.

  26. def switchY: Direction

    Returns a direction that has the opposite dy as this one and the same dx.

  27. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  28. def toDegrees: Double

    Returns this direction as degrees.

    Returns this direction as degrees. (Zero degrees points rightwards, positive angles are counterclockwise from there, negative ones clockwise.)

  29. def toRadians: Double

    Returns this direction as radians.

    Returns this direction as radians. (Zero radians points rightwards, positive angles are counterclockwise from there, negative ones clockwise.)

  30. def toString: String

    Returns a String description of the Direction.

    Returns a String description of the Direction. The exact format varies for different direction objects.

    Definition Classes
    Direction → AnyRef → Any
    See also

    roughly

  31. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  32. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  33. 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 Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped