Intro CS Assignments
Assignments by week:
Fall Term:
Winter Term:
Spring Term:
Monday, October 1
Description
Introduction to Functions
Homework
  • Write a house() function that takes two parameters: x and y. The function should draw a house centered at the values provided for x and y, using relative calculations to place all of the shapes (like "x-100"). The house can be simple (building, roof, door, windows); you don't have to make it as fancy as your earlier houses if you don't want to.
  • Write a randomColor() function that takes no parameters. It returns a color that has been generated from completely random numbers.
  • Write a quadrant() function that takes no parameters. It uses the current position of the mouse (mouseX and mouseY) to determine which quadrant of the screen the mouse is in. It should return an int that correponds to the location as follows:

    1. Top-left
    2. Top-right
    3. Bottom-left
    4. Bottom-right
  • Write a radial() function that takes four parameters (all floats): an x and y coordinate pair, a length, and an angle. The function should draw a line starting at (x, y), with length length extending at the given angle. The function does not return anything. You'll need to use some trigonometry to make this work!
Tuesday, October 2
Description
Function Practice
Homework
  • Here are the functions that we worked on in class today. Those that we didn't solve together in class are your homework tonight:
    1. Write a function that determines if the distance between the current mouse position and the previous mouse position is greater than a given amount. The function should take a single float that is the minimum distance, and should return a boolean. The function returns true if the absolue distance between mouse locations is at least as large as the amount provided in the parameter. You may use processing's built-in dist() function to calculate the distance.
    2. Write a function that takes a single integer as its parameter, representing some number of seconds. The function does not return any values. Instead, it uses println() statements to output the number of hours, minutes, and seconds that are needed to represent the given number of seconds. For example, if the number of seconds was 342, the method would print "0 hours, 5 minutes, 42 seconds". If the number of seconds was 90000, the method would print "25 hours, 0 minutes, 0 seconds".
    3. Write a function that determines if the given year is a leap year or not. It accepts a single integer parameter: the year value to test. It returns true if the given year is a leap year, and false otherwise.
Thursday, October 4
Description
More Function Practice
Homework
  • Create a function called house(). It takes no parameters and returns nothing. The function draws a house that is centered at the origin (0, 0). You don't need to turn this in to me, but be ready to use it during your next class.
  • Read the processing site tutorial on 2D Transformations. You may also wish to read the reference entries for the functions introduced:
Friday, October 5
Description
Coordinate Transformations
Homework
  • Write a house function that draws a house centered at (0,0) [the origin] Now, use coordinate transforms to move the house wherever you want.
  • Write another "house" function that takes two parameters: x and y. The function should draw a house centered at x and y, using matrix transformations (translate()) instead of altering the coordinates.
  • Write a house function that takes 4 parameters: x, y, scale, and rotation. The function should draw a house centered at that location, then rotated by the given number of degrees, then scaled by the given factor. You may want to call one of your other house functions from this function so you don't have to copy and paste all the code (just add the bits that do the rotation and scale).