SUCCEED

   

programmingHS 2010
Shodor > SUCCEED > Workshops > Archive > programmingHS 2010

Today, Trent started off the class by implementing a few more abilities for the simulation. He started with allowing the sick people to recover, then added data sets to the graph that showed the population in terms of their current status: sick, recovered, or susceptible.

Joel then stepped in with the main topic for today: graphics. He explained how Java drew objects on what was called a canvas, usually using lines and other filled, basic shapes. He showed us how to draw faces on the previously bland dots that represented our population of people. We treated each square on the grid as a separate entity by using nested 'for' loops to get the coordinates of each square, then multiplying the width or height of one square to get to the correct distance from the origin on the main drawing area.

Once we were in the correct square on the grid, we added facial features to each dot: we started with eyes, formed by lines, and eventually moved to the mouth, which was a line, smile, or frown, based on whether the person was sick or not. In order to draw these lines and arcs, however, we first needed variables to store where each of these features belonged within each square. We declared and set these variables in the same way we determined which grid square to draw in: using the coordinate multiplied by the width or height of one grid square.

Once the basic features were in place, the students were given a chance to experiment with other additions, ranging from hats to beards. By the end of the day, the students had a basic understanding of how Java draws and how to use Java to draw whatever they needed to.