MynameisDanSchiffman, and I haveabout 40 minutesbefore I havetogo.
I justfinished a hourofcodetutorialonthecamera.
Ofcourse.
JustshutoffWhere I madethisprojectthattracksyournose.
Ittracksyournosewith P fivemlfiveandthepostnetmodel.
And I'm herenowtowasteyourtimebecause I havethings.
I wanttoexperimentwiththediscuss, butyoushouldprobablyjustgoaboutwithyourday.
If I canmanage a goodquotingchallengeinbefore I go, I wouldliketodothat.
Soonething I want a testhere, and I don't knowwhythisisn't working.
Letmetryrefreshingthisagain.
Allright, So I'm planning, bytheway, isprobablygonnabeDecember 20th.
I amplanning a fundraiserfortheProcessingFoundationProcessingFoundationdot, orge, ifyou'renotfamiliarwiththeProcessFoundation.
Theprocessingfoundationisthenonforprofitentitythatthatmanagestheprocessingproject P fivejazzprocesspython, andalso a lotofcommunityandeducationinitiativesaroundartandcodeandallsortsofstuff.
AreyouHopefullythat, umhopefullythat I shouldmakeyouknowwhat I shoulddoforthefundraiserisonthefundraiser.
I shouldwrite a P fivesketchthatcommunicateswiththeYouTube a p i andlike, makes a little, likeheartorsomethingwheneversomebodymakes a donation.
Butyouneedtogetthatsuperchatforgoodthingworking.
Um, okay, Soifanybodyknows, I mean, I'llcontactYouTube, butifanybodyknowsaboutthatorhaveworkedwiththeYouTube a p I actually I knowyoucanwritebotsandthingsforthechat, sothat's actuallyprobablywhatThat's something I shouldlookintoanddoSowhatcan I do?
RightNow I have a 35.
I hadthisidea.
Actually, thisisprobablyinsanetotrytodothisofdoinglike, a flockingsimulation.
Ifyoudefine a to d shapeinrelationtothepoints, surelyyoucaninthree D aswell.
Yeah, absolutely.
Umallright.
No, uh, I really I havenoplan.
Notwhatsoever.
SchrodingerequationCreate a Gaffingrevisitingpixelsortingthroughquicksort.
I wouldlovetodothequicksortcodeJohn's rightnow, but I don't think I'm goingtotriplependulum.
Jane, we'reactuallymarchingcube.
Who?
Thatwouldbe a goodone.
Stolennecklace, drunkenbishop.
Spiralmapprojectioncodingchallenge.
Maybewhatwecoulddoyouknow, I havethis, like, weirdideathat I wouldliketo D'oh, um, whichisbecause I waswatching a standupmathsvideoononunboxingthisDVDandwas, like, thiscrazy, infiniteRikersinintotheTVthing.
I feellikeweshouldjustprogramthatThatwouldbefunif I wasdoingvideostuff.
Um, but I don't know, uh, plotter, softbodysimulationroominnumerals.
Clickingonobjectinthree D spacelizardvisualization.
Andyoucanalsofindanexplanationofitaspartofmynatureofcodebookonlinewithsomediagramsandcodewritteninprocessingandanexercisethatyoucouldtry, which I'llreferyoubackattheend.
But I'm goingtostartfromthis.
A blankslate.
I justhave a canvas.
Youhavesomeamountofpixelsinit.
Thereisnothinghappeningintheconsole.
And, um, I'vegotthiscoatsetupanddraw.
Allright, sowhatdo I needtodonow?
There's definitelygoingtobe a bigneedtorefactorofthecodethat I comein, right.
Soifyoulookatmyexample, it's hopefullysomewhatwellorganized, but I'm gonnathankyou, Matthew, foreditingforme.
Allright, letmejustletmeletmedoublebackfor a second.
So I'm gonnawritethiscodewithoutworryingaboutbeing, like, perfectlyorganizedandbeingabletoscaleitveryeasily.
I justwanttotrytogetthealgorithmworking.
Butofcourse, whereisthebutton?
Ifyouwanttosee a refactoredexampleofthat, heprobablygoinglookingactuallyatmyfinishedversioninnature.
Sothefirstthingthat I wanttodosobecause I wanttoaddanotherjobuh, a filecalledparticledotJsactuallyknowwhat I shouldrenamethistoBoyddotJs.
Sowhatisthisterm, Boyd.
WhenCraigReynoldsinventedthisalgorithmforsimulating a flockingsystemlike a flockofbirdsor a swarmofbees, I supposehedidn't wanttousethetermburned, butitiskindoflikebirds.
Soif I nowactuallycreate a, uh, P fivedotvector a randomto d believethisis a functionthatwillgiveme a randomvelocityvector, and I nowgoinhereandsayBoyddotupdateokay.
Cannotreadpropertyadofundefined.
Oh, no, I havethevis 0.0, I justspelleditwrong.
I thought I missedthisstarts.
Okay, therewego.
Look, it's moving.
It's movingwithIraninvelocityeachtime.
Okay, Now, let's justmake a bunchofthese.
Now I have a systemof 100.
Boyd.
Sointeresting.
Lookatthis.
ItfansoutinthispurposePerfectcircle.
DoyouknowwhythatISS?
Because I make a Boydand I giveit a randomvelocity.
Thatrandomvectorisalwaysofunitlengthone.
Thedirectionissomethingdifferent.
Sothey'reallactuallymovingwiththesamespeedif I wantedthemtohaveThisisnotanimportantdetailtotheflockingstuff, butjusttosortofget a senseofhowthisvectorstuffworks.
I couldsaythisdotvelocity, umsetmag, whichissetthemagnitudethio a randomvaluebetween, like 0.5 and 1.5.
Andnowyoucanseenowthey'reallmovingwith a slightlydifferentvelocity.
Sothisis, bytheway, a nicelittle, like, almostlikeexplosionmotif.
And I couldhavethemwith a realbigburstandtheyslowdown.
There's allsortsofphysics.
See, stuff I coulddowiththis, but I justwanttodoflocking.
Youmightwanttogowatchmyvideosabouthowvectorswork, but a vector a p fivevectorjustholdsan X and A Y oran X and Y and Z.
So I wannaaveragethevectoritsrepresentativesanarrowwithanextrabonein a Y componentgoingaverageitjustlikemyaverageunderrayofnumbers.
Addthemallupanddividebythetotal.
Andthen I wouldsay, averagedotdividebyBoyd's dotlength.
Thiswouldbe a wayofgetting a wayofgettingtheaveragevelocityofalloftheboys.
Butremember, I onlywanttheoneswithinsomedistance.
Soactually, let's implementthatrightnow.
Let's let's havesomesortofdistancelike, uh, Maxare a cultlikeperceptionequals, let's justmakeitthrougharbitrarylike 100.
Andthen I'm goingtonowsay, ifthedistancebetweenthedistancebetweenthisstockpositiondotexpoyouknowwhat, I thinkthere's a P five.
Thisisfine.
It's justgonnabeIt's kindofalongtheway.
I'm writingthis, but I don't mindifthedistancelet's actuallymakeitin a variable d equalsthedistancebetweenthisBoyd's positionandtheotherBoyd's Position X Andwhy?
Andifthatdistanceislessthan 100.
Uh, lookatthat.
Lookatthisfancythingthatit's doing.
I havesome, like, prettierstuffthat, like, doesn't wannaletmelearn a longlineofcode.
I guess I'llkeepthatinthereforrightnow.
So I'm calculatethedistancebetweenthisboy's position, theotherboysposition.
Andifthatdistanceislessthan 100 I'm addingitup.
And I shouldsay I shouldalsoprobablyhave a totalnumber.
Totalequalszeroaddedup.
I alsoshouldprobablyignoremyselfandifotherdoesnotequalthisright, So I basicallyand I mightaswellputthatfirstright, aslongastheotherthingisnotme, andthedistanceislessthan 100 addedupandthendividebythetotal.
Okay, Sonowif I gobacktosketchand I say, uh, BoyddotflockBoyd's, weshouldnowhavealltheBoydsdoingthatonewithjustjustimplementedwiththatAlinealignmentRuleboydoesnotdefinesketchtouchasline 14.
ItwascalledFlock.
Oh, thisismyvariable.
Namingisterrible.
Um, but I'm gonnaleaveitthatwayrightnow.
A lineisnotdefined, boydotJs a lineBoyd's Oh, thisdataline, thisdatalinevoidshopesaccelerationisnotdefined.
Oh, mygoodness.
That's notmuchbetter.
Okay, solet's thinkaboutthis.
It's soit's kindofworking.
Letmeletmegivethem a muchhigherburstofspeed, because I think, um, andallthemstartingthesameplateactuallyalso, let's let's do a couplethings.
We'renotseeinganythingdifferent, butif I weretomakemaximumforce, like 0.1 likereallysmallrightnow, you'regonnasee, likethey'renotactuallychangingtheirvelocity.
Theyare, butvery, veryslowly.
Andtheotherthingwe'rereallygonnaneedtodo I justhaveto, like, giveupanddothis.
I'm gonnaaddsomesomethingfortheedgeshere.
So I'm goingtosayifthisstoppositiondot X isgreaterthanthewiththisstoppositiondot X shouldequalzeroelse.
Ifthisstoppositiondot X islessthanzero, thisstoppositiondot x equalswithsoandthen I'm justgonnadothatforthewhyWhyareyouhere?
Whydidtheterminalopen?
I havenoidea.
Uh, I think I hitlike a keycommandthatmadethathappen.
Andthenwe'regonnadothisforwhy?
And I coulddothisinsomanydifferent, morethoughtfulorrefactoredways, butthisisgonnabegood.
Oh, no.
Whatam I doing?
Okaywithwith x x y y y y y x x x x x x withwithallrightnow.
Thisisactuallygonnabeworthit, because I shouldalsogivethem a maximumspeedliketheylikethisisgonnabe a parameterofvariable.
It's gonnaallowmetocontrolthesystemprettywell, and I couldconsidertheirdesiredvelocityinthealignmenttonotactuallybetheactualaveragevelocity, butjusttheaveragedirectionbecause I couldthensaysteeringdotsetmagnitudetothisStottmaximumspeed.
Sobasically, I'm saying, like, I alwayswanttogointhedirectionofmyneighbors, butatmaximumspeed, and I don't knowthatthat's reallyanimportantdetail.
Butif I addthatinhere, wemightgettheeffectthat I wassortofhopingtoget, whichnowthisiswhat I wasexpectingtosee.
Thisiscohesionhappeningbaitandthatneighborradius, bytheway, is a superimportantvalue.
Right, thatneighborradius.
If I weretochangethatand I have a differentperceptionradius, if I weretochangethatto, like 10,000 right, they'reallgoingtocometogetherasonebecausetheyallSeeeverybody.
If I weretochangethatto 10 rightthere, Really?
Thisis a littlepears.
Likeyoucouldseethatkindofgetin.
Littlegroupsoftotheforce, though, isn't sostrong.
So, like, if I weretochangethemaximumforcerighttolikeoneNowyouseethem.