2.1: Variables in p5.js (mouseX, mouseY) – p5.js Tutorial

[ad_1]
In this video, I introduce the concept of variables in p5.js. The setup() and draw() functions are covered as well as mouseX and mouseY.

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

39 responses to “2.1: Variables in p5.js (mouseX, mouseY) – p5.js Tutorial”

  1. Mario Hui Avatar

    Oh man, you are a good teacher as you are passionate about it !!! Thanks man 🙂

  2. sujith john Avatar

    Thank you very much for these classes. Is web scraping possible using p5? Do you have any videos on web scraping using Nodejs

  3. Qiang John Wang Avatar

    thiss issss ammmaaazing

  4. Ishan Dave Avatar

    The only programming languages I know are c,c++ and java, and trust me if you want to make a Paint program in any of them its a hell lot of work. This is a really powerful language indeed.

  5. ylham eresov Avatar

    Guys check out what i made with this tutorial XDXDXD https://codepen.io/ylham/pen/mWyxoZ

  6. Se2b11 Avatar

    you're the best daniel!

  7. crashonthehumble Avatar

    Thank you for these lecture series. How are these functions running without being called?

  8. Nebrok Red Avatar

    For some reason when I play the program, I get a white screen instead of what my code is meant to output. I have checked the syntax multiple times and to no prevail. When I refresh the window occasionally the background colour comes up but nothing else. Can someone help?!

  9. Ramiro Federico Gonzalez Avatar

    the fastest twelve minutes in my youtube life! You are a great teacher Daniel, thank you very much!

  10. Greg Bowler Avatar

    Your videos are really inspiring, if only other teachers/lecturers had your enthusiasm and style.

  11. Noah Stone Avatar

    Was there a 1.5 tutorial? or did his lessons go from 1.4 to 2.1? Don't want to miss any.

  12. Danish Afiq Avatar

    my mousePressed function doesnt work. help

  13. T 3 Avatar

    0 dislikes? lol

  14. Random Avatar

    nice
    but feels like I'm supposed to understand by now how to write " if/when mouse is pressed then draw" but I don't :s

  15. Luca Knaack Avatar

    why is in every video out of this playlist always some kind of sirene noise in the background 😀

  16. Mr Ed Draws Avatar

    I've been watching Coding Rainbow for a few months. I coded as a kid in BASIC, Pascal and FORTRAN, but had to stop when new computers stop supporting the compiler and video calls. I took JAVA in college, but it wasn't as easy to understand as the older languages (for some reason). After watching the Beginner Videos, I was setup and coding in less than 30 minutes. Fantastic!! There's so many things I want to code, like cellular automata. Thanks, Daniel!!

  17. Saurabh Ambulkar Avatar

    can we do Serial port or USB port communication using p5.js as we are able to do in processing ?

  18. TechNerd01 Avatar

    I made this… But I'm not AT ALL happy with this… I would like to instead check the mouse over thingy more conveniently and efficiently… any tips??? Thanks!

    var brushSize = 10;
    var overButton;
    var brushColor;

    function setup(){
    createCanvas(640,360);
    background(255);
    brushColor = color(0,0,0);
    frameRate(100);

    var blue = 70;
    var green = 40;
    var red = 10;
    }

    function draw(){

    noStroke();

    fill(255,0,0);
    rect(10,10,20,20);

    fill(0,255,0);
    rect(10,40,20,20);

    fill(0,0,255);
    rect(10,70,20,20);

    if (mouseIsPressed) {
    fill(brushColor);
    ellipse(mouseX,mouseY,brushSize,brushSize);
    }
    }

    function mousePressed() {
    if (mouseX-10 < 20 && mouseY-10 < 20) {
    brushColor = color(255,0,0);
    } else if (mouseX-10 < 20 && mouseY-40 < 20) {
    brushColor = color(0,255,0);
    } else if (mouseX-10 < 20 && mouseY-70 < 20) {
    brushColor = color(0,0,255);
    }
    }

  19. Fu Yuan Avatar

    This is really interesting, I never know you can draw with programs such easily.

  20. Hitler Avatar

    why do we put this ; becuse i forgot to put it everywhere where it should be and the code still worked

  21. Zappis Yoman Avatar

    if i type:

    function draw() {
    if (mouseIsPressed) {
    noStroke();
    fill(120);
    ellipse(mouseX, mouseY, 25, 25);
    }
    if (keyCode == 32) {
    background(255);
    }
    }

    i cant start to draw again, how can i make it to draw again??

    srry for my english

  22. Zappis Yoman Avatar

    you is the best to make coding tuturials on YouTube

  23. cronnostiger64 Avatar

    Really good classes! p5.js is really easy to draw graphics, great for begginers!

  24. Reena Paranjape Avatar

    Awesome video Daniel. Just one question.
    When you run the program at 8:08 (same can be seen in 7:55) there is a circle already at the top left corner of the canvas. How do i get rid of that?

  25. Lam Sang Chu Avatar

    omg thank you so much for doing this

  26. SandyRocks Avatar

    Hello Daniel will this p5.js work with Phonegap ? For making mobile apps !

  27. Ya rk Avatar

    Thank you so much for this!

  28. Robert Terlaak Avatar

    Great fun to watch and I used it for my first project: http://macrobody.freevar.com/project_1/

  29. Yumi Arantes Avatar

    best teacher ever. thanks for the classes. im watching all.

  30. Poppo Avatar

    Your explainations are always very clear, i think i'll watch all the playlist of p5.js tutorials 😉

  31. Paul B Avatar

    Well I'm planning to use these films in my programming class next semester. I hope you're not planing om removing them.

  32. Roxanne Baril-Bédard Avatar

    you make everything seem just accessible and fun and silly. bless!

    excited to tame java into pritty stuff ( •̀ᄇ• ́)ﻭ✧

  33. dxxPacmanxxb Avatar

    But what if I have a website and I want to draw something above this HTML/PHP website using the p5.js ? How do I do this?

Leave a Reply

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