UAL CCI: Introduction to Creative Computing 2025: ⏰ & 🗺: Lecture 8: Time and Algorithms. Back to slide index.
The two main things I want you keep in mind this afternoon is that you can use algorithms to make decisions in your programs and you can use time in your code to trigger things and to animate smoothly.
By the end of this lecture, we'll have learnt 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 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 asynchronous code - code that can be used to load images and other data into your p5.js in after the sketch has started to run
What algorithms are
An algorithm to work out if something is off the screen
An algorithm to work out if a mouse is over a rectangle or a circle
An algorithm to sort things
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 find out the year, month, day, hour, minute or even second within a p5.js sketch.
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.
An algorithm to work out if something is off the screen. Let's code this together from scratch. I find working on paper (or whiteboards) really helpful for this.
An algorithm to work out if a mouse is over a rectangle or a circle. Let's code this together from scratch. What are the conditions that must be true if a mouse is over a rectangle? And a circle?