Assignment 4: Functional Images Implementation

Description

By the time you have completed this work, you should be able to:

  • Write key components of a functional, heavily generic Scala libarary
  • Utilize types (both generic and non-generic) to help guide program implementation

In this assignment, you will implement key components of a library that manipulates images. Further details about the concepts used in the library are available here.

Download the template code below. There is only one file you need to modify in the template code: fi.scala. In fi.scala, you will need to implement a number of methods (defined with def) and functions (which are bound to val definitions). These have been marked in the code with the following comment:

// !!FILL ME IN

Unlike with previous assignments, the template file does not contain signatures for the components you need to implement. Merely writing the signatures is considered part of this assignment. We recommend implementing these signatures first, with implementations of ???. This way, your code will be compiling relatively quickly. As a hint with implementing the signatures, the provided test suite in tests.scala calls these components, so you can see what a correct call looks like.

Some of the components require you to implement curried methods. If you are unclear on what curried methods are and how to define them, you should revisit 012_currying.scala in Assignment 1's Scala tutorial.

Once you have the signatures implemented, you should move on to giving these components implementations. Types are tremendously helpful for this purpose, as in most cases it is possible to derive correct implementations even without a complete understanding of the problem. We have a written up a short guide on how to best use types for this purpose, which is available here.

Running, Compiling, and Testing

Your code can be compiled like so:

scalac -cp swing.jar *.scala

A small test suite has also been provided; this can be run like so (once your code is compiled):

scala -cp swing.jar:. Tester

The code you are writing ultimately is used to produce images. These images can be created in batch with the following command:

scala -cp swing.jar:. SaveAll

Once the images can be created, they can be compared to provided reference images like so:

./compare.sh

The above command will produce no output if all the images match up.

Grading

A breakdown of the grade follows (out of 100 points):

  • Correct lift0
  • Correct lift1
  • Correct lift2
  • Correct lift3
  • Correct lerpImgClr
  • Correct overlayImgClr
  • Correct selectImgClr
  • Correct msk2clr
  • Correct gray2clr
  • Correct translatePt
  • Correct scalePt
  • Correct rotatePt
  • Correct swirlPt
  • Correct polarXf
  • Correct translate
  • Correct scale
  • Correct rotate
  • Correct swirl
  • Correct fullM
  • Correct emptyM
  • Correct notM
  • Correct intersectM
  • Correct unionM
  • Correct xorM
  • Correct diffM

Downloads

Assignment 4 (zip)

Deliverables

You must use turnin to turn in all of your code. The command below will work for this purpose:

turnin assign4@cs162 fi.scala

Note

As a reminder: with fi.scala, you may not use any mutable state. This is to encourage you to think in a functional way, rather than to write Java/Python with a new syntax.