1.2: PVector class – The Nature of Code

[ad_1]
In this video, I look at how to apply the concept of a vector in Processing itself using the PVector class. The video accompanies Chapter 1 from The Nature of Code book.

Twitter:

Read along:

Code:

Help us caption & translate this video!


Posted

in

by

Tags:

Comments

32 responses to “1.2: PVector class – The Nature of Code”

  1. Anthony Cokayne Avatar

    Easily the best programming videos on YouTube, such a great energy, I'm constantly smiling whilst following along.

  2. Nerdão Avatar

    thank you so much love ur videos, btw when's the next stream?

  3. Bradley Stone Avatar

    Is there any reason why all of this wouldn't work the same in Brackets?

  4. zoilo garingan Avatar

    What is the file type for the class Ball?

  5. Ini Ade Avatar

    my ellipse doesnt work when i put my pvectors in please help

  6. DJ Techno Avatar

    Mind if I steal some of that good mood?

  7. Inside the Matrix Avatar

    @6:13 Living with your weird ramblings. Sometimes those ramblings help me understand better.
    Keep the weird ramblings and NEVER cut them out =)

  8. Procrastination girl Avatar

    I wish he was my teacher instead of "Te Taka" #boycottTeTaka

  9. Silas Eriksen Avatar

    What editor to use??

  10. SilenceOfThought Avatar

    class Ball {
    PVector location;
    PVector velocity;

    Ball() {
    location = new PVector(20,20);
    velocity = new PVector(4,0);
    }

    void move(){
    location.add(velocity);
    }

    void turn(){
    if (location.x>width-20){
    velocity.x=0;
    velocity.y=4;
    }
    if (location.y>height-20){
    velocity.x=-4;
    velocity.y=0;
    }
    if (location.x<20){
    velocity.x=0;
    velocity.y=-4;
    }
    if (location.y<20){
    velocity.x=4;
    velocity.y=0;
    }
    }

    void display(){
    fill(0);
    ellipse(location.x,location.y,20,20);
    }
    }

    Can u tell me why ball is leaving my screen after 1st "run".

  11. Djz Aamir Avatar

    Thank you Sir , someday i am gonna meet you and have a cup of tea with you 🙂

  12. clemente ferrer Avatar

    I really like your wallpaper. Where did you find it?

  13. tarnos12 Avatar

    Where do you clear your canvas? In my processing window I need to do it manually in a draw function.

  14. Paul B Avatar

    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("-—-");

    }

  15. David James ASMR Avatar

    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!

  16. Damilola Olagundoye Avatar

    how do i write this in my p5 ide?

  17. Shockszzbyyous Avatar

    there is a way to override the + operater in java right?

  18. Lewis Shemery Avatar

    is a vector essentially a slope?

  19. Gen Valencia Avatar

    This guy makes me feel like it's okay to be as awkward as I am and it's so comforting

  20. jowadul kader Avatar

    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

  21. Yasamin Khalilbeigikhameneh Avatar

    U made processing funny and lovely for me

  22. Conan Richard Avatar

    I love the way you teach Thank you for doing this , and also the explaining you do makes it easier to understand . Than You

  23. corey333p Avatar

    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 800×600 so I expected values of location.x and location.y to be 400 and 300 respectively

  24. ShaolinMonkster Avatar

    Why this channel has only 36k subs.
    You are awesome

  25. Wei Zheng Avatar

    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!

  26. cimmik Avatar

    I get this error when I tries to declare "private PVector position;":
    Cannot find a class or type named "PVector"

  27. Jullienne Vilela Avatar

    could you replace my programming tutorial teacher??

  28. Kevin Bay Avatar

    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?

  29. Rob Thompson Avatar

    Thank you very much.Thats what I call infotainment! Keep going Mr Shiffman

  30. GonzoGonschi Avatar

    super excellent and entertaining presentation. Thank you so much for the effort Daniel!

  31. GonzoGonschi Avatar

    super excellent and entertaining presentation. Thank you so much for the effort Daniel!

Leave a Reply

Your email address will not be published. Required fields are marked *