Assignment Set 7

Objects with Functions

7.0 Exercise — Creating Your Own Functions

This exercise is a little different from most. Take an existing project you've done (e.g. portrait, variations on a drawing, wallpaper, etc...) and reorganize it using functions that you define and call. You must define and call at least two functions. Here is an example I did for my whale (and this was the original). The end result will be the same, but the code will be different. +10 points if you use parameters.

7.1 Exercise — An Array of Objects

Using an array of objects with functions, create a random amount of circles or rects on the screen. Have them all move vertically. When each shape reaches the top of the screen, reset it to the bottom. Your sketch should look something like this.

7.2 Project — Generative Landscape

For this project, you will create a continuously changing, scrolling landscape. This could take the form of a scrolling citiscape. It could be a conveyor belt at a factory. It could be a ship moving through outerspace. It could be someone looking out a train window. It could be sailboats on the ocean. If you're lost at how to do this, start with your solution from exercise 7.1 and build off of it. Use classes. You must have at least two different moving object types (i.e. two arrays of objects) in your solution. The landscape should never end. Here is a good way to approach it:

  • Think of a continuously changing, scrolling landscape you'd like to implement.
  • Draw a static background.
  • Create a class with a constructor function (e.g a star), some variables, and function to display them.
  • Create an array of those objects using the new keyword in the setup function.
  • In draw, use a for loop to call a display or update function you've defined.
  • Repeat this process for each new item in your landscape.
  • Consider moving objects that are further away slower to give a sense of depth.

Here is an example for reference. This would receive a terrible grade, but should help you with how you might structure your code.

To hand in your work get the URL from the editor and link to it from your index.html page. To receive credit, it must be uploaded by class on the date specified. Label it clearly. Here is help if you need it.

Projects will be graded on both creativity and implementation.