[Music]
good morning happy coding train day it
is me Dan I was like taken aback by the
fact that I had to start I thought I had
another 30 seconds there there's a lot
to say probably as there often is and
I'm you know while you are watching the
coding train perhaps at this point it
should just be called the nature of
coding because I am just still slogging
through making the examples in the
nature of code book and that's what I'll
be continuing today do have some ideas
for things in the next few weeks month
or two where I will hopefully take a
break from nature of code but I would
like to by June and kind of get through
the entire book we'll see if that
happens but before I do any of that at
all I have to test something yeah you
might I don't know if you noticed
something slightly different about me
and no no not the haircut there can I
had last week same haircut nope not this
sweater that I don't think I've ever
worn before although I have worn this
shirt it's something else
I will I will wait for a few minutes to
see if anybody can notice something else
that's maybe a little different and
while I'm waiting I will take a brief
moment to thank the sponsor of today's
coding train - Lang comm - late is a
password manager if you don't have a
password manager you should have a
password manager and I would - Lane is
one that you could try and if you go to
- Lang comm slash coding train you can
get a 30-day free trial of their premium
service and then also if you choose to
purchase the p m-- service a 10%
discount everybody's got it the jet
already everything yes yes
new glasses but not just new frames
which hopefully you ohhblue reflect okay
so that's interesting let me address
that so the lenses are really what I'm
here to discuss because something quite
big has changed I which is these are
progressives I've been having a lot of
trouble reading really for the last year
or two and I would have to take my
glasses off to read and so the options
as I understand them well besides all
sorts of like laser eyes
options were to just get a second pair
of glasses so I would switch if I'm
gonna read but that's sort of silly
because I could just take them off to
read which I was fine doing I was that
well the other option was just do
nothing but the third option was get
progressives which I now have and I have
to say yeah I mean I've only had them
for I think I got them on Tuesday so I
mean like for about 48 hours in and I'm
having quite a difficult time with them
if I'm being perfectly honest although
I'm much more used to them today than I
was yesterday or the day before but I
don't know if anybody watching we're all
so young and youthful with your
excellent eyesight oh just wait just
wait until you get to be me and you need
these but I didn't really rise is your
but because of the way the lenses
progress for distance and reading
there's some distortion on the sides and
we're going to create that progression
and so it's my peripheral vision is less
it's has a smaller cone a focal poke
what's the thing Fache frustum my
frustum vision is smaller but the good
news is I mean all for you the viewing
audience because I know your favorite
part is me reading random numbers I'm
looking at the chat here and this I
could just do so easily now the reading
is quite phenomenal and I I wasn't
really able to before so we're gonna do
a reading of the ceremonial reading of
the random numbers with my new
progressive lenses and people had
mentioned there's a blue and so I did
get I did I don't know maybe this is
silly but I did get the blue light
filter in them which hopefully is not
going to be too distracting or cause
like weird reflection in me making these
videos but we'll find out field of view
thank you I have a problem I can't
remember words anymore I think it's
related to the fact that I need lenses
it's good stuffs all going downhill they
go watch my I always say like all those
videos are so old or out-of-date
I think I had was like I was what were
with it then so let me go back and watch
the old nature of code videos 931 fifty
two thousand one hundred and seven
ninety two thousand eight hundred and
twenty three thirty nine thousand nine
hundred and ninety four seventy four
thousand six hundred seventy seven
ninety nine thousand four hundred and
seventy one fifty four thousand and
sixty five fifty four thousand nine
ninety six thousand two hundred and
fifty six 80 thousand eight hundred
twenty three twenty five thousand four
hundred and seventy nine seventy
thousand eight hundred and twenty three
thirty nine thousand six seventy nine
thousand two hundred and ninety four
ninety three thousand one hundred and
seventy thirty four thousand four
hundred and sixty nine the music is a
bit loud
okay thank you that's useful to know
that's a oh my goodness it certainly is
sorry about that no wonder everything
seemed off sorry about that
I'm fixing why is blue filter useless no
I I think it is useful I'm just
sometimes I wonder like what's this
what's the real science behind blue
light filtering and what studies have
been done and how effective is it how
bad is blue light how effective it's the
filtering but you know and you know one
thing that I try to do is you know I
really give myself like I should give
myself like at 8:00 p.m. limit but 9:00
p.m. I try after 9:00 p.m. I try to look
at no phone no screens nothing I'm
watching a movie or whatever but and I
don't want the fact that I have a blue
light filter to give me an excuse if you
like oh now at night I can play pokemons
go on my phone not that that's what I
play I don't play that no that's like
that's like so two years ago and you
know people in their 40s don't play that
anyway so why why would I be playing
that no definitely not I do not
like trying to get to level 40 or
anything and I don't have like extra
yeah no no no no no that's somebody else
[Music]
it's 8 p.m. a year coincidently yes Sri
young turn this off you've got to get to
sleep soon
too blue light for emanating it's not
worth it
the coding train is not worth it'll be
here tomorrow morning when you wake up
and our fresh I do use nightshift yes I
do
I do use night shift Luke is asking to
use the night shift I also use that
which I quite enjoy all right I would
like to get into it pretty quickly I'm
there's a little less of the high jinks
these days on the coding train because
I'm trying to I'm trying to be a serious
teacher of content I'll be here till
around noon and that's that let's see
what other kind of OC like my screen is
like distorted especially I'll look from
left to right it's like a waving bubbly
thing whoo okay but I'm gonna I'm gonna
I'm gonna be fine all right let's open
up the Chrome browser and let me just
mention one thing and I'm really not
mentioning this to ask anyone to buy
anything or spend any money I just want
to let you know what's going on because
some people have asked the coding train
hoodies have hit the minimum number of
orders to get made so they will be on
the way nobody needs to buy anymore but
I just wanted to mention that if you
were interested I think maybe tomorrow
I'm gonna say hey go ahead
that's enough orders send them to the
hoodie maker and so I don't know that
you'll be able to order them anymore
after tomorrow so if you were interested
in getting a hooked coding trade hoodie
I know I mean hopefully we can put them
up for sale again or make them or make
t-shirts
something new next time but I'm they do
these are being done in limited runs in
in terms of how they're being made and
the quality so if you were interested in
one of those
now's your lucky your last chance okay
I also by the way I put one of these
mugs in the dishwasher here at work and
it got a little faded so if you have one
of the mugs you can wash it and wash it
does anybody have one of these I don't
have one of these if you have one of
these could you send me a like picture
of it or something sends me on Twitter
social media whatever disk or join the
discord that's the other thing that I
was like to mention the discord has been
as far as I'm concerned a big success I
don't success is the right word but has
been really productive in that it's III
don't know where to tell people to go to
get help specifically related to the
content of my videos there's lots of
places on the Internet to get code help
some are you know they all have their
pros and cons and they're sort of vibes
and different strokes for different
folks the processing forum discourse
discourse it's confusing is not discord
but discourse dot processing dot org is
a really excellent place to ask
questions about processing and p5.js
specifically and I would say there's a
lot of crossover between the coding
train community and the processing
discourse but if you want to engage with
getting help from the you know laser
focused coding train passengers then the
discord is the place for you to do that
and if somebody I know that I saw Kobe's
name pop up in the chat is can post a
link to joining the discourse the
discord in in the YouTube chat that
would be helpful
now I also wanted to mention a couple
other things Google Summer of Code
I think this will get me to the site I
can't remember if I mentioned this or
not but the organization's have been
announced yeah because this was
announced before I probably mentioned
this last week but google Summer of Code
is a program that I participate in as
part of the processing foundation but
there are over 200 I think whoa
oh no 686 over how ever many years but
there are a large number of other
open-source organizations that
participate as mentoring organizations
for google Summer of Code and you if you
are a student I mean do have to be a
student unfortunately or fortunately you
can apply to work with collaborate with
make an open-source contribution to one
of those projects over the summer and
get paid a stipend so again I'm not an
official representative of Google or
Google Summer of Code all of the
administration and application process
and eligibility is handled through them
I'm just here because it's a program
that I participate in as a mentor and
would love to encourage you to apply if
it's something that interests you and to
the extent that I can help with that or
we can maybe we can open a discord
channel for people who are questions
about that that's something that I would
be open to Thank You Koby for posting
the discord invite I should probably
just get a button like I have one button
on my stream deck when I press it it
both choo-choo into the chat you know I
should maybe make one I need to get the
dist that stream deck with the with more
buttons I need more buttons oh my god I
just want I just like a giant panel of
buttons that's my dream all right so
that's the nature of code is what I'm
gonna be doing what other things I
shouldn't make a list of it'll be so
helpful if I've just made a list of
things that I wanted to mention as
opposed to just try to remember them
while I'm live-streaming just think
about this for a moment
[Music]
I thought of it alright so there's two
things up and coming on this channel
that are unrelated to the nature of code
Oh everything's kind of related nature
of code one is March 14th is Pi Day
and traditionally I've tried to do
something special to mark the occasion I
will be not available to livestream on
pi day so I'm probably going to prepare
something in advance to really be
released on pi day but I don't have any
idea what to do so if if you know
certainly I'll take suggestions in the
discord but right now for better or
worse the system is a github repo where
you can if you have a suggestion for a
topic oh whoa whoa hold the presses do
welcome for your membership to the
coding train you have one random number
[Music]
and that number is 90 4544 you are the
sole owner I mean I don't think we're
ever gonna get to a million members that
would be kind of nuts I will just ride
off into the sunset if that happens and
thank you by the way if you don't know
there let me see if I can find how am I
gonna do this
I'm looking for there we go perfect this
is what I'm looking for if you are not
aware and I'm sorry if you don't want me
to be plugging this it's too late for
you you put this on the internet I get
to plug it without your permission
Jose teaches a course called
introduction to computational design and
it seems like it's at Harvard and all of
the lectures are all online in this
playlist is this a learning playlist or
is it just a regular playlist you should
get access to the learning playlist if
it's not it looks like a learning
playlist so check check this out welcome
well thank you I uh I was talking about
something high day so back to this so if
I go to label you won't be able to add
your own label but I encourage you to
file your issue with your suggestion and
then I will or somebody else will add it
but I'm just gonna see what's there
right now so Pi Day 2020 let's see
there's every year so you look at this
every year damn does a couple cool yes
thank you I am as my kids tell me very
cool I'm the cool dad definitely every
year dance has a couple cool coding
challenges related to calculating
visualizing or using pi this year would
be a good time to start a pythons no no
no you make last year's pi day
challenges in Python and also explain
Python today it is a really nice idea
ddddd ttttt but i'm not sure that that's
gonna fit with my schedule and something
there you know actually at my son's
school not to keep talking about my kids
today but they're always on my mind they
have a PI digit memorization contest so
I one thing I was thinking is there a
tool I could build it helps people
memorize the digits of pi if you have
any ideas about that but it really
anything that is
eh especially if it's like a beautiful
geometric pattern algorithmic pattern
that's what I really like to do for
these kind of challenges that relates to
PI and the mathematics associated with
PI then please suggest that here as a
github issue or talk about it in in the
discord otherwise I will be just baking
a pie oh that's what I should do clearly
I mean because have you all seen the
bone Appetit YouTube channel I know I'm
like really late on this but it is just
Oh chefs kiss I just wish that I could
be like one of their cooking people
which I definitely cannot be there's no
way but I aspire I can a spike in dream
D t6o which i assume is the same ddddd
tttt tttt has memorized 80 digits of pi
i was like how did you do that maybe I
should just try to memorize them but I
think is I don't think I can do a live
stream so I don't think I'll be like a
live PI day live stream this year but I
do want to do just like a video maybe
I'll do it as a Cabana one or something
like that will I be here on towel day
yeah maybe I'll just wait till tala day
so that's number one number two is
insanely and I really don't understand
how this is possible but it seems as if
this channel will soon have 1 million
subscribers I'm assuming that then the
next day they'll just like everybody
will unsubscribe but you know probably
at least for a day and me I kind of want
to do nothing like just like keep going
is I'm usually doing but people are
asking and maybe it is a nice thing to
think of doing something special to
celebrate that so I could use ideas I
really want to do something with the
original unoriginal I I know I got I'm
gonna keep mentioning this till somebody
if you live near a like a rare bookstore
or have some way of finding a copy of an
original print I will pay I will pay for
shipping I will purchase all these
things I would very much like to
purchase
a original print of this million random
number book I have found some listed
online but there's no way for me to
authenticate them and I've emailed and
asked and I mostly I'm seeing them three
amazon listings and no one will give me
any real information and I don't feel
like it's a good idea to spend a large
amount of money to purchase something
that I have no idea what it really is
okay
[Music]
oh Lord
the cutting tree hit with your
membership of the coding train you have
won stickers in the name eventually
eleven thousand eight hundred and twenty
seven new member that I already now
can't see in the chat anymore I think
was Adrienne that is your random number
you're the sole owner of the random
number eleven thousand or twenty seven
please write that down because I won't
remember I suppose a lot of the numbers
appear more than once in this book
though so you might have an issue there
this this is the million random digits
doesn't mean B million unique random
digits okay now so that was that ideas
for any kind of special video for
million subscribers I would the other
thing that's on my mind related to that
was it oh yes I'll bring this up in the
discord and maybe um I am working on
training a machine learning model to
generate text based on all of the
captions of all of my videos ever and I
could use some help with that so but
that all that I'll bring up in the
discord row that's a separate thing
alright numberphile showed that 39
digits of pi would calculate the
circumference of the known universe to
the width of a hydrogen atom whoa
whoa okay
that's intense oh my goodness
Simon Says Simon Says that is
calculating the rate that I'm getting
subscribers and estimating that this
might actually happen on pi day ah
well can you slow down please I'm not
ready
April first I think is a much more
appropriate day for me than pi day said
that last week okay so I think I better
get started it's 10 o'clock half an hour
should really be my limit of shenanigans
let me go to the web editor of p5 oh
wait hey where's my what's going on here
here we go
look at this huh isn't Ashley wonderful
it got me logged into the coding drain
editor and I have no idea what my
password is it doesn't matter cuz I'm
using
okay hmm 36 I think is the number I tend
to use let me go to where I left off
last mmm whoa what is going on here oh
by the way this is a little this is kind
of an aside and maybe I shouldn't be
showing this but let's see if this works
I was helping a colleague who's teaching
a class about animation and this is like
an animation I think made does it made
an illustrator knowing After Effects but
using a library called using a library
called la tjs and these are some like
Lodi and p5 examples actually don't know
what I'm talking about but I helped de
minimus but it's cool because like the
whole animation is all just in this big
like JSON file and then I have p5 like
playing it back which is kind of cool
alright but that's I someday I would
like to make some videos about this with
alone who I worked on this example with
ok coming back to opening my sketches
the one that I want to get is this here
we go so this is where I left off this
is the last we last left off all our
rights we miss Adam or vias code we
don't like the browser-based editor too
bad no no I get it I get it
thank you for your feedback in your
comment it's important for me to use
this editor because it is a tool that
I'm feel very invested in in helping it
grow and for it being something that is
a really friendly easy place for people
to start to learn coding so when I do
certain projects that really don't fit
well with the web editor I certainly
will do things outside of it but I do
feel like it is a useful tool for me to
demonstrate the basic nature of code
examples
okay hello Argentina people of Argentina
[Music]
okay all right I think I'm trying I just
trying to figure out where I want to
kind of begin with this
all right I am going to actually go for
it whoops no I don't want to download
this I'm gonna go further back
friction forces 1 I think this is yeah
yeah this is where I'm gonna this is the
example I'm gonna build on it okay
I really am having trouble because I
don't have peripheral vision so to see
the screen over here to turn all the way
to the side okay I'm gonna need to start
all my recording things so let me do
that actually now start recording let me
go here and set the multi quarter to go
um one thing I also want to mention is
I've had a little bit of audio
interference
I'm noticed it must not be significant
because nobody is ever says anything to
bring the live stream or at least I
don't catch it if you are if you're
noticing like a little almost like and
you know the the sits just like a sort
of like a high-pitched hum that sort of
like slowly fades in and fades out if
you're hearing that could you let me
know at any point and I'm just trying to
get the various chat things back up here
is there we go the YouTube chat back up
you can see that Oh Simon is giving me
some excellent suggestions about
additional things I could do you know
I've got to move on to chapter 3 but I I
hear you read the entire book online for
free how nice okay and then I want to go
to where am I
forces holding chapter 2 boy this is
going very slowly and
here we go okay so this is what I'm
going to be doing today I am going to go
through this particular scenario and
example I need a minute to pull myself
together here and by the way oh I don't
want to show this diagram because this
diagram is absolutely incorrect there's
a major flaw in this diagram I think I
can't remember if I fixed it or not and
just not on the website but this are
needs to be the distance between the
Centers of the bodies not the edges of
the bodies so I hate to show this I mean
one option is could replace it later
so maybe much yeah what we're gonna do
today is I'm gonna leave this flawed
diagram up and then I will I fix it in
Illustrator and we'll just like replace
that in post even if the recording
system isn't working we don't have the
separate green stuff we can I'm pretty
sure like overlaying a diagram should be
possible although I'm gonna like point
to it and stuff like that so that's
gonna really mess us up but whatever
we're gonna try our best we're gonna
hope for the best everybody that is an
absolute mistake alright so if I'm
making a brief list I'm gonna does this
overhead thing working know what
happened my overhead camera so sad
that's weird
oh well I am going to let me make a list
so the first thing I'm gonna do is just
do attraction and then I'm gonna I think
in the same video I can make an array
making notes to myself here you know
what usually I type these out let me do
that so you can see it right because
actually I have it here
right uh okay here we go oh right so
I've done all these I already have these
nodes all right so this is done so
gravitational attraction plus array I
think I could do that in one will file
might change that I think that can be in
one then I'm going to do repulsion plus
like a kind of group behavior so instead
of there being separate attractors a
separate attractor and movers or bodies
whatever I want to call them particles
I'm gonna have them interact with each
other and then I'll add and I think this
could I think this could all be in one
so I think hopefully this will be two
videos right do the implement the basic
gravitational attraction then I just
switch it to repulsion and show I could
make it a group behavior and a wall
force and then I also have I should look
like some of this is a little bit
redundant content because last year I
did a traction coding challenge couldn't
challenge fifty-six I guess that's more
than though that's what we go oh
are you insane have I really been doing
this for this long that it felt like oh
that was just last year that was three
years ago that I did the attraction and
repulsion coding challenge just look at
the code did I I'm hoping that I was
using es6 classes at the time I was or I
changed it whoa all right okay so then
there's also this so I'm gonna refer to
this coding challenge and also include
it in the playlist and are noting the
chat is and my minds are exactly aligned
here Arn don't forget to mention your
coding challenge on attraction repulsion
okay so yeah so you know a few years ago
I didn't feel like I had time to redo
the full nature of code tutorial series
and so I
picked and choose little things and did
them as coding challenges gym anyway
makes more sense because I kind of make
one video that has a whole lot of
concepts all in it but this year I'm
doing it differently and as soon as I do
this I can no longer see because this is
the reading part distance reading
distance whoa I'm dizzy dizzy okay so
that's there
this is Jose's playlist and I'd
mentioned pi day anybody anybody file
any issues money to pi day ideas okay
and then Here I am and then Here I am
alright okay let me just
actually you know what I'm gonna do this
get rid of this interest thing oh boy
boy duplicate duplicate duplicate oh did
I mess it up hold on everybody let me
just I might have messed up that other
example and if I did I just want to
check real quick I think I did oh no I
left I might have like changed something
but oh yeah okay so this doesn't need to
be in there and mover is fine okay great
that's fine I'm here get rid of the
edges function and oh I'd if I also want
mass hold on I don't need edges I don't
need this you'll see but I also want to
get the idea of mass back in here which
I implemented in the previous one this
stuff would be nice if I did this in
advance so apologies a drag so what I
did in the previous one is added mass
hold on and then I calculated the radius
based on the mass so that's gonna go in
here and it's gonna take a third
argument and
also / mass and then add that and then
what else what else what else I think
and then I just need to give it a mass
here like five okay great all right
I love the Wesley Crusher reference in
the chat right now by the way all right
Adrian thank you for your new membership
I winced identity I happened to see your
message to the YouTube chat but pi day
suggestions if you want me to see them
the discord or the github repo is the
best place all right but please talk
amongst yourself about all sorts of pi
day ideas in the chat
I don't need this anymore all right here
we go is there are you serious oh this
is the worst okay the worst this is the
terrible thing that I have discovered on
the internet today that when I mean it's
mic no I'm not signed in hmm
when you search gravitational attraction
this image comes up just from my book
would you read it would be great bonanza
mistake in it oh look at this what a
coincidence
so by the way my the book is Creative
Commons non-commercial and Khan Academy
hugely correct diagram also has a
basically AB duplicated version with a
bunch of changes of the nature of code
book hopefully that I'm credited on here
but I think that I am Shh
but I'm looking for yeah this is what I
want to look for yeah here we go
all right I have such trouble getting
started but it is time for me to get
started
got to get some stuff done today not
looking at my email if I wanted to I
could just pull pick up my phone I have
progressive lenses so I can see it
really well and I could see if I have
any important messages but what could be
more important than what happens we know
nothing but the phone is going further
away I see it out of the corner of my
eye it's going over here I'm taking this
coding training notebook I'm taking the
phone
putting the notebook on top of the phone
and it's going over there
all right
and we're gonna start having trouble
where does some encouragement please
little by the time started by the time
you hear me say that's never mind
stretch everybody stretch if you're
watching and you can whatever works best
for you to like move any parts of your
body that you can move stretch oh so
Raul says just heard the noise hearing
the chirp what can I do about that
all right let me I have a suspicion that
maybe where this receiver is placed so I
have an idea so thank you for telling me
that you heard the chirp and now I'm
hoping I moved some wires around hold on
there's one other wire that I should
maybe move that could be having like
some interference okay so hopefully
that's going to do the trick I think you
you need the CJ timer I definitely do
happens when I do certain poses Oh
could it be I don't have any like I
don't have any other electronic devices
in my pocket and could it be the zipper
or something this is the mic
well alright alright everybody listen
listen standing still talking talking
talking talking does it happen
I'll do anything to not have to do like
coding tutorial
can you tell okay oh it's ten third all
right this is this is bad start all
right
hello and welcome to another I mean now
what he wants to look if they're
watching the secrets and I just keep
thinking welcome to but I don't know
what else to say
all right no I don't like starting with
that way either it is time for Newton's
law of universal gravitation so this is
the final example that I will be
demonstrating as part of chapter two
although the concept of forces and how
they are applied permeate throughout the
rest of the video that I intend to make
but I'm gonna wrap up this chapter by
looking at the equation for universal
gravitation that looks exactly like this
and trying to see can I take this
equation and implement it in a p5.js
sketch okay so that's good that's the
only one I wanted to say at the
beginning so much but I'm we're gonna
sort of like hope we can fix this we'll
see well I can always come back and
rerecord or something okay
let me just see here
here's the same formula with a diagram
in the nature of codebook itself so the
idea of this law is that every body
every particle every thing in the
universe attracts every other thing with
the force that's proportional to the
masses of those bodies and inversely
proportional to how far apart they are
so the farther apart they are the weaker
the force the closer they are the
stronger the force I did something very
much like this in the first example as
part of this series where I had done
actually look let me actually put this
here
all right
oh it's my watch
is my watch doing it okay that's easy I
don't need to wear this silly overpriced
Pisa unka exercise tracking surveillance
couch or okay look I do some free iPhone
and watch your God all right
so I know I don't think it's worth me
was it really bad and is it really bad
that I need to go back and redo the
intro or was it fine
like the glitchyness audio it's going to
end up in the edited version of this but
if it's just like a little minor hum big
deal did it happen again all right I'm
gonna just keep going
turn it again oh well what could it be I
wonder I guess I could change the it is
it just the Bell fine good all right all
right I'm gonna I'm gonna I'm gonna keep
going
in the first in the first example in
this chapter I did something very
similar to this idea of the law of
attraction
I created a vector that points from the
mover object to the mouse and then made
that vector the acceleration of the
mover object itself and it appears if if
this body like orbiting the mouse itself
I got it so there is sort of a problem
with me keeping my eye on the chat is
it's very distracting and I lose my
momentum so I'm gonna just take a break
from looking at the chat and I'm gonna
I'm gonna move I'm gonna plow forward
this cuz I shouldn't keep stopping and
starting hey what's going on here
I did something in the first example on
this in the series very similar where I
took a mover object and created a vector
that pointed from that mover object to
the mouse itself and set that vector as
the acceleration of the object so this
was like attraction but I wasn't
thinking about mass and I wasn't
thinking about distance let me try to
diagram what it is that I want to do I
want to have a new object that's called
an attractor so I'm not actually going
to at this moment in I just I realized
something
let me diagram what I want to do in this
video so I'm gonna simplify things and
have this concept of an attractor object
so the attractor object isn't a real
body in the universe it's a fixed entity
that does it that that attracts things
to it but it cannot move and it cannot
experience forces itself then I'm going
to have the mover object with some given
velocity and the mover object the
attractor is basically the mouse from
the previously but the mover object is
going to experience a force a
gravitational force that pulls it to the
attractor and that force which is a
vector is going to be equal to the mass
of one object times the mass of the
other object divided by the distance
squared and I put this in the wrong
order but also times G which is the
universal gravitational constant
now there's a very real number that is
this value in the universe as we know it
but for us in our fake p5 or I don't
want to say fake I'm say pretend but for
us in our in our pretend p5 canvas over
this word ok I understand what I'm doing
now but for us in our pretend p5 canvas
if I draw like a box around this G is
just a way for us to kind of like tune
the the world to have stronger
gravitational attraction or weaker
attraction forces and in a way I could
think of this G as a property of the
attractor itself may be different
attractors have different constants
although to some extent that is taken
care of by the mass but I have
everything that I want I can make up
so I need everything that's in this
formula I need to figure out where is it
here so the mass of one object well
would be the mass of this mover object
the mass of the other object would be
the mass of the attractor so to some
extent the mass and gee I could conflate
these into one constant but I'll keep an
exception for now distance is the
distance between the Centers of both
objects so remember when I'm calculating
a force I need two things I need
direction and I need magnitude so this
is really all of these numbers are
talking about the magnitude how strong
is that force how long is this arrow
that I'm drawing here the direction is
just a vector that points from the
object being attracted to the attractor
and so that I can get there's a bunch of
times now with subtraction so the sum
function for subtraction I can take the
position of the attractor minus the
position of the mover and that gives me
a vector that points this way set its
magnitude to the result of this formula
and voila
I have gravitational attraction okay
so coming back to this example I am
going to now get rid of this
acceleration calculation and when I run
the sketch I should just see this mover
not moving at all
and in the main tap sorry and in the
main JavaScript file where I have set up
a draw I want to add an attractor so
I'll create an attractor that also gets
in X Y position and a mass
I'll say a tractor
attracts mover and a tractor dot show
now I might have just confused to you
for a second there because you might be
thinking wait did I miss something did
you write in a tractor class and is this
just gonna work right now definitely not
like when I run this is gonna be like I
have no idea what that is so this is the
way that I work sometimes it's a little
bit of flawed me making this tutorial
video because this is probably an
example that I've written many many
times so I had it just sort of right in
my mind at the ready but sometimes it
can be helpful to sort of sketch out
what did how it is you imagine writing
the code to operate an object before
writing the class because now I have the
instructions for what it is I need to
write I need to make a class called
attractor the constructor takes three
arguments it needs to have a show
function and it also needs to have an
attraction that receives a mover object
so all of these things are now at things
that I can write into the attractor
class I've already created another
JavaScript file attractor j/s which is
empty so I'll put class attractor in
there then write the constructor which
if you remember required three arguments
an X Y and amass the X while used for
position the ammo use for math let me
write a show function just to draw it as
a circle
I'm now realizing I should calculate a
radius based on mass the same way that I
did in the previous examples with the
mover so I'm just gonna grab this code
which takes the mass takes the square
root multiplies by 10 I'll use the same
convention and then so let's leave out
the attract function for a moment
comment that out move the mover to like
a little higher up in the canvas run it
and what do I have now tractors not fine
oh I can never seem to remember to add
the script tag when I have a new
javascript file and here we go alright
now I see the attractor and the mover so
the net would have been chat
now I see the attractor guess I'm
looking at the chest now I'm seeing both
the mover object and the attractor
object the next step is just to actually
write a function in the attractor object
that we're that loud noise
you have a vector on the left side the
feedback was bad when you were at the
white hold on time after second
the feedback was bad when you're at the
white board might be from the mic cable
moving so what might Cable moving do you
mean just like this
and then you have a vector on the left
side and a scaler on the right side oh
yes yes
okay people are telling me that the
noise is annoying I really I don't think
it's an OBS problem because I think it's
also in the audio track of the I have
another system that records a backup of
everything zipper gets close to the mic
I mean that doesn't really make sense
right I mean that's gonna make have
noise but I mean I've done streams
without zippers before oh you don't see
me right now
bum-bum-bum-bum-bum what do I do about
this
I don't think it's a it's mostly when my
hand is near the mic my ring is hand
so I'm just I'm taking a pause for a
second to figure out if I can sort this
out at all I'm trying to think
charger what charger though
it's interference it's a mugging well
yeah it's fine you know I guess just let
me know if it was particularly bad the
game being too high yeah I have that
down I don't think it's feedback though
but one thing I can do is just turn off
I do let me just let me just check one
thing for a second okay
it was really bad just now huh people
are telling my phone but it's my phone
so far away I'm just wondering if I turn
the audio monitoring off
what's weird I it's interesting because
I'm not hearing it the way I think I
just heard it yeah I hear it oh yeah I
hear it okay
playing with the receiver
oh yeah okay that is really weird I was
able to get it to move such as the
coincidence
yes you were watching a person and move
around trying to figure out if it was a
way to trigger the audio interference
all right I have an idea I have a I have
another laughs Mike let me just try the
other laugh Mike which I should done a
million years ago so I'm muting myself
for a minute
[Music]
they test one two three all right I
think this mic is working and it doesn't
look like it's crazy left so the
question is is there interference this
is better or worse the same test one two
huh I don't hear it too loud
okay well that's easy to fix
okay that should have turned it down a
tiny bit and hopefully the interference
will be gone
we'll find out okay so if if you hear
any audio issues let me know but I'm
gonna assume that hopefully fixed it
Wow it's 10:40 already I'm gonna be
taking a break shortly
great I I actually have a third idea of
something I could do if it's really bad
because I have new wireless headphones
and I could wear them and the mic wall
it's actually pretty good
so but anyway well everybody saying the
mic is better I there's exactly the same
mics it's just two of them all right
okay that was a burp did you pick that
up clearly easy to forget you're live
streaming and the body just does what
the body wants to do
[Music]
alright I'm gonna move on
okay so okay all right all right all
right now you're catching up to me in
real time I'm gonna move on you know
while I took this break just give me a
second to check
I'm just curious now to see how that
recording is going okay now if I could
only remember where I left off but here
we go
now I can see both the mover which isn't
moving at all which is what it should be
doing and the attractor just as a circle
there's a better pic suggestion in the
share channel could you repost it here
because I not easy for me to check other
channels cuz I'm gonna repost it in the
live chat supporter group
I the problem is you're gonna it's gonna
be a while so you hear me say that okay
get a move on
how's everybody doing today okay we're
really feeling okay as things in the
world are spiraling everybody take a
deep breath relax hug your neighbor a
friend all right I'm gonna move on
I'm waiting for it to appear but I don't
think it's going to
oh there it is oh thank you perfect yes
that's exactly what I intend to do yes
that's a great diagram whoever made that
thank you how do I pull that up here
hold on a sec
hey can someone make money all right I'm
moving on thank you for that diagram but
I it's I need a better system for all
sorts of things move on okay the account
that I hopes there's an account that I
log into discord on this laptop that's
not in the supporter Channel I could
have checked share Dirk Harrell six
eight seven okay all right
everybody I'm moving on
okay now I have the mover not yet moving
because no force has been activated and
the attractor just in the canvas so the
next step is for me to write this
attract function and implement the
formula but before I do so let me
address something why did I choose to
say a tractor dot attract mover I could
have said a number of other things I
could have said
I could have choked I could have caught
up I can't get the momentum back I could
have called a function it's gotta be
okay everybody here we go I could have
called a function on mover instead of a
tractor or I could have written a new
function that takes the two arguments
the mover and a tractor or I could just
work out the code in here so I'm making
a somewhat arbitrary choice but to me it
feels conceptually consistent to have
the attractor object itself have the
functionality to create a force that
attracts the mover object but you know
if you want to try to redo it and
reorganize your code in another way I
would really encourage you to do that
and share it with me
returning to the diagram for a second
you know I did make a sort of slight
mistake here which I am calculating a
force and I talked about wanting to
calculate a direction and a magnitude
but this whole why whoa what just
happened
all right everyone don't worry I have a
solution for this
apply force to get momentum yeah now I
didn't make a sort of small error here
or inconsistency where is that I'm
saying I'm calculating a vector but all
of the variables and aspects of the
formula that I'm working with here or
just calculating a scalar value the
magnitude of that vector so let me be a
little bit more clear about this diagram
if I have two objects each with a mass
and I'm calling this vector or this
if I have these two bodies each with a
mass Matt this one being the attractor
but that doesn't really matter so much
and I think of this vector pointing from
object 1 to object - as a vector R then
the the distance is really the magnitude
of that vector squared and then the
direction is the unit vector R which I
don't really have a lot of room here but
I could say
which I could write as our with the hat
on it so now this formula is more
accurate and all I need to do is
calculate both in my code is calculate
both this unit vector and this equation
put them together and apply that force
and I'm going to do all of this in a new
function called attract that's part of
the attractor
so let me first get this vector R I'll
call it direction and it is the mover
sorry it is this position - the movers
position we need to say subtract the
distance is the magnitude of that vector
and actually I'm going to want distance
squared so let's make this distance
square it is magnitude squared
I'm gonna make up just for right now a
universal gravitational constant of one
so I could really just ignore it but
let's keep the variable in there and
just set it equal to one and I'll and
I'm gonna use the word strength to
calculate the magnitude of that force
which is this dot mass times mover mass
I'm gonna give myself more room here
divided by distance squared and also G
times that so this right here is exactly
the same formula that I have right over
here and I just want to take this vector
R and set its magnitude to the result of
this
so and just to be consistent I'm
actually going to rename this from
direction to force because ultimately
I'm going to use this very lips I'm
going to use this variable to be the
force and then I'll say force set
magnitude to that strength and then
mover dot apply force force clean this
up for a minute and we can see I have
all the steps here get a vector that
points from the mover to the position
remover to the attractor
get a vector that points from the mover
to the attractor calculate all of the
elements to get the magnitude of that
vector put it in this variable strength
and then set the magnitude of that
vector to strength and apply the force I
don't know let's run this this what kind
of work I think so I'm not seeing
anything okay well one thing would be to
actually call the function attract hmm
stength is not defined alright that must
be a mistake that you've all noticed
strength with an R
[Music]
oh oh wait is moving just ever so
slightly and snowy this is where having
G can really come in handy let's make G
5 and let's make G 50 there we go so I
can scale the force relative to that
universal gravitational constant but
there's actually something else going on
here that I think that I would like to
fudge
while I really would love to stay so
true to this formula you are a wonderful
formula and I want to stay true to that
formula a little bit of wiggle room here
because this is this made-up p5 world
it's pixels and there's a lot of aspects
to what I feeling that I want to create
and how it's actually going to behave
with this literal formula and one of the
like a big element here that's playing a
role here is this distance squared do
you think about it the amount of pixels
apart that these could be could very
easily be you know 200 pixels and if
they're 200 pixels apart that's going to
be um you know dividing by 40,000 which
is going to make the strength of the
force very very very small so I could
increase the mass of everything I could
increase G but ultimately something that
I might just do is kind of constrain the
distance that I'm using in the
calculation to a limit so I'm always
going to even if there it's farther than
50 pixels away maybe just cat that at 50
on the other hand when they're really
really close they could actually be in
the same spot in which case the distance
would be zero which doesn't make any
sense in actual reality but could happen
here or even if their distance is
something like 0.001 pixels apart if I
were to square this to have Justin
squared and then divide by it I'm gonna
make that strength so strong that things
could kind of spiral out of control so
this isn't it you could really play with
and sort of like try a lot of different
scenarios but for me right now I'm going
to say that whatever that distance is I
want to constrain its range when I go
and calculate the forces magnitude
to do that I'm just going to use the p5
constrain function and now I am getting
the magnitude squared which I don't love
so I'm going to constrain it's between
25 which is 5 squared and 50 squared
which is 25 hundred twenty-five hundred
people and 50 squared which is 25
hundred let's see what happens now
I'm just like sitting here all right you
know this is like this range is you want
to play with it something you know you
there's no science to what I'm doing
here if it's pitch lately because I've
like violating sexual rules of science
but this is something that you might
these are parameters that you may want
to play with based on what it is you're
you really want your system to do in
this case what I want to see is it
actually have it in this case I think I
this would be a better demonstration if
I give that mover an initial velocity so
I am going to do that I'll give it a
random one just so we can see different
things
and it has a bit more of the quality now
of a body a body orbiting this attractor
it's moving so slow did I have a limit
in here No
one thing that might actually make sense
here is to get rid of this multiplier of
mass and actually just give the objects
bigger mass so I'm gonna give the
objects a mass of 50 each
yikes
well I guess I let's give them
and then let me just multiply it by two
oops
where did I mess up
all right this is what I was kind of
looking to see and actually it would be
interesting to trace this one thing
visually that I think might be
interesting to do is trace the pattern
over that I can give the background
quite a bit of Alpha
and we can kind of see the path that
it's going in
and then even better let me make this an
array
so now I'm making hope and I'm gonna add
this in here now I'm making 10 mover
objects oh and I want to give them each
at a random location with a random mass
so I'm gonna just put 10 out into the
canvas
I'll make the attractor a little bit
bigger with mass and then I have to loop
through them all in draw
let me give a bit more pixel space to
work with here and let's see what this
looks like whoa what happened to the
mover oh no it's okay let me put the
mover in the middle and I think I want
to draw the mover a different color to
make it more obvious
and
[Music]
I'm gonna make this constraint of the
distance even smaller so it's still
weighted according to distance but it
won't be as extreme and let's see what
this takes a look look like so now again
have what have I made here I don't
really know but what I'm showing you and
actually I want there sorry I want the
initial velocities to be a bit stronger
I think we'll also make this
demonstration a little bit nicer
there we go so this is what I was more
hoping to see so what I'm looking to do
here is create a bunch of mover objects
that are orbiting and swirling around
this one attractor and you could imagine
oh what's something interesting that I
could do here is that I could actually
just right now in just a very quick
moment I could say hey you know what the
attractors position now if mouse is
pressed
if the mouse is pressed move the
attractor to where the mouse is
I'm not sure what that really added but
I'm getting somewhere I'm getting a sort
of swirling set of bodies all
experiencing gravitational attraction to
this one attractor in the center the
upper limit is too low I think
yeah that's all coming next what Armour
and Simon are both asking about will
shouldn't these objects be attracting
each other and also attracting the
attractor that's coming next I think you
might have confused the naming of mover
and attractor where
what did I say I was going to do next
repulsion group behavior in a wall force
okay
reduce the trails yeah
let me just take out the trails
completely
and removing the trail this is what I
have
oh I confused a tractor and mover in my
verbal explanation a few times while
setting the color and mouse position oh
I should put the mover in the center all
right let me we'll dub it's over later I
should put the attractor in the center I
should put the attractor in the center
is that how I said it I should put the
attractor in the center and I should put
the attractor in the center right give
it some extra audio
this example might actually look a
little familiar to you I've got three
years ago I did a coding challenge
called attraction repulsion where I
essentially built exactly this but I had
multiple attractor objects and I also
was took that attraction formula and
multiplied it by negative one to reverse
the direction to make it a repulsion
force so those are things that I would
suggest trying like what would it mean
for you to add multiple attractors maybe
every time I click the mouse a new
attractor is placed in here how could
you adjust this with repulsion but what
I want to do in the next video is make a
couple changes to this one is I want to
show you repulsion so I'll do that but I
really there's a big flaw here in terms
of how the universe works I mean there's
there's no flaw in yeah right you need
to see that but I just read it to the
wall over there because I'm frustrating
myself so this is what it looks like
without the trails and you can see I
kind of like wrapped up this example
that I wanted to make and there's a lot
that you could play with here
incidentally this might look very
familiar to you about three years ago I
did a coding challenge called attraction
and repulsion where I made exactly this
the difference was I took it a bit
further and this is something you might
think about trying on your own now with
this as a basis for your example is what
if I were to click the mouse and add
multiple attractors what if some of
those weren't actually attractors at all
but repellers how would I make a
repulsion force just multiply by
negative 1 to reverse the direction so
I'm gonna actually do some of that in a
follow-up which will be the next video
in your playlist here but what I want to
look at more closely though that neither
of not neither this example or that
previous coding challenge addressed is
what if I want every mover object to
exert a force on every other mover
object what if going back to this
original diagram right
where I'm
what if going back to Newton's law of
universal attraction every particle
attracts every other particle so really
there should be a force all of these
should be attracting every other one and
what does the system look like if I have
a lot of bodies floating around all
mutually attracting each other so that's
what I'm going to focus on in the next
video it's a bit of an introduction to a
group behavior I might need like a
nested loop we'll see
and that'll bettle really wrap up this
chapter - okay all right I'm gonna take
a short break right now and I will come
back and finish this off I'm glad we
have the audio thing worked out how are
there's a lot of people watching this
right now which is always mind-blowing
to me I need to get some like water but
before I take my short break
let me a really thank the sponsor of
today's livestream - Layne dot - Layne
which you can go to at - link calm so
what do I say I have a little story to
tell go back so I was talking to back to
my son again who's now a programming in
scratch my daughter is also program at
scratch but she's a lot younger so a
little bit a little bit harder but she's
just doing a great job
but I was he has an account that's part
of his school and I was asking him oh
what's you know like I wanted to see
what he was doing I was like oh maybe
I'll just log into your account later
like do you know your password and he
was like yeah I know my past was like
well how did you get a password he's
like it assigned to you did you make one
up there's like oh well I just keep my
password in a file on my computer on the
computer that he uses for school at
school and as well and I thought to
myself oh my goodness I am NOT teaching
my children proper password management
and if you're doing things like all of
your passwords are on just like a plain
text file sitting on your computer or
you have the same password across
everything you're using this is not good
you know there's lots of things you I
that I like to attempt to do
my best to sort of like protect accounts
and not use and and and so one of the
things that I can't live without really
is a password manager and what a
password manager does dashlane being a
great a service password management
service is that it allows you to store
to have different passwords everywhere
everywhere
don't don't hurt yourself and and have
them all stored in a single place in a
secure fashion so and then you know
frankly it just makes life like super
convenient when I'm trying to order a
very expensive copy of a million random
number book a regional print on eBay
which is what you're seeing me do right
now only I can't because I can't find it
can I please find it on eBay somebody
help me so I could use my dashlane to
quickly enter in all my information to
buy that expensive random numbers book
what else do I want to tell you about
dashlane so there's a few things that
are important so one thing is - lean is
different than other options that you
might have already for automatic logins
solutions like keychain and krob they
lock you into a single system so your
passwords and info are trapped in one
place sign-on solutions like login with
Facebook and misuse your data because
they make money from collecting it
selling it and using it to annoy you
with ads so dashlane ever has access to
your personal data and won't trick you
into subscribing there's no credit card
required at signup not even - Lane can
see your data and it's always an ad-free
product so really I mean for me this
ability like fill in forms fast with
one-click logins and autofill you saw me
do that with the people I've web editor
is just so incredibly convenient it's so
nice to have something that I can use
across a Mac Mac Windows a mobile device
whether it's Android or iPhone and
really sort of like respond easily to
breaches and hacks with personalized
security alerts so if you're interested
in giving dashlane a try you can go to -
Lane comm slash coding train if you sign
up through that link it lets them know
you found it from the coding train thank
you very much and you'll get 30 days of
free premium subscription to all of the
features I mean and then if you also if
you choose to purchase it after those 30
days you'll get a 10% off the premium
so I thank you again thank you - Josh
lien for being a sponsor it really helps
make all the stuff that I'm doing
possible and I am going to take a break
and come back to this coding example so
I think it'll probably be about five
minutes I'm just kind of like getting
all my various windows back up here and
um a few I've benefited I'm gonna do the
next part of this I think I'm hope I
wanted to get to chapter 3 today we'll
see if that happens I've got until about
noon so I'll have when I come back in
five minutes all about 40 minutes left
till like plow through some more
examples and stuff thank you for
watching and I will see you in about
five minutes
[Music]
everyone eat about one more minute so
I'm going to set the music back a little
bit
[Music]
okay sorry for the delay of praying
alright I've got some water thank you -
- Lane as the Kotick train sponsor and
also water which keeps me hydrated
all right what is next what is next
spill the water on the computer
everything's gonna be fine like that up
and who okay so now I can move this here
and this is the last video tutorial I am
going to make as part of chapter 2 and I
guess chapter three will probably have
to wait until another day I mean I could
there might be enough time after I'm
done with this next demonstration for me
to continue into chapter 3 but I sort of
feel like I mean if I'm gonna do it
would be so much nicer I think in terms
of keeping everything together and
having a nice flow to the videos for me
to do a session that's dedicated to
chapter 3 as opposed to like starting it
at the tail end of one and then coming
back a week later so you know if I have
a little extra time I'll answer some
questions or talk about something else
but I will be here until noon
either way hmm okay now we're talking
yeah I could just sort of dance around
and act ridiculous at a minimum for like
the last ten minutes all right
I'm gonna save this and duplicate it
all right and
ready to go okay I don't know why not
let's let's let's keep going with this
I actually really like this example I am
back with one more demonstration and
really I this finished
wha-wha-wha wha-wha-wha wha-wha-wha
wha-wha-wha wha-wha-wha wha-wha-wha-wha
one more one more video here in chapter
2 I want to just do a few more things
with this example so the previous
example I built this sketch where
there's a single attractor at the center
of the canvas and all these other mover
draw objects are experiencing a
gravitational force pulling them towards
that attractor and all of that happens
in this function called attract where I
am writing code to realize this
particular formula formula for the
universal law of attraction but this is
not really how the universe works in the
sense that there aren't separate
attractor entities and separate mover
entities so let me take this a step
further and have every one of these
mover objects I really want to just call
them particles but I'm gonna wait until
chapter 4 to call things particles but
every one of these mover objects
attracts every other mover object and
I'm gonna get rid of the attractor
no more attractor concept whatsoever
yeah
before I get rid of the attractor but
before I do that I let me save this code
because I'm gonna want to use this code
so I'm gonna take this code and put it
actually just in the mover object itself
then I'm going to delete this file
get rid of the reference in index.html
get rid of the attractor here comment
this out and get rid of all this nope
let's run this sketch and see what
happens
great all of the mover objects are
moving with their initial velocity but
there's no other forces
now I have a loop here that says for
every mover inside of the movers array
update and show but what do I also want
to do for every mover in the movers
array each one of those movers is in a
tractor to attract all the other movers
so inside of this array while I'm
looping through all the movers I want to
check every other mover so I can write
another loop inside here for let I'm
gonna call it other of movers
other dot attract mover or mover dot
attract other I don't know both would
really be the same I think mover dot
attract other makes a little more sense
update the move or show the mover and
that mover then should attract all the
other movers there's a big problem with
what I've done here but I'm just curious
what happens if I run it whoa oh cool it
kind of worked what a nice coincidence
I'm surprised didn't get any error but
there is a there's an issue Emma it
nicely just sort of like bypassed this
issue and I got no errors or nothing
really crazy happened but this
particular loop is going through all of
the elements of the array oh no so is
this one so for every element of the
array go through every element of the
array I'm saying the same thing a lot I
know
and so it's technically possible that
the mover at some point is going to
attempt to attract itself because this
given mover will then appear during this
loop as well so I want to avoid that and
something that I can do is actually
check to see if the two objects are
equal which is sort of a weird thing am
i checking to see what am i checking
exactly so
this is a little bit of an aside but
what's actually stored in a particular
variable and we're talking about an
object is so if I'm talking about a
specific move or object what's stored in
that variable is the memory address
where all the data for that object is
stored so it's kind of like a pointer
so we can think of this variable as
storing a reference a pointer to some
place in the computer's memory where all
of the data for that object is stored so
if it's stored in an array this mover of
the movers array that pointer is moving
around and pointing to all the different
objects and maybe they're stored
continuously etc etc so at some point
other will actually be pointing to the
same data the same memory address will
be in both of these variables so if I
check if they're equal it's actually
checking if they're both pointing to the
same area of memory which is different
than if I had something like Val equals
5 you know Val 2 equals 6 and I'm trying
to say is Val equal to Val - with a
primitive value like a number it's
actually checking to see if the actual
things stored in memory is equal the
data is equal here we're just checking
to see am I looking at the same object
that was kind of a long-winded
explanation don't know if we need it in
the video but and maybe that didn't make
any sense so I can check right here now
as long as other is not equal to mover
then the mover can attract the other and
the result visually doesn't really look
any different but it is but the result
visually I don't not really seeing
anything majorly different here but I've
now protected the system from having
that from from a given object attracting
itself which I don't want to happen
Alvar says I can't believe you explained
pointers faster than you explain static
functions well that's sort of true but I
don't know if I really explained
pointers they're just kind of like
glossed over it all right
I'm going to take this variable G
outside of the attract function it's a
nice to have this global variable that I
can use to just kind of scale the
strength of the attraction force across
the board we just lower this down to two
little little little less frantic
one thing you might notice is the system
is not very stable as all of these
objects are pulling towards each other
they're kind of as a group just moving
off and out of the canvas and it kind of
makes sense that that would happen but
what if what I want is to experience
this but have everything really stay
within the canvas but what if what I
want is to sort of experience this same
animation the same feeling that I've got
with this sketch but not have the stuff
just fly off and eventually disappear so
there's a few things you might be
thinking of that you could try I mean
one is I could have a lot mover or
tractor in the center that's always
attracting everything so that at a
certain point maybe a little bit
stronger I don't know if it needs to be
stronger or not that everything is kept
within the canvas I just realized I
might have a no-no I have that's fine
another option could be to go back and
get that edges function that I wrote so
every time one of these objects hits the
edge it's a hard edge and it reverses
its velocity bouncing back on that would
be interesting I'd be curious to see
what that looks like but I think this is
a nice opportunity for us to look at I
mean this is quite artificial what I'm
gonna introduce here but what if I just
created a force that is activated from
the edges of the canvas pointing inward
and the strength of that force is mapped
to how close a given mover object is to
that edge
so
to do that I'm going to reintroduce the
edges function
I'm trying to have not done this before
so I'm like thinking about I mean I've
done this with the steering behavior
stuff and let me just start with the
left edge so I'm gonna say the the
difference between of the exposition of
which is zero I'm actually just going to
look at the exposition of the object and
I'm gonna say the strength of this force
that I'm being introduced is a map
mapping that exposition which goes
anywhere from zero to with and of course
it could be a negative number but the
way I'm gonna do this is going to
account for that and when and and when
the distance is zero
I want that force to be really strong so
let's make the magnitude just five
arbitrarily and when it's when it's far
away I want it to be really weak I think
I should only activate this force if
it's within a certain distance let's not
worry about that right now let's see how
it goes and I'm gonna have it zero if
it's all the way on the other side and
the force itself is a vector that just
points to the right so I'm just gonna
make a force that points to the right
I'm going to do force set magnitude to
that strength and then I'm going to
apply the force so this is left edge
let's call the edges function and let's
see what happens when I run this well
you can see the whole system is kind of
fading off to the right because there's
that left edge force that's always in
action now let me do this again
whoa I don't know what just happened
there
and
so I'm gonna reuse all the same variable
names and there's probably a more
elegant way of doing this but I'm gonna
say right edge and DX equals the width
minus that position that's the
difference and that also can be the same
mapping would apply but the vector
should point the other way let's see
what happens now okay let's do the top
and the bottom
okay so I've built this out with all of
the edges and there's a lot of redundant
code here that could be reduced but
let's just see what happens
better right not perfect but the system
is staying kind of within the bounds of
the window now that the strength of
those gravitational forces are getting
bigger and bigger the accelerations are
building up I might want to put a cap on
the velocity of the movers also
something quite artificial that I'm
introducing here but I think this could
help
so let me limit the velocities to like
I'm just gonna I'm gonna give it a
pretty large number like ten whoa come
back that's weird
[Laughter]
so what's interesting is that
gravitational attraction force is so
strong when they get close that they get
kind of locked onto each other and you
know maybe this limit was sort of like
too strong or too harsh or maybe I want
to kind of tune in a different way and
go back to this attract function to
change the way that I'm doing this
constraint but I have another idea I
think would actually be interesting to
see a repulsion force
so let's actually just change this to a
repulsion force so I could rename this
function to repel which maybe would make
sense but ultimately really what I just
want to do is say force multiply
negative one and let's see what happens
oh my wall force is terrible I think
it's not really working hold on let's
take off the attraction from each other
yeah okay the wall force is working do I
have any typos in there it's not very
strong
you know lowering the gravitational
constant is something I could try also
one thing that I could really do to
improve this is this five in there is
really construe is really controlling
the strength of that wall force as it
approaches the edge so it would make
sense for me to store that like sort of
like max strength in a variable then I'm
gonna make that 20 just to make it much
much stronger right now
let's run this again
you know this feels tuned properly with
the way that I want that edge force
there's no attraction or repulsion
between them but the walls are keeping
them within the window itself let me
lower the gravitational constant down to
one and turn back on repulsion the
repulsion is just still much too strong
let me lower that even more but now I
don't really see them repelling each
other
honestly I think one of the issues here
is that
I think one of the issues here is that
force keeping them on that force keeping
them within the edges is so strong it's
overwhelming the attraction or repulsion
force and it's always on like I'm
mapping that force the X I'm mapping the
force from the edges in any direction
wherever it is so what might make more
sense is for me to check to see if it's
within right only if it's within like 25
pixels so maybe we can have like a
buffer which is 25 if it's within that
buffer then map the force according to
that buffer and then only apply it if
it's within if it's close to the edge
now let me do that for all the other
ones
whoops
so I have that check now in for left
right bottom and top I'm going to turn
off the attraction or repulsion in this
case and run the sketch again so nothing
is moving because no object was close
enough to the edge to experience the
force oh no actually no they're not
moving because I have an error strength
is not defined mover line 46 oh look at
this so actually this is kind of better
because I I had these now these
variables or local variables to the if
statements
run this again
so they're staying within the canvas and
that force is only activated if it's
within 25 pixels let's make that 50 then
let's make that force much stronger
because you know this is much more like
a bouncing ball sketch in a way because
that force only activates when they get
close to the edge and it's very very
very strong now I think that I could
have the repulsion back in and increase
its strength the repulsion is so strong
they're all trying to stay very far like
from the corners but not what I wanted
at all let's let's weaken the repulsion
let's go back and make this attraction
Oh
it's a mover train look at what an
interesting little weird thing that I
created what if the distance is within a
certain threshold they repel each other
otherwise they attract each other oh
that's an interesting thing I could try
I want to go back to just using the raw
distance not the distance squared which
i think is easier for me to kind of
think about so we'll make this between
10 and 50 and then we'll actually say
here distance times distance and then
I'm gonna say if distance is less than
what being constrained is equal is less
than 20 make it a repulsion force let's
see what happens now
so they're all attracted to each other
but then when they get close they kind
of repel interesting there you can see I
could play with this forever and ever
and I assume while you're watching this
you're like oh whatever you're doing is
so silly I have a much more creative and
interesting way to make this a dynamic
compelling beautiful artistic
visualization please go ahead and do
that and share it with me I would love
to see it there is something that I
should point out here which is that I am
NOT the warder of the movers is kind of
playing a role here in the sense that I
am updating their location and then
applying a bunch of forces and then
update in the next ones location then
applying all the forces if I want it to
be really much more exact about this I
would want all of the movers to
accumulate all their forces based on
their current position and then all
update together so it could actually
make sense for me to do that to have two
separate loops
one where I update and draw them all
then I apply a whole bunch of forces
based on those fixed positions and then
update them all together all at once
we'll see if this actually has any
different quality to it
another aspect of this is I'm not
considering anything I'm not considering
another aspect of this is I'm another
aspect of this what was I gonna say Oh
another aspect of this is I'm not
treating these as rigid bodies notice
how they can easily move over each other
I'm not worrying about actual collisions
here that would be a whole other complex
thing for me to work through and
implement and in many cases when I'm
doing collisions I end up using a
physics library and I have some videos
that are will appear in this playlist
about that using the library called
matter Jas but ultimately I think this
really wraps this up this wraps up
chapter 2 of the basic idea of looking
at the universal laws of motion Newton's
laws how those laws of motion can be
applied in code not in an accurate
perfect way but in a way that reflects
the sort of core ideas of them but is
easy to implement and runs kind of fast
and then what kinds of things do I need
to adjust your tweak or sort of fudge to
kind of keep to create the simulation or
visualization that goes with whatever
story or that I'm trying to tell with my
sketch and I don't really have a story
that I'm trying to tell other than I'm
trying to teach how this stuff works and
how you could apply it but I hope that
you have an idea or a story or a project
you're working on where this applies so
if you do share it with me
final link to the coding train comm page
where you can share your work in this
video's description you could also join
the coding train discord and share your
work that way and I look forward to
seeing you in chapter 3 where I will get
into
I hope you're excited I'm really excited
and I shouldn't have played that sound
effect I should play like a beautiful
sound effect like birds singing because
trigonometry it's our friend we'll be
there together enjoying trigonometry
together in the next video this one
really has to end now I'm just talking
way too much goodbye and see you soon on
the coding train oh that was like the
worst ending ever yes Lucas writing is
this an implementation of G equals m1
times m2 bubbeleh
so the divided by zero thing is
something I really should protect
against I should have a check here that
says if distance is as long as distance
is greater than zero go go forward and
multiply but I'm choosing to not bother
with that extra error check mostly
because it's just not gonna happen with
floating point math that these pixel
values are going to be exactly the same
and then I'm also constraining it Oh
actually it's never gonna happen because
I'm constraining it to between these two
values
so I'm actually protecting against that
here with this extra constraint that I'm
adding all right actually I thought I
was gonna have all this extra time which
I clearly do not because I only have
about ten minutes but ten minutes is
actually quite a bit of extra time and
maybe people have questions there's are
some other things I wanted to mention
maybe I should rerecord an aspect of
this feel like I was really fumbling
towards the end there but it is what it
is
questions oh there was a super chat from
Vito list thank you
I'll press my to chew button let's see
there's probably people who join now who
didn't who weren't here at the beginning
of the stream so let's think up let's
look at the pi day let's see if anybody
added any pi day issues no there's no
new ideas for pi day where are you my
people let's see what there is
previously whoops no no I want to look
at pi day ideas generating PI from
random numbers I think I did basically
that already o co-prime
oh yeah the stand-up Mass video okay
that's interesting so I haven't done
this one the co-prime thing I did the
thing the dart throwing one idea I like
this that's certainly a possible pilot
generator what if I trained a machine
learning model with the digits by the
generate PI that seems kind of silly a
good opportunity to talk about Co
Prime's literary nerds invented a
dialect known as pylus in which the
numbers of letters and successive words
match the digits of pi for example my
Keith wrote the book not awake entirely
in pilus now I fall a tired suburbian
and liquid under the trees okay this is
kind of Awesome ok pilot this is a this
I like I like this idea
thumbs up I'm gonna assign myself so
that is not at all in the wheelhouse of
things I was thinking about but it could
absolutely work pi day challenge
calculate million digits of pi yeah I
don't know how to do that I wrote some
code based on somebody else's code based
on an algorithm that was doing that
pi day challenge 3d monte-carlo
approximation of pi by dropping
raindrops into or outside a puddle
that's very similar to what I did
already I didn't do it in 3d a lot of
visual flair to it but that's that's an
interesting idea
oh wait I'm already at that one
visualize an infinite series I think I
need something more specific
I like the suggestion
[Music]
pi day challenge
Audio visualizer okay this I did with
Gaussian rather than a circle
this is interesting it's a little bit
similar to what I did previously I guess
I'm a little less interested in pie
approximation since I've done that
before although this is really an
interesting one to see thank you this is
a great example del squared this is
awesome um
a list of pi day challenges pi art
countdown to the next pi day oh I like
that
use pi any object you make use the line
function to manually draw the numbers of
pi some nice ideas this I did oh I
didn't use matter digest this is what I
did last year pi music PI rock concert
make a sheet of pi music this I really
do like the idea but here's the thing
when I when when I've done things where
I visualize the number the digits of pi
there's so much mystery and meaning in
those digits but ultimately they're the
distribution of them is really just like
a bit of a pseudo-random number
generator and I know there's more to it
than that but I'm I don't know would I
get anything melodic are meaningful by
assigning the digits of pi to note
values so that I think is a really
terrific idea that I would like to do it
maybe some of you who are musicians or
sound artists might have some specific
ideas of how I might implement this but
I'm going to keep this on my list who
ASCII art I know that violet has done
work with ASCII art yeah
this one especially whoa
so I a ski art with the digits of pi
that's an interesting idea
I'm not I feel like I need a little bit
more focus to this you could use PI's
decimal development consecutive digit to
represent the PI yeah I think I need
something that's sort of connecting to
connecting to the the sort of like
mathematical aspects of Pi themselves I
mean I'm making just like a PI is fun
all right pipe rot approximation day
which is uh 722 right July 22nd which is
22 so now I'll come back so if somebody
remind me to do this in July stem coding
project p5 just I have done so many PI
approximating staying this is this is
similar to what I did already
um spiral okay you had me at spiral ooh
no that's cool this is kind of fun
is there something about this that's
tied to the math of Pi probably in the
sense that you're I'm doing polar to
Cartesian coordinates old-school PI
demonstrations
I like old-school Oh
this is super interesting
this is actually highly relevant to
chapter three of nature of code so I'm
gonna consider this one rolling wheel
full of paint I like this idea a lot pie
is made of pie
yeah make a visual image of the
character pie made of lots of little pie
for you to make the larger character yet
so this I could sort of imagine this and
that's kind of in the ASCII art
territory draw a circle with pine
numbers this is a suggestion from Simon
Willie oh boy oh boy why are you so
these are these are definitely I could
consider I think I was looking to do
something more visual and less pie
approximation II calculate the I don't
think this is possible
I mean I could I you know I could train
gbt to on or like a recurrent neural
network on the digits of pi couldn't
learn like what I mean that's sort of an
interesting idea I I mean I don't think
this is gonna work but like I'm gonna
like keep this in mind is something that
I could do where am I
they also need to do a song so I got my
ukulele song ideas oh it's noon noon
o'clock I got to go search for words in
PI this I like oh this I like this I
really like okay I'm gonna add that so
there's a lot about nice ideas here oh
boy there's so many pi city skyline
pie-in-the-sky Oh interesting so these
are like the digits of pi in a skylight
it wants so much nice a nice idea I see
there's like it looks like there's a
three blue one Brown video being posted
okay I think I got to go
there's actually quite a bit of all okay
yeah yeah these are the original
suggestions yeah so I've done stuff like
this which I really like but I don't
want to just copy somebody else's
beautiful art so I would need kind of a
a new creative idea but that I have done
oh here we go
so that's the proof okay so I'm gonna
look through these some more thank you
for those suggestions someone added a
new suggestion
I don't know why I'm not seeing oh
because it's not doesn't have the label
yet so let's label this pi day
bake up high I mean I kind of really
want to do that I pie day comes at a
very difficult time because it's written
sort of like the prime like March 14th
is like Spring Break for NYU is the week
after they were like a week later I have
a lot more time to like maybe do
something kind of special or have like a
hold a stream and it's really busy right
now for me so I might have to just do
something quick but I might record it in
the Cabana although those take a look
longer and harder to produce so anyway
thank you for all these ideas I'm gonna
get going
thank you again to dashlane as the
sponsor of today's live stream
- link comm / coding train will get you
a free 30-day trial or in 10% off if you
purchase the premium subscription -
Elaine is a password manager and cookie
hit the cabana and I'll see I'll be back
next Thursday so I'm pretty locked in to
this Thursday thing I can tell you
though that just look at calendar for a
second
[Music]
what month is it
[Music]
today's what is today March 5th hello
Michel watch Johnny we're yeah okay I
was gonna open up Google Calendar I'll
just open this so I'm gonna pause for a
sec March 12th
we're on Oh pi day is Saturday the 14th
which would bring like a good time to do
something but I'm gonna be travelling
assuming traveling is still a thing it's
close travel but I won't be available to
livestream so March 12th will be next
week I guess I could like maybe try I
could like do actually some of these
challenges and then Matt you and I could
edit them together quickly well hey we
will do it and I'll be like thank you
but to come out on the 14th and then
March 19th I will also be doing a
livestream the 26th I am NOT available
so I believe the live streams for this
month will be 5th 12th and 19th and then
if I can get my act together and at some
point the channel hits 1 million
subscribers maybe I'll try to come come
do an extra like sort of bonus live
stream whenever that happens there's a
little celebration so thank you
everybody
any more questions to ask before I go
[Music]
shabam says you talked me p5.js and ml5
Jess and I got an A grade for the
project thanks a lot
congratulations I'm glad you got an A
and every grade is a great grade to get
if you learned something has got to be I
congratulate you as well
it's always nice to hear when people are
applying stuff from this channel to
school or to work or their own creative
just hobby is that I love hearing that
thank you
[Music]
JMP asks what classes do you teach on
campus so I teach a variety of different
classes at NYU part of the ima program
and the ITP program um those are at
Tisch School of the Arts I also teach
some online classes for NYU using some
of these videos learning to code and
currently I'm actually teaching the
nature of code course which is why I'm
focusing on making the videos during
these live streams that get edited into
a playlist and I've just been really
behind but I do do the the playlist is
there and I'm gonna make it unlisted
available for people to see pretty soon
so if you a videos will slowly be made
public on the channel so if you're
subscribed you'll get notifications to
click the bell blah blah blah but if you
join the discord that's a place where
I'll make sure to share when there's
some extra unlisted videos that you
might want to check out as well
[Music]
thank you Jason writes I love your book
which book I wrote - really trying to
get a new edition of nature of code out
I was actually working on it I kept
probably working on it maybe an accident
like two hours per week and it really
needs like eight to ten hours per week
for me to make more progress but I'm
editing and it will be a new version out
soon enough
[Music]
Guzman writes I am new to programming
alright there were only ten seconds left
there so I had to pause so one thing and
thank you especially to violet who has
done a lot of this work oh you can't see
this but the coding train website you
you should be able to find things on
YouTube itself but the website mirrors
the all the YouTube content and has
extra things but it one thing that it
does is it kind of highlights specific
playlists so under beginners up at the
top p5.js this will take you to the
beginner decided beginner videos so if
if I were to go click on watch on
YouTube it's going to now why does it
not oh it's going to show with this
hello first video and one thing that I
would also note is that a lot of these
cuttings are in these learning playlists
so if I click here you'll then see this
interface which has all the videos and
different sections of all this content
so you know if you're new to programming
there are many other places and videos
and books and tutorials and communities
where you could learn to code this is
just one of many but this would be my
playlist that's designed for people who
have never coded before alright thank
you everyone I am going to say goodbye I
will play you out with a bunch of the
coding train remixes there's some new
ones that have coming in and it crossed
my peripheral vision that I saw someone
post there's like a new remix with maybe
a position let me see if I could find it
all right hold on somebody help me find
this there was a new coding train remix
which I am now at going to attempt to
play you out with so we open up the
discord somebody posted it in the
discord where where where
a remix maybe if I search for position
oh yeah
oh I posted it I posted it let's try it
let's try this one
oh the track was not found maybe it has
been removed oh wait maybe somebody else
posted one
my position remix of today's livestream
it's gone
does anybody know what I'm talking about
I really have to go but I really want to
find this remix let me just search
position I guess
oh boy there's a lot of people asking
questions about code examples with the
word position in it alright I guess I
can't find it
it was Titan a user named Titan had
created a remix with position let me go
to SoundCloud so this is random this is
noise Perley noise that is in there more
random algorithm the actual random
algorithm itself those numbers aren't
related at all you pick like I'm picking
random numbers between zero and ten nine
two seven six one nine four nine two
this by the way is the SoundCloud play
literally noise I pick numbers like a
lot of reviews and I will play a bunch
of em thank you I really gotta go now
guys performance part
[Music]
two three four three four five six five
these look like birthing noise
performance apart with curly noise I
might pick numbers like this
by purling noise that is early noise
this is Hurley noise that and it's
Hurley no this is this is Hurley noise
that is Hurley no so this is Hurley
noise that it's her Hurley know her
purling noise that is Hurley boy this is
Hurley noise that it's hurtling this is
this is Hurley noise that is Hurley so
this is Hurley noise that it's early
early early early early but with pearly
noise I might pick numbers like this
[Music]
I always forget to do this star this
star this star this star song never
forget the miss start somebody composed
that song for me this neighbor count
equals zero blood fill time it's flood
filled time
[Music]
yeah how could you better but anyway
there was an error the song didn't load
and then there's a callback that's like
it's loading is loading it's the loading
song it's loading loading it's the
loading song so let's see if this works
[Music]
the loading song of course I could do
sound synthesis myself
[Music]
all aboard
[Music]
and auto-tune and the internet will fix
that for me
[Music]
coordinates
[Music]
our coordinates
it's the phone to Cartesian coordinates
its Cartesian coordinates
the chords and rainbows and cupcakes
what else is there yes kids thank you
very much
kittens and rainbows and cupcakes notice
that look what I get I'm really losing
my mind
[Music]
- kittens
[Music]
[Applause]
[Music]
I feel just sort of like a nice feeling
of relaxation everything's gonna be okay
today dream is not broken it has not
frozen this isn't this is a wonderful
thing okay we're gonna do it I'm really
getting to something I need my sound
[Music]
what else is there unicorns
kay that would be valid syntax I forgot
one other thing here that I will use the
tingly over and over again all sorts of
text generation analysis states that I
will use continuously over and over
again the first thing to do is
[Music]
we're gonna do
[Music]