Тёмный

7.4: Mouse Interaction with Objects - p5.js Tutorial 

The Coding Train
Подписаться 1,7 млн
Просмотров 231 тыс.
50% 1

How can an object interact with the mouse? This video looks at how you can implement basic mouse interaction (rollover, mousePressed) with your own code and HTML5 canvas.
💻 Code: thecodingtrain.com/Tutorials/...
🎥 Next video: • 7.5: Removing Objects ...
Links discussed in this video:
🎥HTML playlist: • 8: HTML / CSS / DOM - ...
🚂 Website: thecodingtrain.com/
👾 Share Your Creation! thecodingtrain.com/Guides/com...
🚩 Suggest Topics: github.com/CodingTrain/Rainbo...
💡 GitHub: github.com/CodingTrain
💬 Discord: / discord
💖 Membership: ru-vid.comjoin
🛒 Store: standard.tv/codingtrain
📚 Books: www.amazon.com/shop/thecoding...
🖋️ Twitter: / thecodingtrain
📸 Instagram: / the.coding.train
🎥 Coding Challenges: • Coding Challenges
🎥 Intro to Programming: • Start learning here!
🔗 p5.js: p5js.org
🔗 p5.js Web Editor: editor.p5js.org/
🔗 Processing: processing.org
📄 Code of Conduct: github.com/CodingTrain/Code-o...

Опубликовано:

 

15 окт 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 183   
@oo0O08
@oo0O08 6 лет назад
Dan, just wanna compliment you on the smooth transition to the whiteboard with the marker flip.
@nazobanaguska
@nazobanaguska 4 года назад
I was just thinking the same how cool he flipped the marker.
@mrshurukan
@mrshurukan 6 лет назад
So I see you are telling story about basics again :D nice to see you care about newcomers! I'm, myself, really thankful to you for getting me into p5.js and Javascript! You are the most creative, intelligent and interesting to listen to person! Thank you for all of those amazing tutorials I still watch to this day, and good luck to all newcomers!
@justinsciullo3342
@justinsciullo3342 11 месяцев назад
i i i i don’t have a a a lot at mekzznow how mk😅ii😢 14:58 o i😢
@inventanew
@inventanew 6 лет назад
once again, a stellar production, this series is giving me a ton of ideas for art apps in the future
@LIGHTRAYMultimedia
@LIGHTRAYMultimedia 4 года назад
You are the best teacher ever! What energy! Joy! Competence! Congratulations, man! You make my day!
@mj9665
@mj9665 6 лет назад
he is so talkative and entertaining when alone. imagine him drunk and in a company of friends.
@AHTUNGERSAN
@AHTUNGERSAN 6 лет назад
I'm really fond of your way of teaching and explaining complicated things in a fun way. I love your videos and wish you luck doing this in future! :)
@Hunar1997
@Hunar1997 6 лет назад
What does it mean to be a bubble
@TheCodingTrain
@TheCodingTrain 6 лет назад
Someday I will discover the true meaning.
@inventanew
@inventanew 6 лет назад
bubbles are function (giggly) and class {bouncy}
@zayanwatchel8780
@zayanwatchel8780 6 лет назад
john blakley no classes in JavaScript
@ronaldortiz7173
@ronaldortiz7173 4 года назад
@@zayanwatchel8780 there are, now in es6
@kosmic000
@kosmic000 5 лет назад
thank you so much dan for these top class videos , they help me in my programming career though my tools are not visual like yours but i use your courses to improve my algorithm skills and how to think and apply algorithms for problem solving , i so much appreciate ur hard work,,greetings and love form Egypt
@jhonandresmedina
@jhonandresmedina 6 лет назад
Hey congratulations for all your good videos, really helpful!! Just one question that comes to my mind: I'm seeing you registered the mousePressed event each time for all the bubbles in the array, how efficient is that? is there any other way to achieve the same thing? thanks!
@JowJoris
@JowJoris 6 лет назад
This is so helpfull for my school project where I need to select objects and deselect them, also looking forward to the next video where you show us how to delete from an array, also needed for the project. Great video again!
@begga9682
@begga9682 6 лет назад
JowJoris First, find the index of the element you want to remove: var array = [2, 5, 9]; var index = array.indexOf(5); Note: browser support for indexOf is limited; it is not supported in Internet Explorer 7 and 8. Then remove it with splice: if (index > -1) { array.splice(index, 1); } The second parameter of splice is the number of elements to remove. Note thatsplice modifies the array in place and returns a new array containing the elements that have been removed.
@JowJoris
@JowJoris 6 лет назад
Thanks for your help! Although I am coding in processing, I understand what you mean and will use it.
@cubbybear8322
@cubbybear8322 4 года назад
Hahah I absolutely love this guy,what an absolute hero!!
@simshp
@simshp 4 года назад
Thanks for your classes .. informative and entertaining !!
@hoaihung3189
@hoaihung3189 2 года назад
thanks for the useful lessons, by the way, you are better than all my previous teachers Thanks you so much!!!
@TheLegoJungle
@TheLegoJungle 6 лет назад
0:01 What the hell XD Gotta love these videos!
@albertoarielarce2982
@albertoarielarce2982 4 года назад
I'm learning a lot with you, thanks!
@seokyungkim7837
@seokyungkim7837 6 лет назад
Hey Daniel, your tutorial is amazing. I am learning a lot from you! Maybe it will be nicer if there is a written code of each tutorial, so that I can review and find some corrections! :)
@TheCodingTrain
@TheCodingTrain 6 лет назад
There is! github.com/CodingTrain/Rainbow-Code
@lucywilliams256
@lucywilliams256 4 года назад
Thank you so much! Your videos are great
@RameenFallschirmjager
@RameenFallschirmjager 5 лет назад
this little sweet video is a great piece of work to explain polymorphism and oop design patterns. Shiffman, you are a hell of a guy! I bestow the presidency of united stated to you!
@vidalexperience
@vidalexperience 6 лет назад
Yo dude, that''s sick!
@brotherlui5956
@brotherlui5956 6 лет назад
(d < this.r) doesn't work anymore. Now it has to be (d < int(this.r/2)) as according to p5.js reference the 3rd and 4th argument of ellipse() are the width and height and NOT the radius.
@Anonimousxz
@Anonimousxz 4 года назад
Of course it works buddy, see: editor.p5js.org/willianxz/full/dFZVe4bpI You must have implemented it wrong.
@Fun-Planet
@Fun-Planet 4 года назад
It was never the radius.
@hoangminhnguyen2191
@hoangminhnguyen2191 5 лет назад
So entertaining!! And still learn a lot :v thank u very much sir
@ahmedr.
@ahmedr. 4 года назад
I guess , you should make the code for the clicked function like this : if (d
@ELBARTOmovies
@ELBARTOmovies Год назад
Really great course!
@chandraprakashshukla413
@chandraprakashshukla413 4 года назад
What will we use instead of the radius of the circle if we workout the same thing with a square shaped( bubble)?
@funkyb6598
@funkyb6598 6 лет назад
Is it bad of me to want you to forget a dot in order to hear the "this dot" song?
@lorenzmeier8020
@lorenzmeier8020 3 года назад
I love your tutorials! 10:50
@oscarurrego9662
@oscarurrego9662 5 лет назад
well that works easy for bubbles (circles) but I'm not quite sure how to decide whether the point is in or out other kinds of shapes, maybe not so complex ones, maybe just regular polygons, could you help me with that? :)
@alonattar3836
@alonattar3836 6 лет назад
Great work
@racethegamer7101
@racethegamer7101 4 года назад
Please tell if we can write a function or a command regarding the visibility of each individual object?
@Bunglay
@Bunglay 6 лет назад
8:51 - 9:06 best part of the whole serie
@agata0214
@agata0214 4 года назад
Could you explain why it is necessary to put bubbles.push(b) in setup(), instead of draw()?
@Fun-Planet
@Fun-Planet 4 года назад
Draw runs infinitely many times, so after a few frames you would have 20 million bubbles.
@navneethsuresh9995
@navneethsuresh9995 6 лет назад
hey coding train i have a real big trouble with p5:c. I have brackets installed before p5 so when i open the p5 file in winrar it immediately opens brackets with some set of code. what should i do now to get p5 as a separate application ?(I am using windows 8)plz help me...
@SciStone
@SciStone 3 года назад
How can i tell if my mouse is hovering over a sphere in 3D space? i can get the screenX and screenY of the spheres location but the size of the sphere on the screen is different depending on the distance from the camera..
@RameenFallschirmjager
@RameenFallschirmjager 5 лет назад
cloning humans must become legal! because we need more people like this dude! just one won't suffice our educational needs!
@borimirdimitrov473
@borimirdimitrov473 Год назад
hi coding train i just have a question.Shall we be able to make such code with the moving circles and everything by the time we have come to this video?
@vaniaoliveira2686
@vaniaoliveira2686 4 года назад
Hello :) I'm new here! I'm creating an online tool to manipulate type with p5.js, is it possible to do this with text? It might sound a little bit basic (idk ahah) but I'm still learning and I'm a graphic designer transitioning to the programming world! Also, how do I do this with a square? Thanks! I love your videos!
@najibsaad5765
@najibsaad5765 6 лет назад
Hey Dan, I tried to use Processing and p5 and I couldn't get the setup correctly can you please make a video explaining how to set up everything (to get the same as you have) because I really want to go along with you in coding. Thanks :)
@Kino-Imsureq
@Kino-Imsureq 6 лет назад
in the p5 setup function, you need to create a canvas using createCanvas(width,height). then you can use the draw function.
@Anonimousxz
@Anonimousxz 4 года назад
My friend, you were to earning as a soccer player instead of them !!, alial all the teachers who teach like you !! You enrich society !! Know that people like me from Brazil are here seeing you !! O/
@subeshbhandari1652
@subeshbhandari1652 6 лет назад
What if two bubbles lie in the same point? Wont they be highlighted at the same time? I got that error. And while making the same process for drag the mouse pointer goes out of the circle and it wont drag.
@MemeticArts
@MemeticArts 3 года назад
you would need to set a global flag to detect if clicked has been called. though it might seem simultaneous, technically there is a sequence, so you should be able to prevent the second event from firing.
@eltonbergruh8339
@eltonbergruh8339 6 лет назад
Love your vids! But could you use Processing again once in a while? I'm a Processing person. I know the concepts are the same, but still... Thanks!
@bernardnoctor5627
@bernardnoctor5627 3 года назад
Very good he's very entertaining
@shwetajain7027
@shwetajain7027 3 года назад
Hi, can you please tell how can get boundary of shape when mouse is dragged over its boundary. Please reply
@eboubaker3722
@eboubaker3722 5 лет назад
@The Coding Train 8:18 i did that code without using the dist() function : you just put conolse.log in that clicked() function : and in mousePressed do : function mousePressed() { if (abs(bubble.x - mouseX) < bubble.r && abs(bubble.y - mouseY) < bubble.r) { bubble.clicked(); } }
@Fun-Planet
@Fun-Planet 4 года назад
That's the dist function!
@eboubaker3722
@eboubaker3722 4 года назад
@@Fun-Planet after 1 year of being a programmer i can't put it in my mind that i am the one who commented this, what a shame
@julezzzzzzz
@julezzzzzzz 6 лет назад
It would be cool to see how one can check the cklicked state for non circular shapes with p5js.
@HarshTalpada
@HarshTalpada 6 лет назад
That is actually easy, for closed body objects, as you already know the area covered by the shape. instead of checking the difference between the mouse and the radius. You just have to check, if the mouse is within the maximum and minimum value for your shape.
@TheVengeur69
@TheVengeur69 6 лет назад
Harsh Talpada if it's not to much to ask, can you make an example for a rectangle ?
@HarshTalpada
@HarshTalpada 6 лет назад
Sure, check this sketch, I have not documented it, but feel free to ask me if it doesn't work or you do not understand it. Click the individual rect to start and stop rotation. alpha.editor.p5js.org/neoxharsh/sketches/SkywecP2-
@loukask.9111
@loukask.9111 6 лет назад
NICE THE VID CAME :D
@letthemcode7199
@letthemcode7199 Год назад
any chance you find it increadible hard to fit a canvas into a whole page with borders on the parent elements? as soon as i add any padding but make the canvas child 100%, it rockets over the screen size
@k.v.narasimhamurthy3455
@k.v.narasimhamurthy3455 6 лет назад
he's alive.
@anacondong
@anacondong 6 лет назад
Thanks its so fun
@slemif
@slemif 2 года назад
how do you add objects to an array in order like in a line rather than randomly
@anonymoussloth6687
@anonymoussloth6687 3 года назад
How can I make it so that the bubbles collide (like balls) instead of overlap. Futher, what if I want them to pop when they collide. Finally, is it possible to drag a bubble and drop it in another place?
@ImBananas4
@ImBananas4 6 лет назад
Hope you do the triangle one day cheers
@notAvn
@notAvn 4 года назад
i wish someone loved me as much as this guy loves his bubbles
@Kino-Imsureq
@Kino-Imsureq 6 лет назад
dist is kinda usefull.. dist(x1,y1,x2,y2) = sqrt((x1-x2)^2 + (y1-y2)^2)
@abhiroopkar202
@abhiroopkar202 4 года назад
yeah
@clairesong3341
@clairesong3341 4 года назад
You are amazing!
@travellingstranger3378
@travellingstranger3378 2 года назад
...works fine for a circle but what to do for one of those complicated poligons?
@QuinnWaters
@QuinnWaters 6 лет назад
i guess my "this.r" was not the radius so i did: if (d < (this.r/2)) and it seemed to work! thank you so much for these videos!!!!
@Anonimousxz
@Anonimousxz 4 года назад
Of course it works buddy, see: editor.p5js.org/willianxz/full/dFZVe4bpI You must have implemented it wrong.
@filipkendes1866
@filipkendes1866 6 лет назад
Use of the orientation sensor is deprecated. p5.js:46412:6 Use of the motion sensor is deprecated. p5.js:46412:6 I get these Warnings. What could this be?
@sharath2273
@sharath2273 4 года назад
It depends on your code. If you used the sensors in some way, it is just saying that it isno longer supported.
@dustinmarino5096
@dustinmarino5096 5 лет назад
successfully did the exercise in this video to change them to rectangles and have them turn on and off and apparently bubbles are rectnagles now according to my code! here's my code for it: let bubbles = []; function setup() { createCanvas(600,400) for (let i = 0; i < 10; i++) { bubbles[i] = new Bubble(random(0, width), random(0, height), random(width), random(height)) } } function draw() { background(0) for (let i = 0; i < bubbles.length; i++) { bubbles[i].move() bubbles[i].show() } } function mousePressed() { for (i = 0; i < bubbles.length; i++) { bubbles[i].clicked(mouseX, mouseY) } } class Bubble { constructor(x,y, x2, y2) { this.x = x this.y = y this.x2 = x2 this.y2 = y2 this.brightness = 0 } clicked(x, y) { let d = dist(x, y, this.x, this.y) if (mouseX > this.x && mouseX < this.x + this.x2 && mouseY > this.y && mouseY < this.y + this.y2 && this.brightness == 0) { this.brightness = 255 //console.log("CLICKED ON BUBBLE") } else if (mouseX > this.x && mouseX < this.x + this.x2 && mouseY > this.y && mouseY < this.y + this.y2 && this.brightness == 255) { this.brightness = 0 } } move() { this.x = this.x + random(-5,5) this.y = this.y + random(-5,5) } show() { stroke(255) strokeWeight(4) fill(this.brightness, 125) rect(this.x, this.y, this.x2, this.y2) } }
@danilovujicic9380
@danilovujicic9380 2 года назад
how could I use the same method just with rects? I tried to find the tutorial but I couldn't find it.... thanks in advance :)
@dwikristianto
@dwikristianto 2 года назад
"object only know something inside, not the world outside" it's good point.
@rbotdance
@rbotdance 6 лет назад
where is the previous video? I don't know where the word "let" comes from?
@ophello
@ophello 6 лет назад
rbotdance yeah...he kind of missed that. I think let is a stand-in for var. let is a local variable, var is global.
@streetfashiontv9149
@streetfashiontv9149 4 года назад
I recorded these in the past but for you it'll be the future....deep! Thats a mind f@$k...
@maskman4821
@maskman4821 6 лет назад
Sir, I tried to do the exercise you mentioned at the end of this tutorial, when mouseover on bubble changes the shape to rectangle. However I found that p5 doesn't have a particular function called 'function mouseOver(){}', instead it has a mouseover() function like an event and the example I found is weird and it is defined in setup function. I have tried a lot of ways but just can't get it done. If there is 'function mouseOver(){}' it would be simple and easy to accomplish this task, but it has not. So I wonder if you can give me a hand to solve this problem that you want us to finish? if there is 'function mouseOver(){}', I would do as below: function mouseOver(){ for(let i = 0; i < bubbles.length; i++){ let x = random(width); let y = random(height); let w = random(10, 50); let h = random(10, 50); bubbles[i].beRectangle(x, y, w, h); } } class Bubble{ ... beRectangle(x, y, w, h){ stroke(255); noFill(); rect(x, y, w, h); } } that is the way you teached, but there is no such a pre-built function, and the example p5.js talked about I don't know how to implement it!
@normajeanchariot
@normajeanchariot 4 года назад
I'm also having this problem. To change the color of a bubble to white when you move the mouse over it, I think you need to create an if statement that basically says: for (let i = 0; i < 10; i++) { let d = (mouseX, mouseY, bubbles[i].x,bubbles[i].y) if (d < bubbles[i].r) { bubbles[i].brightness = 255 } } HOWEVER, this doesn't work for me. Apparently "bubbles[i].x", "bubbles[i].y", "bubbles[i].r" and "bubbles[i].brightness" are not defined, so I guess I should be using a different way to refer to them? I've had this problem before, where sometimes bubbles[i].x will work and other times it says it's undefined.
@lukecarey7244
@lukecarey7244 3 года назад
Hello! Was wondering if anybody could help me out here, How does this work with irregularly/curved shapes? I have a simple design - a rectangular window and it's raining outside. The rain particles only show if within the rect, no bother! However, a rectangle is a bit stiff so I have curved the edges, though now rain appears outside the 'window' around the edges, and I'm strugling to find a solution to this. Any help would be greatly appreciated! P.S. Your videos are incredible! I have learned so much from you in such little time, thank you so much! Best teacher out there
@janssenuy9397
@janssenuy9397 4 года назад
Can you make an android app using p5? I love your channel and you inspire me to code. I learned a lot from every video i watch from you. I am new to coding and wanted to make a simple learning language using p5. I am struggling creating the main menu with interactive rectangles with text (buttons actually) and then I realized something. Maybe p5 cant make android apps or am i just not good enough?
@TheCodingTrain
@TheCodingTrain 4 года назад
Thank you for your nice comments ! I recommend you join our Discord where you can ask code related questions to the community : discord.gg/hPuGy2g - The Coding Train Team
@matthewsnyder1079
@matthewsnyder1079 3 года назад
Can someone tell me how to apply the radius part of the circle function to a square? Am struggling. thanks
@kobod
@kobod 3 года назад
I used: rectMode(RADIUS); and then kept the conditions the same so: if (d < this.r) {} and for the rect I put: rect(this.x, this.y, this.r, this.r); It works fine, but it doesn't work for the corners of the square since the radius from the center of the square to the corner of the square is obviously bigger than the radius from the center to a side in the middle of the square.
@jocegoss
@jocegoss Год назад
What would this look like with triangles instead?
@michaelpaquette
@michaelpaquette Год назад
Hi Daniel - Can you please point me in the right direction on how to do a mouse over with object label on a shape that is moving and has transformed....for example - I would like to add a label to my p5 planet in my drawn solar system...how do I add a mouse over on a moving planet type thing.
@michaelpaquette
@michaelpaquette Год назад
Can I access to shape's x and y coordinate after transform is applied ?
@kimina310
@kimina310 6 лет назад
Hey there internet surfer, noob question here How can i get a p5 sketch as a background for a webpage?
@fabianbosiger61
@fabianbosiger61 6 лет назад
in the html page create a div, give it an id and make sure it is fixed on the top left border like this: in the p5js sketch add this in the setup function: var canvas = createCanvas(windowWidth,windowHeight); //
@wedercoliver
@wedercoliver 5 лет назад
I just made this with forEach
@HarshTalpada
@HarshTalpada 6 лет назад
Hello Daniel, I guess I have asked you the same in the comments on one of your previous video, so I guess it was because of me. (Swag smiley). Well, this is indeed good, but I would like to know how do I apply rotate translation on multiple rectangles, without rotating the entire canvas, and just all the individual rectangles.
@TheCodingTrain
@TheCodingTrain 6 лет назад
Take a look at ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-o9sgjuh-CBM.html
@Neogenum
@Neogenum 5 лет назад
Does anyone have a link to the code for this lesson? I've looked all over the github and I cant seem to find it. I've tried writing it exactly as it is in the video and it doesnt work for some reason.
@TheCodingTrain
@TheCodingTrain 5 лет назад
Apologies! It's here: github.com/CodingTrain/website/tree/master/Tutorials/P5JS/p5.js/07 I need to redo these descriptions and put the code in the web editor for easy access.
@chanitnanthphadungnanonth1615
@chanitnanthphadungnanonth1615 2 года назад
Can Anyone help me out if I want to do the rectangle (I used Center as a rectMode) instead of circle? How can I write it with the mouse clicked?
@chanitnanthphadungnanonth1615
@chanitnanthphadungnanonth1615 2 года назад
also with the class TT
@oscantes
@oscantes 5 лет назад
Before you said "there is a function for this, called dist()" at 6:58, I thought that you'll write an algorithm for it and I guessed something like; if (mouseX < this.x + (r/2) && mouseX > this.x - (r/2) && mouseY < this.y + (r/2) && mouseY > this.y - (r/2) { console.log("rectangular clicked!"); } Boy I was so wrong :D But I have a feeling that my algorithm will be handy if the object is rectangular.
@MrDeathinstict
@MrDeathinstict 6 лет назад
ok i have a question: lets say you create a class line how you create a polyline, same as the CAD software do? ps. when you press the mouse you add another point or line to the array, but how you can draw a line from the last point to the future point(not pressed yet...) but the canvas draws the line moving alongside the mouse.
@thisismyalias
@thisismyalias 6 лет назад
line(mouseX, mouseY, lastAnchor.x, lastAnchor.y)
@HumbertoRincon
@HumbertoRincon 6 лет назад
In setup: Declare an empty array with posX and posY. In draw: As you click on the canvas, store that particular mouseX and mouseY in the array. If you have at least one item in the array you can draw a line from that last pos to the current mouseX and mouseY which will draw a line dynamically as you move the mouse. If you click again, store the new pos, draw a line between you array's previous points and repeat. A part of this was shown already in another tutorial, cannot remember which one.
@SimoSimo-xm9de
@SimoSimo-xm9de 6 лет назад
do you do your live streams in youtube, if not give me the link pllz, I love you btw, you are awesome
@slowdown_
@slowdown_ 6 лет назад
yes he does it on yt. he announces them here also
@SimoSimo-xm9de
@SimoSimo-xm9de 6 лет назад
thanks man
@ibrarahmed3476
@ibrarahmed3476 6 лет назад
Hi sir I like your channel and videos . Your videos are very helpful . I try to make a kids fun program like (LND version 5) in processing i3. So i need a little help .......
@salmanmaxee8bpyt900
@salmanmaxee8bpyt900 3 года назад
i am, your big fan sir.love from pakistan
@ka26rider40
@ka26rider40 3 года назад
can anyone tell how we we can check for triangle.
@amirulidzham3686
@amirulidzham3686 5 лет назад
I don't get it. I did like almost looking like yours. But what happened is all my object turned color that I've defined. I believe the issue is in my array and the attribute that I've defined. So how do I supposed to do?
@TheCodingTrain
@TheCodingTrain 5 лет назад
Would you mind asking at discourse.processing.org/! It's a better platform for Processing and p5.js related code questions. You can share code there easily! Feel free to link from here to your post.
@freddymeng
@freddymeng 4 года назад
does anyone know why it says cannot read property "move" of undefined
@kremlinkrusher2551
@kremlinkrusher2551 3 года назад
Yes I ran into the same problem. In function setup() he renames "let b = ...." to just "bubble =...." he removed let. Remember that "let" is block scope or only stores for what is inside the {}. Therefor, when you use 'let bubble = ;' you haven't stored it for use outside the {}. I could be wrong but I think that is what happened. I fixed it that way and mine ran finally.
@joeninocainday6568
@joeninocainday6568 Год назад
How do you implement mouse interaction in 3D
@bulverismo
@bulverismo 6 лет назад
i really love you kkkkkkk
@pastuh
@pastuh 3 года назад
show() is reserved function by p5js
@spamaccount4474
@spamaccount4474 4 года назад
But what if u want to interact with a key
@jeremylindsay1682
@jeremylindsay1682 6 лет назад
2:57 "Peel away from the array"
@jacobfruth4769
@jacobfruth4769 5 лет назад
can you PLEAS give me a link to this code
@mehediabdullah9852
@mehediabdullah9852 6 лет назад
yesterday i saw there is 7.9 and 7.10 but today i lost that track.... !!!!!! confused...
@TheCodingTrain
@TheCodingTrain 6 лет назад
7.9 and 7.10 are now numbered 7.7 and 7.8. I am updating this playlist at the moment, that's why it gets a little confusing some times. The important thing to remember is that the same topics are being covered, they are just explained in a more effective and updated way. Sorry about that! -MB
@williamtaylor6074
@williamtaylor6074 6 лет назад
I have a strange bug that makes it so when I click a bubble a different bubble changes colour... if there is just one in the array then it changes colour but if there are two then the wrong one will change colour... Any ideas?! It's driving me mad!
@TheCodingTrain
@TheCodingTrain 6 лет назад
Would you mind asking at forum.processing.org/? It's a better platform for Processing and p5.js related code questions. You can share code there easily! Feel free to link from here to your post.
@williamtaylor6074
@williamtaylor6074 6 лет назад
Wow speedy response! Thank you, I certainly will do! Just also, I've been following this playlist and it's amazing! Can't thank you enough!
@MrArthean
@MrArthean 6 лет назад
Cx in the chat bois 7:13
@EhKurd
@EhKurd 6 лет назад
YAHOOOOOOOOOOO
@Chickenwing38nigeria
@Chickenwing38nigeria 6 лет назад
Monarkh cmonBruh
@Frederic_Chopin.
@Frederic_Chopin. 5 лет назад
lmao
@siddhantjain2591
@siddhantjain2591 4 года назад
Hello sir, I have been following your channel for about a month now and I don't think I need to go anywhere else to learn JS and ML, but I'm quite confused right now. Your channel has over 1060 videos and I am about to complete this playlist but I also noticed videos on p5js tutorial up to 17.x series can you please help me by guiding me for a smooth sequential flow :) Hope is all I have right now :) Thus hoping, you notice this comment
@leali1200
@leali1200 5 лет назад
I change bubble into box (3D with WEBGL)and ┭┮﹏┭┮ it don't work (it didn't excite the move and the show in WEBGL ?)thankyou Coding guy ……
@calebsherman886
@calebsherman886 5 лет назад
14:32 You could say you POP the bubbles. ;D
@MemeticArts
@MemeticArts 3 года назад
I thought about that too . . . and actually makes sense considering that in JavaScript, "pop" is also a function that removes the last element of an array!
@ukaszdebowski6539
@ukaszdebowski6539 6 лет назад
(WARNING - LONG COMMENT) I have a little problem with my program. I've tried to modify the one that you've showed us the way that it should only create new bubbles and add them to the array, when you click the mouse and also you are not hovering over any other bubble. And if you are hovering over any other bubble and you click the mouse, it should only change the color of that particular bubble. It works almost perfectly, but when I have more then 1 bubble in the array, it seems like it only checks if I'm hovering the mouse over the newest bubble, and when I click on some older one, not only does it change the color of that bubble (which is what I want), but also creates a new bubble on top (which is what I don't want to happen, unless I click somewhere, where there is no bubble). Can you look at the code below and tell me what did I miss? let bubbles = []; let isMouseOver; function setup() { createCanvas(500, 400); isMouseOver = false; } function draw() { background(150); for (i = 0; i < bubbles.length; i++) { bubbles[i].show(); bubbles[i].move(); bubbles[i].edges(); } } function mousePressed() { for (i = 0; i < bubbles.length; i++) { bubbles[i].over(mouseX, mouseY); bubbles[i].changeColor(); } if (isMouseOver == false) { let r = random(10, 40); let b = new Bubble(mouseX, mouseY, r, 150); bubbles.push(b); } } class Bubble { constructor(x, y, r, color) { this.x = x; this.y = y; this.r = r; this.c = color; } move() { this.x = this.x + random(-3,3); this.y = this.y + random(-3,3); } show() { strokeWeight(2); fill(this.c, 125); ellipse(this.x, this.y, this.r*2); } edges() { if ((this.x - this.r) < 0) this.x = this.r; if ((this.x + this.r) > width) this.x = width-this.r; if ((this.y - this.r) < 0) this.y = this.r; if ((this.y + this.r) > height) this.y = height-this.r; } over() { let d = dist(mouseX, mouseY, this.x, this.y); if (d < this.r) { isMouseOver = true; print("TRUE"); } else { isMouseOver = false; print("FALSE"); } } changeColor(){ if (isMouseOver && this.c == 150) { this.c = 220; } else if (isMouseOver && this.c == 220) { this.c = 150; } } }
@ukaszdebowski6539
@ukaszdebowski6539 6 лет назад
For anyone interested - I've worked out the problem by modifying the if statement that was responsible for checking if the mouse is over any bubble. I've changed it to check, if any of the bubbles has its color changed, and if no, create another bubble (that required modyfing the changeColor() function to have another variable 'changedColor' in it that changes its value to true, if the change happend. And if the change didn't happen, the program resets the value of this variable everytime the mousePressed function is called). Here is the properly working version of the "game": let bubbles = []; let isMouseOver; let changedColor; let numOfBubbles = 1; function setup() { createCanvas(500, 400); isMouseOver = false; for (i = 0; i width) this.x = width-this.r; if ((this.y - this.r) < 0) this.y = this.r; if ((this.y + this.r) > height) this.y = height-this.r; } over(px, py) { let d = dist(px, py, this.x, this.y); if (d < this.r) { isMouseOver = true; print("TRUE"); } else { isMouseOver = false; print("FALSE"); } } changeColor() { if (isMouseOver && this.c == 150) { this.c = 220; changedColor = true; print("CHANGED COLOR"); } else if (isMouseOver && this.c == 220) { this.c = 150; changedColor = true; print("CHANGED COLOR"); } } }
@angelcaru
@angelcaru 4 года назад
over(px, py) { let d = dist(px, py, this.x, this.y); isMouseOver = d < this.r; print(String(d < this.r).toUpperCase()); }
@01234567897298
@01234567897298 5 лет назад
WISH YOU HAVE THE MOUSE INTERACTIONS ON PROCESSING BESIDES OF P5.JS.
@Disillusioned_one
@Disillusioned_one 6 лет назад
Who's going to burst his bubble, not me.
@rbotdance
@rbotdance 6 лет назад
How do I know if the mouse is inside a square?
@TheCodingTrain
@TheCodingTrain 6 лет назад
Use an if statement and check the square boundaries!
@rbotdance
@rbotdance 6 лет назад
thank you for answering! :D I wrote this code for squares, I don´t know if there's an easier way to do it: if (mouseX>(this.x-this.width/2)&&mouseX(this.y-this.height/2)&&mouseY
@drunkenmonkey1457
@drunkenmonkey1457 6 лет назад
if (mouseX > this.x && mouseX < this.x + this.width && mouseY > this.y && mouseY < this.y + this.height) Adding half the width/height to each side would mean you could get false positives, as you've made the boundaries twice the size of the rect, and the extra brackets aren't needed as they don't change the order of precedence, of course feel free to use them if you feel it makes it easier to read or whatever. But as Dan said you should probably use local variables and pass mouseX and mouseY to the function. Probably a bit late, but hopefully this helps.
@Canwegetsubswithnovideos-yy4gn
why doesn't mousePressed() work for me
@kite4792
@kite4792 2 года назад
00:15 lol!
@shwetajain7027
@shwetajain7027 3 года назад
Actually I want to do it for triangle and polygon
Далее
7.5: Removing Objects from Arrays - p5.js Tutorial
18:24
9.8: Random Circles with No Overlap - p5.js Tutorial
19:25
The Trump rally shooting from a photographer's POV
00:58
skibidi toilet 76 (part 2)
04:28
Просмотров 14 млн
JavaScript Pro Tips - Code This, NOT That
12:37
Просмотров 2,5 млн
Coding Challenge 166: ASCII Text Images
22:42
Просмотров 1,1 млн
Drag & Drop with Javascript in 4 minutes
3:58
Просмотров 23 тыс.
Learn JavaScript Touch Events In 17 Minutes
17:45
Просмотров 108 тыс.
Java MouseListener 🖱️
11:46
Просмотров 73 тыс.
Unlocking your CPU cores in Python (multiprocessing)
12:16
Python Decorators in 15 Minutes
15:14
Просмотров 431 тыс.