It is time for another chapter from the nature of code.
Now I've got a little bit of an issue here,
but I'm not entirely sure whether this should
be chapter 5 or chapter 6.
In the first edition of the book,
it was distinctly chapter 6 as you're
seeing right here burned into the screen of this video
forever.
But I am toying with the idea of moving this up to chapter 5.
This is not the most important thing
for me to cover in this video, the important thing
is the topic, Autonomous Agents.
And this is why I was so darn excited about this topic.
Let's say I have a table.
And I were to place a block on the edge of that table.
Adding a wind force expressed as a vector, this block,
this inanimate object with no any easier being
or life or hopes or dreams or fears
would just blow off and fall off the table.
But what if this wasn't a block, what
if this was a magical creature.
And instead of a gust of wind, there
was a big bad scary monster.
And remember this is no longer an inanimate object,
it's a being with desires and feelings.
It feels fear and it decides on its own
with its brain to leap off of this table
to escape from the monster.
Now it might seem ridiculous that I'm
going on and on about this, but this is a big conceptual leap.
An inanimate object which is all of the simulations that
I've looked at in chapters 1, 2, 3, and 4 ,
versus inanimate object, an object that has its own ability
to perceive its environment, make decisions and perform
actions based on those decisions based on its perception
of the environment.
And this is exactly the way that I
think about what it means to be an autonomous
agent in the context of the examples that
demonstrate to you in the Nature of Code book.
So let's for a moment Zoom all the way
to the end of this chapter, the last example
is a flocking system, which I'm showing you
behind me right now.
Here I think we can take a peek into what
are the three key components of what it means
to be an autonomous agent.
Number 1, an autonomous agent has a limited ability
to perceive its environment.
So it has some sensors built into it.
It knows where it is in relation to other things in the P5
Canvas itself because that's what we're working with.
But that word limited is really critical.
It's not an all knowing creature that can see everything
around it, but we're going to get more unique and lifelike
behaviors.
If we could only see within a certain distance
or what's right in front of it or maybe
we think about its perception, not as vision
but as some other type of sense based perception.
An autonomous agent processes the information
from its environment and calculates in action.
Again this is the critical conceptual leap forward.
Instead of being an inanimate object that's
just responding to forces in the system,
the object itself the agent, is perceiving and then translating
its perception into a force, into an action
that it's going to take.
An autonomous agent has no leader.
Now this is not necessarily a hard and fast rule
in what you should always do when you're
programming things in p5 js but it
is an important critical note here in terms
of this flocking example.
This is an example of a complex system.
A system that is more than the sum of its parts.
It exhibits a global intelligence and yet
that global intelligence does not come from a single leader.
There's no one leading the flock around.
The emergent behavior that you're seeing
comes from all of the small local interactions
between all these little triangles moving
around the Canvas.
Each one of these what are actually called voids
just follows three simple rules, alignment, cohesion,
separation.
I'm going to get to those rules in a later video
while I go through this in detail.
They're easy to understand and easy to define.
The outcome, the resulting system
is chaotic and hard to predict.
But I'm getting ahead of myself and veering
or should I say steering off into strange directions I don't
need to go down right now, because I want
to double back and start with what
is the core foundational element of what it means
to be an autonomous agent.
And how does that element linked back to everything
I've done already in chapters 1, 2, 3, and 4, and maybe 5,
I'm not really sure.
We can trace everything I'm talking about right now,
all of these ideas back to the book Vehicles,
Experiments in Synthetic Psychology
by Italian neuroscientist Valentino Brandenburg.
One way of looking at this book is
an exercise in science fiction.
Brandenburg vehicle is an entity a vehicle
that is a hypothetical self operating machine that
can make decisions about how to behave in an environment based
on its sense perception.
Take this example of these two Brandenburg vehicles.
The one on the left a, has sensors
to detect a light source and always steers away
from that light source, while the one on the right, b,
always steers towards that light source.
But the magic the wonder of Brandenburg's book
is not the sense of these vehicles as just steering
away or towards, but is exhibiting emotion
through their sense perception and motion itself.
The left exhibits fear, moving away from the light,
the right exhibits aggression, moving towards the light.
Brandenburg vehicles have been a source of inspiration
for many artists.
Notably one of the creators of processing
itself, Casey Reese used them as inspiration
for his series, Process Compendium.
Here's also a sketch that simulates Brandenburg's
vehicles in processing itself Casey Reese
created as part of his artistic process
in developing the series.
Really think the word processing a lot.
Have you noticed that?
So why am I going on and on about this book
called Vehicles.
Well, in addition to just being a wonderful thing on its own,
it serves as a core piece of inspiration for this paper
by Craig Reynolds from the 1999, game developers conference,
steering behaviors for autonomous characters.
And in this paper Reynolds proposes
a set of solutions for autonomous characters
to behave in world in a lifelike and improvisational manner.
This work is key and fundamental to so much that we experience
in today's computer graphics, animation, games, films,
interactive systems, all of that stuff.
And ultimately what I want to do in this chapter
is outline the core principles of Reynolds' paper
and re-implement those principles using p5 js and all
of the stuff that I've done in chapters 1, 2, 3, 4, et cetera.
In fact, scrolling down in the paper itself under a simple
vehicle model, we quickly find that what are the properties
of that vehicle. , Mass, position, velocity, max force,
max speed, orientation.
This is exactly everything that I've done with mover, particle,
and now what I'm going to call vehicle.
In the paper Reynolds takes the idea
of the motion of an autonomous character
and divides it into three steps.
So I'm going to go through a little bit about these three
steps.
But I want you to just get out your mental notepad
and take a note of this first one.
Action selection.
This is really where your own creativity can shine.
What are the agents, the characters in your world,
what are their goals, what are their hopes and dreams
and fears, what's their strategy, what kind of plans
do they have.
I'm going to go through some canonical examples of steering
behaviors like seeking a target, fleeing a target,
but you are going to have your own creative ideas of what kind
of world you want to build.
Steering this is going to be the big focus of the next video.
It's actually a very simple formula
and it all boils down to calculating a force.
So we're really lucky we spent two whole chapters going on
about vectors and forces, it's going
to boil down to a formula to calculate a steering force.
And then locomotion is how does that agent, that character, how
does it animate, how does it move.
So in one sense that's the physics engine you're using.
In our case, the position velocity acceleration or maybe
you're using a different physics engine.
But also you can think about what is its design,
does it have oscillating wings, lots of other things
that you could put also your creative spin on.
If you have the time, I really would recommend
reading the full paper, it's pretty accessible
and explains all the different kinds
of concepts and actual algorithms
for the different steering behaviors in a lot of detail.
Ultimately, it's my goal personal goal
to have a p5 js example for every one of these behaviors
that Craig Reynolds outlines.
I have a bunch of them already and I
I'm going to do some of them in videos and then maybe
eventually on the nature of code website
or in the coding training website,
you'll be able to find additional ones.
If you want to contribute and try any of them
that I haven't done already, I highly encourage you to do so.
I should also note here this distinction
between simple behaviors for individuals and pairs
and combine behaviors in groups.
So this idea of emergence of a complex system, that's really
going to arrive when I get to going through a combined group
behaviors.
Flocking being the one that I refer
to as the ultimate example of this chapter.
But I'm going to start in a few videos just
going through the core foundational examples of what
it means to program and implementation of Craig
Reynolds steering force.
And the first one to start with is just seeking and fleeing
a target.
And that's what will be in the next video.
I really hope that these concepts inspire you
and that you discover a new set of tools or ideas
that you could incorporate into your own practice whatever
that may be.
And I can't wait to see what happens.
So see you.
There was no code in this video, I think, if I'm right.
But the next videos all throughout this chapter
will be heavily about the code implementation itself.
Also, I already made two whole coding challenges
about steering forces and the flocking system.
So if you wanted to leap ahead, put links to those
as well you can go watch those were made several years ago.
But I'm doubling back now to go through all the stuff a bit
more detail.
All right.
Thanks for being here.
I hope you like this video.
This is a hard one to do.
And I hope that it made sense and let
me know what you thought.
I'll see you soon.