CS 70

Define the Asciimation Class

In this step, we will fill in the definition for an Asciimation class. The class will contain a single Sprite object that it will draw to the screen. It will also keep track of where that sprite is on the screen.

What's Already Done…

The class has the following private data members (already in place):

Type Name Function
int numRows_ Height (in rows of characters) of the generated animation
int numCols_ Width (in columns of characters) of the generated animation
int rowHeight_ Height (in pixels) of each row of characters in the generated animation
int colWidth_ Width (in pixels) of each column of characters in the generated animation
Sprite object sprite_ Sprite to be displayed (our one and only “actor”!)
int spriteCurrentRow_ Row where the top-left corner of the sprite should be drawn on the animation frame
int spriteCurrentCol_ Column where the top-left corner of the sprite should be drawn on the animation frame
static constexpr int COLORTYPE Tell OpenCV how we are storing images: the (OpenCV-defined) constant CV_8UC3
static constexpr int FONT Tell OpenCV which font to use: the (OpenCV-defined) constant cv::FONT_HERSHEY_PLAIN

Your Asciimation class also has a (partly written) parameterized constructor that

  • Takes in initial values for numRows_, numCols_, rowHeight_, and colWidth_, along with the name of a file with the content of a Sprite.
  • Uses that filename to initialize its Sprite data member.

The Asciimation class also has two public member functions,

  • generateMovie, which will handle the top-level process of creating an animation file; and
  • addFrame, which will add one frame of animation at a time to the animation object.

You will implement those member functions in the next part of the assignment.

Your Task…

Finish implementing the Asciimation constructor such that the Sprite begins centered vertically on the screen, and just off the left side of the screen horizontally so that initially no characters are shown. You will need to determine the corresponding row and column for this position.

Helpful Hints

  • LHS Cow speaking

    Here are some hints for the Asciimation class.

Accessing a Static Member

You can access a class’s static member variable using the class name and the scope-resolution operator; for example, ClassName::variableName.

Initializing the Sprite

Remember that the default constructor for the Sprite class is disabled! When (and how) should we initialize the Sprite data member so that not having a default constructor won’t cause us problems?

Once you’ve finished this step, you should be able to compile and link everything again—but you will still get warnings about unused variables because you haven’t implemented everything needed in the Asciimation class yet.

Use the Member-Initialization List

To receive full idioms points, your constructor must properly use the member-initialization list. You can read about this expectation in Section 4.1 of the CS 70 Idioms Page, and you can read more about member-initialization lists in the lessons and in Chapter 1.1 of the Unofficial CS70 textbook.

To Complete This Part of the Assignment

You'll know you're done with this part of the assignment when you've done all of the following:

(When logged in, completion status appears here.)