AP Computer Science: Simple Graphics Lab

Students are always interested in doing something with graphics. In this lab students are challenged to make the computer draw graphics with the Doodlepad Library which is an open source Java graphics library.

Objectives

The lab is designed to help the student understand the following:

  1. How to use create and use simple objects
  2. How to read and find information in an API
  3. The coordinate system in computer graphics
  4. Reading text files
  5. How to represent data in a graphical program

How to Use Doodlepad

Doodlepad is a simple graphics library. Students need to download the jar file and import it into their projects with the IDE they are using.

If they’re using a simple editor such as Dr Java or Notepad++, then they can just copy the jar file to the same directory as their java file. Then just add the jar file to their classpath when they compile and run from the command line as shown below. Note that in Windows, the semicolon is used as the separator while Mac OSSX and Linux use a colon.

Windows Command Line

javac -cp .;doodlepad.jar MyJavaFile.java
java -cp .;doodlepad.jar MyJavaFile

Mac OSX or Linux Command Line

javac -cp .:doodlepad.jar MyJavaFile.java
java -cp .:doodlepad.jar MyJavaFile

Lab Breakdown

The lab is broken down into 3 parts with varying difficulties. Each part assumes the students can use the knowledge gained in the previous parts. You can give this lab as 3 separate labs if that suits your needs better.

Part 1: Country Flags

In this section of the lab, the students are required to draw the flags of Germany, Faroe Islands, Tanzania, and Burma. As you can see from the pictures below, they are listed in from easy to difficult.

Part 2: Bar Graphs

In this part of the lab, students are asked to read a text file and count the occurrence of each letter. The students are then required to create a horizontal bar graph to display the letter frequency.

For an extra challenge, the students can create a vertical bar graph.

Part 3: Maze Game

In this part of the lab, the students will create a simple maze game. The students read a text file that represents a maze, The students need to use doodlepad and draw the maze represented in the file.

The text file might contain a map that contains a bunch of numbers like below.

 11111211111111
 10000000000001
 11110111011101
 11110000011101
 11111110111001
 11111010111011
 11111000111003
 11111111111111 

0: open area
1: a wall
2: the starting position
3: the ending position

When the student creates a program to visualize the map with Doodlepad, it might look like something pictured below.

The students can then make the maze interactive and control a character with the keyboard to navigate through the maze. In the picture above, it is the character is a purple rectangle.

Prerequisite Knowledge

The lab is broken into 3 parts that increase in difficulty. You can give each part of the lab separately. Below is a list of what they need to know for each part. Every part assumes the students know the knowledge from the previous part.

Part 1: Country Flags

  1. How to use classes and object

Part 2: Bar Graphs

  1. Reading Text File
  2. String Methods
  3. 1D Arrays

Part 3: Maze

  1. 2D Arrays
  2. Overriding Mehods

Ii did this lab after teaching all the above topics and gave the students a week to do the lab. You can split the lab into 3 smaller labs if that suits you better.

Files

The lab is released under the Creative Commons Attribution ShareAlike 4.0 International License.

You can download the lab here.
Github repository is here.
Doodlepad Website is here.

Support

If you like my work, a small donation or feedback will be much appreciated.

Buy Me a Coffee at ko-fi.com Buy Me A Coffee

Leave a Reply

Your email address will not be published.