# Lab 3 (Jan 28-29)

Grades have been updated with your scores on the exam. You will receive your exams back in the lab. Please check to make sure that the score you see listed on the paper copy of your exam is the same with the one that is recorded on-line. If you have any questions please let us know.
1. CandyLand Help.

The demo.

The source code for the demo.

This is the code explained in class. Please take a look at it and try to understand it. You are supposed to either finish this program to do what the actual CandyLand prototype is doing or to write a program of your own design that does the same thing.

This part of the lab is helping you with the homework.

For the ambitious and the extremely ambitious: if the homework is too easy now, go through the next 3 sets of examples and try to figure out how program 4 works. It's quite small but it has no comments.

If you don't get to work on steps 2-4, do not worry! We'll come back to these things. But be sure to check the demos and make sure you get an idea what the programs were supposed to do, even if you don't get to them in lab.

2. Simple, Basic Graphics

Here are two simple examples taken directly from your book. One of them shows how you can draw a small (filled) arc. The other one is getting mouse input and draws small ovals where the mouse has been pressed. Feel free to experiment with more complicated examples after you review the ones below, and the ones in your book.

Drawing circles, arcs and other primitives.

A simple sketching program.

3. Histograms, Pie Charts, Graphs.

Throw a dice and display the outcome in several ways.

The demo

This demo has a certain distribution already wired in an array. You may want to change the program to make (a new) distribution be generated when you push a button etc. Remember the experimental probabilities (frequencies) that we were measuring in lab 2 (when we were analyzing the fair and unnbiased dies)? You can render those in this way, with pie charts, instead of listing them as columns of numbers.

4. Simple 3-D Rendering.

The demo

I hope that you will find this example intriguing and will want to understand the code. It's a very simple trick used for surface rendering when a surface is a function

`z = f(x, y)`
of two variables. In our example we are rendering
`z = sin(x)`
so the `y` coordinate doesn't play any role.

This trick (or, rather, a similar one) was invented by (a certain) Williamson in 1972 and is a very old technique for rendering that can be generalized to more complex examples.

I decided to use it here for its simplicity.