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

final case class Velocity(direction: Direction, speed: Double) extends Product with Serializable

Each instance of this class represents movement in the context of a two-dimensional plane. A velocity is a combination of a Direction of movement with a speed (a non-negative Double).

Another way to think about a Velocity is to divide it in two components: dx and dy. dx indicates the amount (and direction) of movement along the x axis; dy is the same for the y axis. The x coordinate increases rightwards and y downwards. For instance, a velocity with a dx of 10 and a dy of zero indicates rightward movement, and a velocity with a dx of -100 and a dy of -100 indicates faster movement leftwards and upwards.

There are many ways to create a Velocity using the methods on the companion object. Among other things, you can:

  • construct a velocity from a direction and a (positive or zero) speed, as in Velocity(Direction.Left, 50);
  • construct a direction from dx and dy, as in Velocity(-100, 50); or
  • determine the velocity needed to go from one Pos to another in a single unit of time, as in Velocity.between(pos1, pos2).

Many of the methods on Velocity objects also create and return new velocities.

Velocity objects are immutable.

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

direction

the direction of movement

speed

the speed of movement; this cannot be negative

Linear Supertypes
Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Velocity
  2. Serializable
  3. Product
  4. Equals
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Velocity(direction: Direction, speed: Double)

    direction

    the direction of movement

    speed

    the speed of movement; this cannot be negative

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def *(multiplier: Double): Velocity

    Returns a velocity whose speed equals this velocity’s speed multiplied by the given number (which must be positive or zero).

    Returns a velocity whose speed equals this velocity’s speed multiplied by the given number (which must be positive or zero). The direction is the same.

  4. def +(another: Velocity): Velocity

    Sums this velocity with the given one.

    Sums this velocity with the given one. The sum’s dx equals the sum of the two dxs; the same goes for dy.

  5. def -(another: Velocity): Velocity

    Subtracts the given velocity from this one.

    Subtracts the given velocity from this one. The results’s dx equals the difference between the two dxs; the same goes for dy.

  6. def /(divisor: Double): Velocity

    Returns a velocity whose speed equals this velocity’s speed divided by the given number (which must be positive).

    Returns a velocity whose speed equals this velocity’s speed divided by the given number (which must be positive). The direction is the same.

  7. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def changeDirection(newDirection: Direction): Velocity

    Returns a velocity that has the given direction and the same speed as this one.

  10. def changeSpeed(newSpeed: Double): Velocity

    Returns a velocity that has the given speed and the same direction as this one.

  11. def clockwise(degrees: Double): Velocity

    Returns a velocity whose direction is the given number of degrees clockwise from this one’s.

    Returns a velocity whose direction is the given number of degrees clockwise from this one’s. The speed is the same.

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

    Returns a velocity whose direction is the given number of degrees counterclockwise from this one’s.

    Returns a velocity whose direction is the given number of degrees counterclockwise from this one’s. The speed is the same.

  14. val direction: Direction
  15. lazy val dx: Double

    the amount of change in the x coordinate when moving at this velocity for one unit of time

  16. lazy val dy: Double

    the amount of change in the y coordinate when moving at this velocity for one unit of time

  17. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. def faster(addition: Double): Velocity

    Returns a velocity whose speed equals this velocity’s speed plus the given number.

    Returns a velocity whose speed equals this velocity’s speed plus the given number. The direction is the same.

  19. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  20. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  21. def isStill: Boolean

    Determines whether the speed of this Velocity is precisely zero.

  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. def nextFrom(position: Pos): Pos

    Returns the Pos that an object moving at this velocity reaches in one unit of time.

    Returns the Pos that an object moving at this velocity reaches in one unit of time. That is, adds the dx and dy components of this velocity to the given Pos and returns the result.

  24. def noFasterThan(maxSpeed: Double): Velocity

    Returns a velocity whose speed is as close to this one’s as possible without exceeding the given number.

    Returns a velocity whose speed is as close to this one’s as possible without exceeding the given number. The direction is the same.

  25. def noSlowerThan(minSpeed: Double): Velocity

    Returns a velocity whose speed is as close to this one’s as possible without being lower than the given number.

    Returns a velocity whose speed is as close to this one’s as possible without being lower than the given number. The direction is the same.

  26. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  27. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  28. def opposite: Velocity

    Returns a velocity that is equal to this one in speed but has the opposite direction.

    Returns a velocity that is equal to this one in speed but has the opposite direction. The expressions myVelocity.opposite and -myVelocity are equivalent.

  29. def productElementNames: Iterator[String]
    Definition Classes
    Product
  30. def roughly: String

    Returns a String description of the Velocity.

    Returns a String description of the Velocity. E.g., "111.80 with direction dx=0.89,dy=-0.45". Uses two decimals for each number.

  31. def slower(reduction: Double): Velocity

    Returns a velocity whose speed equals this velocity’s speed minus the given number.

    Returns a velocity whose speed equals this velocity’s speed minus the given number. The direction is the same.

  32. val speed: Double
  33. def stopped: Velocity

    Returns a velocity whose direction equals this one’s but whose speed is zero.

  34. def switchX: Velocity

    Returns a velocity whose dx is the opposite of this one’s.

    Returns a velocity whose dx is the opposite of this one’s. The dy is the same, as is the speed.

  35. def switchY: Velocity

    Returns a velocity whose dy is the opposite of this one’s.

    Returns a velocity whose dy is the opposite of this one’s. The dx is the same, as is the speed.

  36. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  37. def toPos: Pos

    Returns a Pos whose x and y components equal this velocity’s dx and dy, respectively.

  38. def toString: String

    Returns a String description of the Velocity.

    Returns a String description of the Velocity. The format varies depending on the velocity’s direction.

    Definition Classes
    Velocity → AnyRef → Any
    See also

    roughly

  39. def unary_-: Velocity

    Returns a velocity that is equal to this one in speed but has the opposite direction.

    Returns a velocity that is equal to this one in speed but has the opposite direction. The expressions -myVelocity and myVelocity.opposite are equivalent.

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