p5js week 10

It usually takes butter to make good toast. In our case, practice will be the butter for our toast.

Before we practice, though, we want to spend a little time working on our wiki pages. Work with the teacher to make some improvements to your wiki page. After that, come back to this practice!

Using classes seems hard, so let's do another simple one step by step. Here's what we want to do:

  1. make a simple picture
  2. put it in the draw method of a class
  3. generalize the arguments of the items in the draw method, adding them as properties of those objects
  4. use buildArray to produce the objects
  5. use forEach to call the draw method on each of the objects

We'll do one together first, then you can do it again with your own simple drawing.

First, we start with some buttered toast.

Now we'll make a class and put this in the draw method so that we can draw it.

Notice that we have to call the constructor once using the “new” keyword with the class name to make an object to draw.

We'll change the position arguments to base them around 0. Then we'll add position properties. We'll use translate and resetMatrix to set the position and restet the matrix so that it's ready for the next thing we draw.

We'll add in a random rotation, like we did before.

Now let's use buildArray to make many of them, then use forEach to draw the objects from the array.

Let's go ahead and make the color of the toast more variable. We'll also make the butter and its position change each time.

Go ahead. Start with the easiest version of this ButteredToast class, then replace the draw method with your own code. Don't forget to rename the class to something appropriate. You'll need to change the name in the place where you call the constructor, too (hint: look for the new keyword).

Remember, these are the instructions from last time. Can you make a drawing that does the following?

  1. draw an animal, plant, or a complicated shape from your imagination
  2. there should be many different versions of it, like different sizes and different colors
  3. make a class to draw it
  4. use buildArray to fill an array of objects from your class; try to make 100 or more!
  5. use filter to change your drawing in some way

When you're done, be sure to put it on the wiki!

  • p5js-week-10.txt
  • Last modified: 17 months ago
  • by reina.chen