5.1: Function Basics – p5.js Tutorial

[ad_1]
This video covers the basics of writing your own functions in JavaScript. What does it mean to define and call your own function? How can this make a program more modular?

Next video:

Support this channel on Patreon:

Contact:

Send me your questions and coding challenges!:

Link to code on Github:

p5.js:

For More p5.js Videos:

Help us caption & translate this video!


Posted

in

by

Tags:

Comments

14 responses to “5.1: Function Basics – p5.js Tutorial”

  1. Alby Ally Avatar

    Shiffman, u are the best dude, have been subscribing to many youtube channels that teach programming, but for the 1st i hit an amazing channel.The way u make programming so fun with a lot of cool examples.

    Thanks sir

  2. Billy North Avatar

    Does anyone know how I can have ellipses falling from 0 on the Y axis at random places on the X axis but each time an ellipse hits the bottom of the screen (Y > height) another 2 ellipses fall?

    What function would this be, I can't manage to make it work with a for loop?

    Thanks

  3. bas fan Avatar

    as the videos on the playlist go on , yuo become more and more serious lol XD !! love your videos anyways and i am still watching the videos in the playlist in sequence !! love your videos !! hopefully, i wish , i will be finishing the playlist tomorrow or day after and i started just yesterday lol <-( that actually did happen and will be for whoever who reads this to figure out what i just said XD )

  4. ghj fghj Avatar

    Is it generally better practice to call the animation function before the display function (as in this video)? As it goes through draw here I understand that it calls move, bounce and display every frame so swapping the order around doesn't make any difference, but it terms of better practice, does it make much difference? Maybe just choose whether I prefer draw or animate first and then stick with that in future?

    For example – I would think of the above sketch as drawing it to screen first, then move the ball, then bounce the ball, so display(), move(), bounce(). Again I'm aware that in this case it makes 0 difference to the execution of the code because all three get called before draw 'draws' it to screen, but yeah – in terms of project workflow, is one generally more accepted than the other?

    Thanks for the help all 🙂

  5. That one NERD Avatar

    can anyone please answer me how to write nested function within a function? I mean in processing you just cancel the void and add a ";" after "()" to write nested functions but what about p5?

  6. Red_Psy Avatar

    Was there any significant reason in setting yspeed equal to -3 rather than 3 in the ball object? As long as you multiply it by -1 below, it should net the same result, correct? Or was it more like a habit – and if so, is it a good one?

    From what I can discern, it just makes the ball start 'upwards' rather than 'downwards'.

  7. Goel Avatar

    I almost never put a semi-colon at the end of the line, usually because I forget too and I'm now in the habit of it, but does it really matter? I don't get any errors, and it has no effect. Should I try harder to put one at the end of a line?

  8. Spencer S Avatar

    hits the corner!!! 7:52

  9. Spencer S Avatar

    me this entire video:
    /watch?v=RTwvbVbNMNw

  10. Luís Vieira Avatar

    Thank you so much for the videos! Your skills to explain these processes are awesome!
    One quick question:
    I do not get the same colors for the different elements of the syntax. Is that customization you did or the P5 editor version?

    Cheers!

  11. wang shihui Avatar

    thank you so much for the tutorials!

  12. Julian Puppo Avatar

    So. Setup and Draw are self-called functions . . ? Cause, you are never calling those functions. YET there they are.

  13. andrew kim Avatar

    what sort of parameters can Setup and Draw take?

  14. deepank verma Avatar

    Can we also have nested functions in p5?
    BTW I was going through your <shiffman.net/teaching/a2z/week1/ > which is awesome, but there is no link for 2nd week in that page. Parallely I was also going through Nature of Code, which is like bible for physics operations for one who likes processing. Implementing these ideas in p5 will have no effect, I suppose. OR are there any differences?

Leave a Reply

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