hello again okay so we're going to begin
now so before we kind of get into the
real kind of meat of the material um
we're going to do I'm going to do a few
videos I'm just kind of going to get us
back and used to programming it
processing and where are we what's going
on
I left the fluorescent lights on turn
those off and just to get us kind of
going here so what I want to start with
is actually a simple example the first
half of this whole video series is going
to be about programming a physics engine
toy it's really loud at the hall play
quiet down there okay um but so before
we we're going to formalize our
understanding of motion we're going to
look at vectors we look at forces but to
even give us a place to start I think
something we could look at would be a
random walker so I'm going to move over
here for a second and so here we go here
is a very simple processing program with
a random bar it's been running for maybe
about 15 minutes now we could kind of
find the little a little friend
somewhere in here do you see where is oh
there is is down I don't know if - he or
she but it's down here somewhere kind of
moving around randomly walking so what's
going on here we have a program that
clearly has a variable called X and it
has a variable called Y those variables
are storing the XY location of this
little dot that's moving around the
screen and you can imagine somewhere in
the program we're saying hey draw an
ellipse or maybe it's a point maybe it's
a line whatever it is I'm going to say
ellipse right now I maybe it's a tiny
one at that location the two pixel by
two pixel wide location we're drawing
that circle so what is it about this
example that is the reason why we're
talking about it well somewhere else in
the code right if we if this works our
code first of all
X&Y of no additional value but let's say
they got initialized let's say we're
doing this ellipse and draw over and
over again we just have this little tiny
circle static on the screen in one place
never moving but it's not it's this
little dot it's moving we zoomed in we
saw it move it's moving why because
somewhere else in the program are
written these lines of code x equals x
plus something y equals y plus something
some thing and by the way this something
question mark this is the question we
want to answer in video after video an
example after example over this entire
series every program we're going to look
at was more and more sophisticated
motion really just comes down to putting
more and more interesting stuff in here
how do we change that object's location
over time well so the other thing about
this that I've written here is we have
we have an organizational structure that
we need to live by in these examples
it's object oriented program now let's
try to remember something about
processing first for a second so if you
recall processing has these two fumbling
word every time and you first started
learning and write your first processing
sketch you're always there right ok here
we go void I don't know void means it's
very weird of course now hopefully you
do void set up curly bracket open close
curly bracket void draw curly bracket
open close curly bracket this is this is
something that you're probably hopefully
very very used to if you have a dead
prostitute happens the beginning gets
triggered it's setup draw happens over
and over again this is our main
animation loop if we move something draw
something blue something draw something
we see it moving on the screen so
traditionally speaking these variables
might be declared at the top I'm going
to initialize them in setup we might do
this and draw we might do this in draw
and that would be our program however we
need to live in an object-oriented world
we don't need to you so do you do any of
this you could really just shut this up
right now but if you want to follow me
along here my examples be
examples they're going to be
object-oriented it makes a lot of sense
for them to add Victoria to we want to
think of the things that move around her
screen as an object so we want to create
this object let's call it a Walker we're
going to declare that as a variable that
native the variable of W the type is
Walker Walker is going to be a new
Walker object and then that's what we do
at the beginning we set up our object
and then a draw
maybe we call like a function called
walk and maybe we call a function called
display what does that mean this is the
structure we want to have that we're
going to have we're going to be
declaring objects initializing objects
and using those objects over and over
again in draw now where do these where's
all this stuff match up to well if we're
going to have an object of type Walker
we have to declare a class of type
Walker Texas Ranger and those curly
brackets go all the way around each
Walker has its own x and y each Walker
perhaps has a function well I guess I
called it walk called walk each Walker
perhaps has a function called display so
we can see here object-oriented
programming what is it it's data and
functionality together a walker is a
thing that has a location what else is a
walker it's a thing that can move that
location it's a thing that can display
itself in that location that's what
we're describing here we forgot that
here we need to have a constructor right
the constructor is the objects method
where that constructs the object work
where all of its goods kind of like the
objects set up in a way is a set up
which is where you do all the stuff that
happens at the beginning of the process
we sketch an object's constructor is its
own set up it's all the stuff that
happens when you first make that object
okay it was just really good exciting
and nobody could believe what they're
watching this amazing compelling video
oh well this is our life you know here
we are drawing things about constructors
ok so this is the structure we want to
get used to but what are we doing we're
doing
a random walker what is a random walker
well let's go back and look at our
little random Walker here again press
that button again Here I am and let's
zoom in on him him I don't keep calling
me him I'd like to keep I want to redo
this video just to be less gender
specific um you can't really see it over
there but but this this Walker is a
traditional I would say severe tradition
he can't stop it this random Walker is a
very traditional random Walker we want
to race on this but it's too late so oh
and I'm you can't see me erasing it I
got to get better practice it is that
there we go I'm over here now
oh I've also made this video 7 minutes
it's too long up which I do it again I'm
just going to keep going I'm probably
going to redo this video later ok so
here is an X Y location the traditional
random Walker sort of basic first
example you could say there are only
four options move up move to the right
move to the left or move down meaning
we're saying ah this is one option this
is another option this is another option
and this is another option either X
changes by 1 or negative 1 or Y to 9 1
or negative 1 4 options each with an
equal probability 25% 25% 25% Furguson
let's go see how that's implemented in
the code now i zoom back out and if I
open this up I've got the code and we
can see here look this is exactly what
we talked about a walker object a new
walker object Walker steps and Walker
draws over there I said walk and display
now I'm saying step and rendered I'm
sprinting your code ok so now if I go
over here to Walker we can see AHA the
Walker has two of X&Y it's initializing
the middle screen the render function
draws it as a point and now look at this
we're using the random function and
processing to choose one of four options
x + + x
- why + + or why - - we're keeping the
Walker on the screen this is your first
exercise create a random Walker and have
it do something slightly different is it
purely random is it based on probability
is it using Perlin noise does it like to
move to the left does it like to go with
spiral patterns what kind of motion can
you do just with this object-oriented
structure take this code mess with it
just work on the step function and see
what you can make in the next videos
we're going to look at techniques in
probability and techniques in Perlin
noise we're going to see how those might
apply at this random Walker with that
this is the scene finish done oh I need
a button that stops recording I have to
go over here it's very awkward you're
watching the end of this for no reason
and click the mouse code