Computational Form
Jared Schiffman
Fall 2007


Week 2 Assignment

Problem 1. Complete the Vec2d class. Add the following methods to the class:

a. Subtract one vector from another and return the resulting vector.

b. Divide a vector by a float and return the resulting vector.

c. Calculate the length of a vector using Pythagorean theorem and return the resulting float.

Problem 2. Create a function called drawCircle that takes as arguments a radius (float), a number of points (int) and a center point (Vec2d) and draws a circle as specified. Demonstrate that this function works by using it in the following ways:

a. Draw 5 circles in a row, each with increasing radii (10, 20, 30...), just touching each other, each composed of 30 points.

b. Draw 5 regular polygons in a row, each with an increasing number of points (3, 4, 5...), each with a radius of 50 pixels.

Problem 3. Create a function called drawOval that takes as arguments a horizontal radius (float), a vertical radius, a number of points (int) and a center point (Vec2d) and draws an oval as specified. Demonstrate that this function works by drawing 10 ovals in a row, each with an increasing horizontal radius (10, 20, 30...) and decreasing vertical radius (100, 90, 80...).

Problem 4. Create a function called drawStar that takes as arguments an inner radius (float), an outer radius (float), a number of points (int), and a center point (Vec2d) and draws a star as specified. Demonstrate that this function works by drawing 100 stars with a varying number of points placed randomly about the screen. Feel free to change the background color for a more dramatic effect.

Problem 5. Create a function called drawNecklace that draws a pearl necklace. Feel free to shade the pearls or make them sparkle in the light of the moving mouse.

Problem 6. Create a function called drawClock that takes as arguments an hour (float), a minute (float) and a number of seconds (float), and draws an analog clock. Feel free to add a pendulum or any other fancy clock accoutrements.