Hi!
I'm going to start every lecture with a promise and an artist to reference.
I promise that by the end of this lecture you'll be able to understand how you can use timing to make different things happen at different times in your code.
His most famous work is "One Year Performance 1980-1981" - he spent 12 months punching a time clock every hour, on the hour, 24 hours a day.
Read more here.
I think alot of Tehching's work is about time passing, which is why he's perfect for today's lecture - which is on exactly those things!
The main thing I want you keep in mind today is that you can use time based code to have logic run at certain times or to animate content smoothly or even to only run when certain conditions have been met.
By the end of this lecture, you'll know more about:
- How to preload images and other content into your p5.js sketches
- How to have code run when a user clicks their mouse or presses a certain key
- How to use lerp() and map() functions to scale variables between different values
- How to find out the year, month, day, hour, minute or even second within a p5.js sketch
- How to use frame count, the time between frames or the number of milliseconds since your sketch started to time animation and other things
- How to build asyncronous code - code that can be used to load images and other data into your p5.js in after the sketch has started to run
How to preload images and other content into your p5.js sketches and how to have code run when a user clicks their mouse or presses a certain key.
Let's take a look at how we can
use arrays to store mouse interaction information over time. Instead of using two arrays for mouseX and mouseY positions, how could we have stored this information differently? Have you ever heard of
a vector? It's a really useful way of bringing two (or three) position values together into one object.
How to use lerp() and map() functions to scale variables between different values.
Let's take a look at the p5.js reference page for the
lerp() function and the
map() function.
Let's take a look at
the p5.js map example to see how to use the map() function to take a mouse position and turn it into the radius and colour of a circle. This is a very powerful technique - taking one input value and scaling it to lots of different types of information - radius, colour or anything we like. One way to think of it is to think of taking a range of values and scaling them to a value between 0 and 1 - then you can take that value and scale to any other value. If you can get your values to 0-1 you can take that signal and apply it anywhere, to anything.
How to find out the year, month, day, hour, minute or even second within a p5.js sketch.
Let's take a look at the reference for the
pmouseX system variable and how it can be used with it's y equivalent in this
drawing patterns example.
But what if you want to do more advanced animation?
How to use frame count, the time between frames or the number of milliseconds since your sketch started to time animation and other things.
Finally, let's look at how to build asyncronous code - code that can be used to load images and other data into your p5.js in after the sketch has started to run.