1.2: PVector class - The Nature of Code

  Рет қаралды 98,820

The Coding Train

The Coding Train

Күн бұрын

Пікірлер
@genvalencia1740
@genvalencia1740 8 жыл бұрын
This guy makes me feel like it's okay to be as awkward as I am and it's so comforting
@susiesan
@susiesan 5 жыл бұрын
It's very endearing
@MegaOmpuri
@MegaOmpuri 4 жыл бұрын
So true!!
@freddiejonesy6168
@freddiejonesy6168 3 жыл бұрын
So true!
@mucjwt8550
@mucjwt8550 3 жыл бұрын
true.. a kind of comfortable awkwardness.
@krccmsitp2884
@krccmsitp2884 2 жыл бұрын
We call this neurodivergent nowadays. 🙃
@KaizenCodes
@KaizenCodes 5 жыл бұрын
Does anyone else ever get stuck on some code and remember a Coding Train video about it - but instead of just skipping to the part where Dan explains, you end up re-watching the entire nature of code series?
@SoDamnMetal
@SoDamnMetal 3 жыл бұрын
Yep that's exactly what i'm doing :D
@GlobalSingeing
@GlobalSingeing 6 жыл бұрын
I like how he mentions Vimeo in 2015 lol Currently watching through your whole Nature of Code series after starting with the Neural Network one. You thoroughly impressed me as a teacher. You remind me of a less edited Vsauce. Keep up the good work!
@yashaswinis45
@yashaswinis45 Жыл бұрын
Vsauce! Exactly! Thought I was the only one who found that faint similarity
@redink891
@redink891 9 жыл бұрын
Your videos are so cool, keep it up! No one else makes coding and math so funny and entertaining! :D
@anthonycokayne7453
@anthonycokayne7453 7 жыл бұрын
Easily the best programming videos on KZbin, such a great energy, I'm constantly smiling whilst following along.
@OstiguyBass
@OstiguyBass 4 жыл бұрын
Re-visiting all nature of code but I will do the home works this time instead of just creating stuff randomly. Thanks for everything. This is SOOOOO useful. Your the best !
@JulioCesar-gz3kz
@JulioCesar-gz3kz 3 жыл бұрын
I just star learning how to code video games because I'm teaching my 12 year old son how to code, but we'd had having issues trying to do every with x and y varíables, but thanks to you I learned how to use vectors and now everything is a lot easier. Greetings from 6 years in the future. By the way the way you teach is awesome!
@DavidDaybreakASMR
@DavidDaybreakASMR 7 жыл бұрын
I have to say: I have been following along from I.0 to here, and I'm glad that you've kept all of the codes relatively short (seeing as codes can get thousands of lines long). I have been able to easily replicate your examples-and I hope that I continue to work through this until I can make some sort of game!
@beil3537
@beil3537 5 жыл бұрын
I want what you're on Dan! You have the most amazing upbeat disposition - and such a brilliant educator. Just awesome.
@insidethematrix755
@insidethematrix755 7 жыл бұрын
@6:13 Living with your weird ramblings. Sometimes those ramblings help me understand better. Keep the weird ramblings and NEVER cut them out =)
@JohnnyDub08
@JohnnyDub08 7 жыл бұрын
Hey Dan..yes.. you were more funny back then.....just kidding... you're still very funny. Everybody should have a teacher like you. Thank you for all the work and effort you put into making programming more accessible. You are great!
@Ferocious_Imbecile
@Ferocious_Imbecile 6 жыл бұрын
I got bogged down a bit on your Learning Processing Chapter 9 with the Arrays so I came over here to have some fun. It was fun. Thanks.
@jowadulkader9006
@jowadulkader9006 8 жыл бұрын
thank you sir.you are an excellent teacher.your videos are very interactive,funny and above all very easy to learn from.thanks a lot
@RRKS_TF
@RRKS_TF 4 жыл бұрын
8:17 there's this thing called operator overloading that allow you to change what operators do for your class. I.e; add the X and y positions of 2 points and return the new vector. I don't know if it's in java but it is in c#
@WistrelChianti
@WistrelChianti 2 жыл бұрын
8:40 I could see you running full long at that cliff drop while thinking "OK how's he going to explain THIS one" and loved your "you just can't do that" bail. =D Epic! [Not faulting BTW, totally get your reasoning just enjoying the comedy - it would take a lot of work to explain]
@rhazzzvvv
@rhazzzvvv 3 жыл бұрын
Entertaining while teaching coding. Love it!!
@sreekesariv.9059
@sreekesariv.9059 3 жыл бұрын
Wonderful explanation Dan!!! I just wanted that bouncing ball to bounce-back right after hitting the wall. Sent a PR to the github-repo 😅 introducing a new variable `ballRadius`... Learning many new things from your series, thanks for doing this!
@thelumiereguy
@thelumiereguy 4 жыл бұрын
Kotlin has a feature where you can implement the operations you want to use with your class. So within my class, I can say operator fun plus(value : Int) (Predefined), but I define the implementation part myself.
@robthompson1331
@robthompson1331 8 жыл бұрын
Thank you very much.Thats what I call infotainment! Keep going Mr Shiffman
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Rob Thompson Thank you!
@ShaolinMonkster
@ShaolinMonkster 8 жыл бұрын
Why this channel has only 36k subs. You are awesome
@caio-jl6qw
@caio-jl6qw 5 жыл бұрын
look again
@loltool5513
@loltool5513 5 жыл бұрын
And now
@benjaminvanderwolf5239
@benjaminvanderwolf5239 6 жыл бұрын
definitly love your videos man. You are a great teacher. bingewatching your videos at the moment ^^
@colemasuno7304
@colemasuno7304 4 жыл бұрын
Your videos are so fun to watch at 2x speed :-D Thank you so much!
@riguidixrodriguez1090
@riguidixrodriguez1090 4 жыл бұрын
I really love how to understand all with you :D you're so cool :) the best teacher ever, take care w/Corona :(
@GonzoGonschi
@GonzoGonschi 9 жыл бұрын
super excellent and entertaining presentation. Thank you so much for the effort Daniel!
@gauravagarwal6565
@gauravagarwal6565 3 жыл бұрын
When you said location. X how does x got binded and how it knows location. X is the first value of pvector
@conan5743
@conan5743 8 жыл бұрын
I love the way you teach Thank you for doing this , and also the explaining you do makes it easier to understand . Than You
@rahulmathew8713
@rahulmathew8713 4 жыл бұрын
Awesome work !!! Really loved your videos
@manualvarado2212
@manualvarado2212 6 жыл бұрын
5:53 I was just thinking a few seconds before on how good those key presses sound.
@chanasiegel2706
@chanasiegel2706 4 жыл бұрын
Whenever I run it I get "UNCAUGHT SyntaxError: Unexpected identifier". Please help. You are an amazing teacher by the way.
@ettorefagioli1012
@ettorefagioli1012 4 жыл бұрын
I don't know too! Help us!
@chanasiegel2706
@chanasiegel2706 4 жыл бұрын
I just realized that he is coding processing and I tried it in p5js. That's what caused the error. In p5js you say 'let location' and 'location = createVector'.
@corey333p
@corey333p 8 жыл бұрын
When I say: location = new PVector(width/2, height/2); location.x and location.y become 50. It's as if location coordinates are being set to a percentage with respect to the drawing dimensions. If this is the case, I can work with it, but I'd like to know it doesn't seem to be using x and y coordinates directly? My screen size is 800x600 so I expected values of location.x and location.y to be 400 and 300 respectively
@paulbelfrage
@paulbelfrage 7 жыл бұрын
Made this to better understand. Used println to print the vectors in console PVector v1; PVector v2; void setup() { size(500,500); background(255); v1 = new PVector(250,250); v2 = new PVector(10,10); frameRate(1); } void draw() { noStroke(); fill(255); rect(0,0,width,height); // Add vector v2 to vector v1 v1.add(v2); // subtract vector v2 to vector v1 //v1.sub(v2); stroke(0); fill(100); strokeWeight(5); line(v1.x,v1.y,v2.x,v2.y); println("v1" + v1); println("v2" + v2); println("-------"); }
@ruizanchetta1220
@ruizanchetta1220 3 жыл бұрын
Could I separate the coordinates of PVector and do this math: location.x.add(velocity.x)? Could I add just the x component of the location PVector?
@emmanuelgatica4998
@emmanuelgatica4998 4 жыл бұрын
You should do this same course but in Javascript. I am watching this doing Javascript instead of Java and it would be so much easier not having to translate Java to Javascript.
@weizheng8637
@weizheng8637 8 жыл бұрын
I watched the 1.4 Vector Math, there is one line I am not sure, mouse.sub(center), I was wondering what is the "centre" stands for? Million Thanks!
@liachrys9325
@liachrys9325 7 жыл бұрын
I live for these videos... thank you
@alejandromurillo2174
@alejandromurillo2174 3 жыл бұрын
Excellent explication....I like
@yasaminkhalilbeigikhameneh4182
@yasaminkhalilbeigikhameneh4182 8 жыл бұрын
U made processing funny and lovely for me
@jamesvic1000
@jamesvic1000 6 жыл бұрын
Can the PVectors be evaluated (i.e. for autonomous vehicle target evaluation)? Thanks!
@kevinbay9542
@kevinbay9542 8 жыл бұрын
These are great, thanks Dan! ...I have a feeling I'm not the only one learning this in Processing and then translating it for use in p5.js along the way. It's a great exercise, but is there a Nature of Code p5.js repository somewhere?
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Kevin Bay Here you go! github.com/shiffman/The-Nature-of-Code-Examples-p5.js (and I'm hoping to release a p5.js version of the entire book soon too!)
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Daniel Shiffman Also this will be in p5.js: www.kadenze.com/courses/the-nature-of-code
@kevinbay9542
@kevinbay9542 8 жыл бұрын
Yahoo! Thanks!
@snnpa
@snnpa 5 жыл бұрын
Is it possible to make video to vectors? I would like to film a person and change that person to vectors and lines. So when the person moves, it just lines moving.
@007aha1
@007aha1 6 жыл бұрын
i can also do this with an 2 dimensional array right?
@YaroKasear
@YaroKasear 4 жыл бұрын
Processing doesn't do any operator overloading? That seems odd.
@diegoferreira3444
@diegoferreira3444 7 жыл бұрын
thank you so much love ur videos, btw when's the next stream?
@TheCodingTrain
@TheCodingTrain 7 жыл бұрын
If you subscribe and click the alarm bell icon you'll get a notification when I schedule it.
@clementeferrer5070
@clementeferrer5070 7 жыл бұрын
I really like your wallpaper. Where did you find it?
@olfmombach260
@olfmombach260 7 жыл бұрын
Selfmade with Perlin noise and force fields I guess
@bradleystone9099
@bradleystone9099 7 жыл бұрын
Is there any reason why all of this wouldn't work the same in Brackets?
@mohshafi3032
@mohshafi3032 5 жыл бұрын
Thank you for your effort, could you please let me know what programming language is that you have coded the "Class Ball"
@spectre.8804
@spectre.8804 5 жыл бұрын
It's Java
@xia1096
@xia1096 5 жыл бұрын
for me, it doesn't work, it said "looks like you are mixing active and static modes ", anyone knows what happened there?
@lewisshemery2585
@lewisshemery2585 7 жыл бұрын
is a vector essentially a slope?
@Djzaamir
@Djzaamir 7 жыл бұрын
Thank you Sir , someday i am gonna meet you and have a cup of tea with you :)
@saiBee7
@saiBee7 4 жыл бұрын
how does processing know x, y variables?? you never initialized it.?? is it inherent..
@iYankrozHD
@iYankrozHD 6 жыл бұрын
Hey Coding Train. I have a question regarding vectors in p5. How come the createVector function only takes one point in a 2d space? Surely, a vector needs to be constructed from two 2d points, so obviously it has the origin as one of the points, but wouldn't it make more sense to have the option of entering two points?
@TheGBsXB
@TheGBsXB 6 жыл бұрын
createVector([x], [y], [z]); x & y & z are optional, that means if: createVector(); // x = y = z = 0 createVector(7); // x = 7 & y = z = 0 createVector(11, 7); // x = 11 & y = 7 & z = 0 createVector(13, 7, 11); // x = 13 & y = 7 & z = 11 I know it is a late reply but it might help someone else, good luck!
@kaz372
@kaz372 4 жыл бұрын
It only needs one point, if you instantiate a vector with x=2, y=2, this means your vector goes from 0 to 2 on x axis, same for y on y axis. If you have a velocity vector of (-1, 1), and you add it to you position vector(2,2), your new vector position is (1,3) From origin you have actually gone right 2 units then left 1 unit, up 2 unit then up 1 unit, leading you to (1,3). And if you subtract your current position from your previous one, you'll get the velocity vector of same magnitude with opposite direction than the velocity vector that led you where you landed, (2,2) - (1,3) = (1,-1)
@katupeku08
@katupeku08 4 жыл бұрын
What is the initial magnitude of a vector, if it doesn't have a second vector? Greetings from Argentina !
@kaz372
@kaz372 4 жыл бұрын
A vector is not a lone and isolated point, it's the coordinates where you land after a move, it traduces a relationship between two points, thus it always assume a starting point, an origin. If no point is precised to be the origin of the move, then the origin simply is the absolute origin of the whole space (coordinates 0,0), and the vector magnitude will be sqrt( vector.x**2 + vector.y**2 )
@katupeku08
@katupeku08 4 жыл бұрын
@@kaz372 thanks !
@kaz372
@kaz372 4 жыл бұрын
@@katupeku08 you're welcome, and if I can reformulate, it's actually not "the coordinates where you land after a move", it's the distance you travel on x and y axis respectively from a starting point !
@sweethomes674
@sweethomes674 Жыл бұрын
Wonderful 😊
@skoskop
@skoskop 2 жыл бұрын
how do I import PVector , I couldn't find anything online for it .
@GERARADO345
@GERARADO345 7 жыл бұрын
my ellipse doesnt work when i put my pvectors in please help
@UnbornFamas
@UnbornFamas 5 жыл бұрын
Mine Didn't work :/ I have you're book and I have followed your video and the book and all I get is a ball that doesn't move now :(
@corykilpatrick1175
@corykilpatrick1175 5 жыл бұрын
My code looks verbatim but I'm getting errors - The constructor PVector(int, int) is undefined The function add.PVector does not exist The global variable x does not exist
@samanthayong6814
@samanthayong6814 6 жыл бұрын
Great teaching! I actually understand haha 👍
@Shockszzbyyous
@Shockszzbyyous 7 жыл бұрын
there is a way to override the + operater in java right?
@Shockszzbyyous
@Shockszzbyyous 7 жыл бұрын
apparently not, but why does string have this behavior ?
@olfmombach260
@olfmombach260 7 жыл бұрын
Hardcoded I guess
@DJTechno94
@DJTechno94 7 жыл бұрын
Mind if I steal some of that good mood?
@manualvarado2212
@manualvarado2212 6 жыл бұрын
13:17 A painting, a painting.
@RenkoGSL
@RenkoGSL Жыл бұрын
That was java. This is the corrected solution for ps5js class Ball { constructor() { this.location = createVector(width / 2, height / 2); this.velocity = createVector(2.5, -2); } move() { this.location.add(this.velocity); } bounce() { if (this.location.x < 0 || this.location.x > width) { this.velocity.x = -this.velocity.x; } if (this.location.y < 0 || this.location.y > height) { this.velocity.y = -this.velocity.y; } } } let ball; function setup() { createCanvas(400, 400); ball = new Ball(); } function draw() { background(220); ball.move(); ball.bounce(); ellipse(ball.location.x, ball.location.y, 20, 20); }
@brenttrenholme7609
@brenttrenholme7609 6 жыл бұрын
I don't understand how to make a PVector it doesn't work for me
@waltersilvestrini6544
@waltersilvestrini6544 6 жыл бұрын
What language and what IDE is he using?
@TheRemiRODRIGUES
@TheRemiRODRIGUES 6 жыл бұрын
Processing ! processing.org/
@cimmik
@cimmik 8 жыл бұрын
I get this error when I tries to declare "private PVector position;": Cannot find a class or type named "PVector"
@cimmik
@cimmik 8 жыл бұрын
Is it because I use it in a class in a file called Walker.java?
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
correct, you need all the java imports if you are using java files and not pde files.
@cimmik
@cimmik 8 жыл бұрын
Thank you for you answer. I found out that, but youtube wouldn't let me do anything with my comment.
@corey333p
@corey333p 8 жыл бұрын
I was having the same problem because I was using "Pvector" instead of "PVector"
@MrOdammy
@MrOdammy 7 жыл бұрын
how do i write this in my p5 ide?
@nikims_
@nikims_ 4 жыл бұрын
With your keyboard
@zoilo87
@zoilo87 7 жыл бұрын
What is the file type for the class Ball?
@TheCodingTrain
@TheCodingTrain 7 жыл бұрын
"pde" for "processing development environment"
@UnbornFamas
@UnbornFamas 5 жыл бұрын
Hey My ball isn't moving :(
@letsgocamping88
@letsgocamping88 5 жыл бұрын
The pen looks like a magic wand. I think you need a magic wand for your new stuff.
@UniverseGOD2525
@UniverseGOD2525 8 жыл бұрын
THANKK U SO MUCH
@silaseriksen5771
@silaseriksen5771 7 жыл бұрын
What editor to use??
@silaseriksen5771
@silaseriksen5771 7 жыл бұрын
Thanks! Is it possible to resize the "canvas"?
@silaseriksen5771
@silaseriksen5771 7 жыл бұрын
Just found out about the size() function
@Kampouse
@Kampouse 4 жыл бұрын
funny how some of your content could pay to watch but you do it for ()
@Rudyok0001
@Rudyok0001 3 жыл бұрын
5:54that kinda freaked me out, lol look at my user name
@shelleyj8813
@shelleyj8813 7 жыл бұрын
I wish he was my teacher instead of "Te Taka" #boycottTeTaka
@Tejas-zx7ie
@Tejas-zx7ie 5 жыл бұрын
But can you adopt me?
@GonzoGonschi
@GonzoGonschi 9 жыл бұрын
super excellent and entertaining presentation. Thank you so much for the effort Daniel!
@TheCodingTrain
@TheCodingTrain 9 жыл бұрын
Thanks so much for watching!
1.3: Vector Math - The Nature of Code
16:27
The Coding Train
Рет қаралды 76 М.
1.6: Vectors: Acceleration towards Mouse - The Nature of Code
10:06
The Coding Train
Рет қаралды 58 М.
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 60 МЛН
Car Bubble vs Lamborghini
00:33
Stokes Twins
Рет қаралды 31 МЛН
The Singing Challenge #joker #Harriet Quinn
00:35
佐助与鸣人
Рет қаралды 9 МЛН
4.5: Introduction to Inheritance Part I - The Nature of Code
13:07
The Coding Train
Рет қаралды 30 М.
4.2: ArrayLists in Processing - The Nature of Code
13:51
The Coding Train
Рет қаралды 76 М.
2.2: Applying a Force - The Nature of Code
17:39
The Coding Train
Рет қаралды 54 М.
3 SHOCKING Games that will change how you look at chess
24:10
mortal chess
Рет қаралды 19 М.
1.5: Acceleration - The Nature of Code
14:20
The Coding Train
Рет қаралды 63 М.
Programming Flow Fields
30:27
Programming Chaos
Рет қаралды 3,3 М.
2.3: Simulating with Mass - The Nature of Code
14:44
The Coding Train
Рет қаралды 41 М.
1.4: Vector Math II - The Nature of Code
11:29
The Coding Train
Рет қаралды 49 М.
2.6: Gravitational Attraction - The Nature of Code
20:16
The Coding Train
Рет қаралды 55 М.
I.5: Perlin Noise - The Nature of Code
13:44
The Coding Train
Рет қаралды 187 М.
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 60 МЛН