Workbook 2: Graphics APIs and Drawing Basics

Spring 2025 Sample Solution

This is a sample solution for the Workbook. You are welcome to refer to it to learn one way to do the assignment but only after you have turned in your own assignment

Remember to look at these web pages using a local web server! For more information on using a local server, see the Tools for 559 page.

You may have noticed from this week’s assignment that we will be doing non-trivial JavaScript programming. If you feel like you need to accelerate your learning, see the Javascript in CS559, specifically the “Advice on Learning JavaScript” section.

Learning Goals

  1. To introduce the idea of object-based graphics as opposed to image-based graphics
  2. To show the two different types of graphics APIs, immediate mode and retained mode
  3. To give you experience programming with the Canvas API that web browsers provide
  4. To give you exposure to SVGs, which we will look at more in the future
  5. To see how the event and animation loop models introduced in the previous workbook are used in graphics
  6. To introduce the concept of display lists
  7. To practice with reading and writing JavaScript programs with actual graphics programs

What you should do with this Workbook

This workbook assumes you’ve already done the previous week’s workbook, and are familiar with the mechanics of doing assignments and turning them in using GitHub, as well as looking at web pages with JavaScript programs. Remember to look at the workbook with a local web server.

You are welcome to look at any of the files in the workbook. However, you can read the text of the pages in the web browser. The files for you to read the source code are stored in the for_students/ folder. For this workbook, you probably just need to look at the JavaScript .js files. This includes files that need to be modified for the exercises, but also source files that you should read and understand to learn about web programming. We will ask you to make changes to some of the programs, and also write some of your own.

For this workbook, you should not need to add any files to the workbook.

This workbook also has links to required readings. Make sure you read them. Even if you don’t need it to complete the workbook assignment, you will need the information for other parts of class (for example, you may see questions on the surveys or exams). Sometimes the readings are information you will need for future weeks.

Don’t forget to commit and push your work as you go - this way you’ll have a backup in case something goes wrong. Also, don’t forget to complete the Workbook Form when you are done to tell us that you’ve completed the workbook and that we can grade it.

Readings

In addition to the pages and code of the workbook, there are a number of things you will be asked to read. It may work best to read the workbook, and go to the external readings when they come up.

The readings (in order of appearance):
Workbook Rubric (10 basic + 5 advanced (4 max) = 14 total)
Box Basic Advanced Description
1 correct WB2 Workbook Form submission on time
02-04-01 2pts for each of 4 shapes
02-04-02 1 it's a picture
02-04-02 1 shapes that aren't rectangles
02-04-02 1 obvious transparency
02-07-01 circles appear at mouse click
02-07-01 circles change change color when mouse is over them
02-07-01 circles change back when mouse leaves
02-07-01 circle changes color when clicked, hover still works
02-08-01 1 user clicks mouse, firework shoots from the bottom towards mouse
02-08-01 1 firework moves to mouse position over time
02-08-01 1 firework disappears (explodes) when it gets to position
02-08-01 1 small moving pieces appear where big one explodes
02-08-01 1 pieces move outward from explosion
02-08-01 1 multiple fireworks at once (if user clicks quickly)
02-08-01 1 fireworks are different colors
02-08-01 1 explosions fade out (or disappear) after a distance
02-08-01 1 fireworks start from random locations at bottom
02-08-01 1 random fireworks in addition to user clicks
02-08-01 1 projectile motion