Review Session Nov 29

code2reviewFast.mp4

1. Map Function

When you have a variable that could contain a numeric range of data and you want to “map” it to a new range. (For instance I have a variable that has a range of numbers from -1 to 1, yet I want to “map” it to a range of numbers from 0 to 400). We can use the map function:

// if oldValue goes from -1 to 1
//   newValue will go from 0 to 400
// For instance if oldValue=0.5, newValue=300
let newValue=map(oldValue,-1,1,0,400);

2. Basic Trigonometry (sin and cos)

The basic trigonometry functions are extremely useful for generative art. I like to use these functions for two reasons, the first is that no matter what “x” value I pass to sin(x) or cos(x), I know it will always return a number from -1 to 1. Second, I like to use these functions, especially with movement because I know that their results will look more natural than movement that happens linearly over time.

https://en.wikipedia.org/wiki/Sine_and_cosine

https://en.wikipedia.org/wiki/Sine_and_cosine

From Class, creating an interesting design using Sin. Feel free to change some of the parameters to see how it effects the design:

Look at source at P5 Editor

Another example (similar, not covered in class):

Look at the source at P5 Editor

Notice how the balls moving in the following sketch appear to move with a rhythm that looks more natural:

Bouncing Ball with Sin at P5 Editor

More Circles at P5 Editor

3. Random