cmpsci220

graphics

package graphics

An API for drawing 2D images and animations.

Linear Supertypes
AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By inheritance
Inherited
  1. graphics
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. trait Color extends AnyRef

    The type of colors

    The type of colors

    There are a few predefined colors in the cmpsci220.graphics package. You can also use the cmpsci220.graphics.rgb function to create your own colors.

  2. trait Image extends AnyRef

    The type of images

    The type of images

    There are several functions in the cmpsci220.graphics package to create simple shapes, such as cmpsci220.graphics.rect, cmpsci220.graphics.oval, etc. You can make more complex images by manipulating and composing simpler shapes. E.g., see the functions cmpsci220.graphics.move and cmpsci220.graphics.overlay.

Value Members

  1. def angle(degrees: Double, length: Double, color: Color = black, width: Double = 1): Image

    Draws a line at an angle.

    Draws a line at an angle.

    Draws a line from (length,length) of length length. The angle between the x-axis and the line is given by degrees.

    Examples

    angle(0, 10) draws a horizontal line from (10, 10) to (20, 10) angle(90, 10) draws a vertical line from (10, 10) to (10, 20)

    degrees

    the angle of the line, specified in degrees

    length

    the length of the line

    color

    (optional) the color; black by default

    width

    (optional) the width; 1 by default

  2. def animate[T](init: T, draw: (T) ⇒ Image, width: Int = 400, height: Int = 400, tick: (T) ⇒ T = identity[T], keyPressed: (String, T) ⇒ T = ignoreKey[T], keyReleased: (String, T) ⇒ T = ignoreKey[T], refreshRate: Double = 35): T

    Starts the program

    Starts the program

    Starts the program in the init state and draws the state using the draw argument. There are many optional arguments that you can provide to customize the behavior of the program. For example, you can use the tick argument to update the state to build an animation.

    init

    the initial state of the program

    draw

    a function from states to Images, which is called on each tick

    width

    (optional) the width of the window; 400 by default

    height

    (optional) the height of the window; 400 by default

    tick

    (optional) a function to update the state; the default value is the identity function

    refreshRate

    (optional) the number of times per second that draw and tick will be applied; the default value is 35 tickes per second

    returns

    the last value of the state before the window is closed

  3. def black: Color

    The color black

  4. val blank: Image

    A blank image

    A blank image

    This image does not appear. But, it is often useful as a base-case when writing image-building functions.

  5. def blue: Color

    The color blue

  6. def fillRect(width: Double, height: Double, color: Color = black): Image

    Draws a filled rectangle

    Draws a filled rectangle

    Draws a filled rectangle with width width and height height.

    Examples:

    fillRect(100, 30, red) draws a short, red rectangle fillRect(100, 100, blue) draws a blue square

    width

    the width of the rectangle

    height

    the height of the rectangle

    color

    (optional) the color of the line; black by default

  7. def green: Color

    The color green

  8. def ignoreKey[T](key: String, state: T): T

    Ignores pressed keys

  9. def line(x: Double, y: Double, color: Color = black, width: Double = 1): Image

    Draws a line

    Draws a line

    Draws a line from (0,0) to (x,y).

    Examples:

    line(100, 0, red) draws a horizonal, red line.

    line(0, 100, blue, 10) draws a thick, vertical, blue line.

    x

    the x-coordinate of the end-point

    y

    the y-coordinate of the end-point

    color

    (optional) the color of the line; black by default

    width

    (optional) the width of the line; 1 by default

  10. def move(image: Image, x: Double, y: Double): Image

    Moves an image

    Moves an image

    Moves an image x pixels horizontally and y pixels vertically.

    Examples:

    overlay(move(rect(10, 10, blue), 5, 5), rect(20, 20, red)) draws a blue square centered inside a red square.

    image

    the image to draw

    x

    the x offset of the image

    y

    the y offset of the image

  11. def oval(width: Double, height: Double, color: Color = black): Image

    Draws an oval

    Draws an oval

    Draws an oval with width width and height height.

    Examples:

    oval(10, 100, blue) draws a tall and thin blue oval oval(100, 100, red) draws a red circle with diameter 100

    height

    the height of the oval

    color

    (optional) the color of the oval; black by default

  12. def overlay(top: Image, bot: Image): Image

    Overlays one image on top of another.

    Overlays one image on top of another.

    Draws the top image on top of bot.

    Examples:

    overlay(rect(10, 10, blue), rect(20, 20, red)) draws a blue square inside a red square.

    top

    the image to draw on top

    bot

    the image to draw on the bottom

  13. def rect(width: Double, height: Double, color: Color = black): Image

    Draws a rectangle

    Draws a rectangle

    Draws a rectangle with width width and height height.

    Examples:

    rect(100, 30, red) draws a short, red rectangle rect(100, 100, blue) draws a blue square

    width

    the width of the rectangle

    height

    the height of the rectangle

    color

    (optional) the color of the line; black by default

  14. def red: Color

    The color red

  15. def rgb(red: Double, green: Double, blue: Double): Color

    A color defined by its red, green, and blue values

    A color defined by its red, green, and blue values

    red

    the amount of red, in the range 0.0-1.0

    green

    the amount of green, in the range 0.0-1.0

    blue

    the amount of blue, in the range 0.0-1.0

  16. def saveImage(fileName: String, image: Image, width: Int = 400, height: Int = 400): Unit

    Save an image to a file

  17. def show(image: Image, width: Int = 400, height: Int = 400): Unit

    Shows an image

    Shows an image

    Shows an image in a window.

    image

    the image to draw

    width

    (optional) the width of the window; 400 by default

    height

    (optional) the height of the window; 400 by default

  18. def solidOval(width: Double, height: Double, color: Color = black): Image

    Draws a solid oval

    Draws a solid oval

    Draws an oval with width width and height height.

    Examples:

    solidOval(10, 100, blue) draws a tall and thin blue oval solidOval(100, 100, red) draws a red circle with diameter 100

    width

    the width of the oval

    height

    the height of the oval

    color

    (optional) the color; black by default

Inherited from AnyRef

Inherited from Any

Colors

Images

Miscellaneous

Starting the program