3.3: Else and Else if, AND and OR - p5.js Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ม.ค. 2025

ความคิดเห็น •

  • @sallymallat9264
    @sallymallat9264 4 ปีที่แล้ว +13

    I watched so many tutorials on processing and P5.js,, but I have to say, these are the very BEST. Thank you! Thank you! Thank you!

  • @BusyAsBee1738
    @BusyAsBee1738 5 ปีที่แล้ว +13

    these videos make me feel so smart even though the way u teach the concepts are so easy and simplistic. Before I thought Id try code and give it up because it seemed hard, but look at me now, months later and still learning...

  • @chrislos7944
    @chrislos7944 9 ปีที่แล้ว +55

    Hi Daniel,
    just wanted to say: Please keep up the good work. Love your tutorials. I'm coming more from a MaxMSP background. All of your examples are super well explained. Thanks for that. Would love to enjoy more of your lessons. Greetings from Berlin.

  • @kemikalreakt
    @kemikalreakt 8 ปีที่แล้ว +14

    Been coding for just over a year now, but your videos have made things 100% crystal clear. For someone who is much more of a visual learner these videos are the best thing out there for learning how to code, keep up the good work man!

    • @TheCodingTrain
      @TheCodingTrain  8 ปีที่แล้ว +7

      +kemikalreakt thank you so much. Makes me happy to hear and motivation to make more videos!

  • @lalomtz2000
    @lalomtz2000 6 ปีที่แล้ว +3

    the thing that amazes me is that when i feel like im half of the video done its already over, your tutorials are great!!!!!

  • @Enikoe
    @Enikoe 4 ปีที่แล้ว +2

    I just wanted to tell you how much I love your transitions when you go from the screen to the whiteboard!!! It is so smooth, as if you would change a room! And by the way, love your explanations, your humour and your detail, on all of youtube I havent seen one video that is so beginner friendly and not overwhelming!!!

  • @tarekmustafa2525
    @tarekmustafa2525 8 ปีที่แล้ว +1

    Your tutorials are amazing. Usually programming tutorials are boring and make me take a nap after few minutes but I finished your videos 1 to 11 in no time and feel still awake. I am glad I found you and learned about p5!

  • @sakthiramar6049
    @sakthiramar6049 6 ปีที่แล้ว

    Daniel how in the world do you teach us without making us get bored. You are a excellent teacher.

  • @Muffin--Man
    @Muffin--Man ปีที่แล้ว +1

    to fill the rectangle(x,y):
    function setup() {
    createCanvas(400, 400);
    }
    function draw() {
    background(220);
    strokeWeight(4);
    noFill();
    if ((mouseX >= 150) & (mouseX = 150) & (mouseY

  • @jenniferjuarez4253
    @jenniferjuarez4253 6 ปีที่แล้ว +1

    Thank you for being who you are! I am so glad I ran into your videos you make tutorials enjoyable and explain everything so well, something I couldn't find with other videos. Keep up the amazing work:D

  • @vaio007
    @vaio007 3 ปีที่แล้ว

    You are really a God sent teacher!! Makes it so interesting and simple!!

  • @namronromedlab5446
    @namronromedlab5446 8 ปีที่แล้ว +32

    Hi Dan, that 10 mins rule of yours never seems to happen XD
    but I liked it though because you won't stop until you explained everything that is needed in the video.
    thanks!!

  • @RameenFallschirmjager
    @RameenFallschirmjager 5 ปีที่แล้ว +1

    this man deserves a noble prize in pedagogy!

    • @mbrasseau
      @mbrasseau 5 ปีที่แล้ว

      I second that!

  • @jodiemenhenett2862
    @jodiemenhenett2862 3 ปีที่แล้ว

    Hi Dan, I love your tutorials/videos, they are helping me a heap with my coding and im getting better and better every time I watch one. Thanks!!

  • @byfab2917
    @byfab2917 8 ปีที่แล้ว +2

    Hello I don't know if you look your comments but i want to say you what your tutorials are very amazing! I'm french and i understand everythink and you are happy so don't borring! continue like that!!

  • @eti313
    @eti313 8 ปีที่แล้ว +5

    Great series! I'm learning a lot, and it's a good review/reinforcement of programming concepts. BTW, Instead of "speed = speed * -1;" you could write "speed = -speed;"

  • @pineappleplayz479
    @pineappleplayz479 4 ปีที่แล้ว +1

    best teacher ever !
    thanks !!

  • @josemiguelgonzalez2402
    @josemiguelgonzalez2402 6 ปีที่แล้ว +1

    Great tutorial !!!
    Greetings from Spain

  • @6stringcuber683
    @6stringcuber683 5 ปีที่แล้ว +42

    I thought we were gona be threatening the computer when it misbehaves

    • @snownkc9749
      @snownkc9749 4 ปีที่แล้ว

      that would be for training artificial intelligence lol
      thats for another video

  • @linkspry254
    @linkspry254 6 ปีที่แล้ว +1

    for the cube you can do
    var c = 600
    var cc = 400
    var r = 255
    var g = 0
    var b = 255
    var x = 300
    var y = 200
    function setup() {
    createCanvas(c, cc);
    }
    function draw() {
    background(0);
    rect(x, y, 100, 100)
    noFill()
    stroke(255)
    strokeWeight(10)
    if(mouseX < 400 && mouseX > 300 && mouseY > 200 && mouseY < 300) {
    fill(r, g, b)
    }
    }

  • @archierat9696
    @archierat9696 4 ปีที่แล้ว

    This is such a good series i love it so much thankyou for making it
    Love your channel!!!!!!!!!!!!!!

  • @adolfocarrillo248
    @adolfocarrillo248 7 ปีที่แล้ว +4

    great solution, I should say Genial!!!!! min 15:50

  • @hamzakhawar134
    @hamzakhawar134 ปีที่แล้ว

    best teaching skills 💗

  • @goldthumb
    @goldthumb 2 ปีที่แล้ว

    I watched Daniel's videos about Processing first because I was more comfortable with Java. I realized that I had to learn more JavaScript in p5js simply because there are more basic 3D shape in p5js than in Processing.

  • @nadbelieres
    @nadbelieres 8 ปีที่แล้ว +5

    dan you are amazingggggggg

  • @user-lb5mm4mz4t
    @user-lb5mm4mz4t 5 ปีที่แล้ว

    sir thank u for giving us this education
    and also thank u for making our future bright
    mgbu

  • @BajoMundoUnderground
    @BajoMundoUnderground 8 ปีที่แล้ว +2

    like the way u explain keep the good work thx

  • @valenchez9303
    @valenchez9303 2 ปีที่แล้ว +1

    10:00 AND, OR explanaition.

  • @SomuMsil
    @SomuMsil 5 หลายเดือนก่อน

    Your class is very nice😊

  • @SomuMsil
    @SomuMsil 5 หลายเดือนก่อน

    Your class is very nice

  • @caiocesar7084
    @caiocesar7084 7 ปีที่แล้ว

    Great work!!! I know the basics for C language before, but even if I am learning the same, your lessons are still really enjoyable! Thank you so much!

  • @Stalitic
    @Stalitic 8 หลายเดือนก่อน

    the 🕹 p5.js Web Editor Sketchs dont work anymore. i dont have the sketch as an example anymore

  • @ntburke4617
    @ntburke4617 6 ปีที่แล้ว

    Hi. I know that this video maybe is old, but I was learning p5..when i write the same code at 9:04 i get an error at the second if else.. if I put it as a comment I get an error at the final ELSE..it sais: "Expected an idetifier and instead saw 'else'. Expected an assignment or function call and instead saw an expression" Does somebody know the reason? I also tried to google it but no solution :(

    • @TheCodingTrain
      @TheCodingTrain  6 ปีที่แล้ว

      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.

  • @abdurrahmanrobin4915
    @abdurrahmanrobin4915 7 ปีที่แล้ว +19

    if ( you love programming ) {
    Do it
    } else {
    Try to love it !
    }

    • @sammyskye9498
      @sammyskye9498 6 ปีที่แล้ว

      SyntaxError: expected expression, got keyword 'else' (sketch: line 3)

    • @sorayagoga8417
      @sorayagoga8417 6 ปีที่แล้ว +1

      Compiler: Error Do you like programming is not defined

    • @sakthiramar6049
      @sakthiramar6049 6 ปีที่แล้ว

      var yes I love coding = 0,

  • @aronpop1447
    @aronpop1447 7 ปีที่แล้ว +1

    You say that as soon as one evaluates as true, it kicks out of the if statements and goes to the other code. That means that if you have 5 if else, and if one becomes true it doesent care about the rest. But in the video it goes through the every one of them.

    • @TheTubejunky
      @TheTubejunky 7 ปีที่แล้ว +1

      I'm guessing that because the first 'IF' statement was checking for 'Mousex > 50' no matter what that first 'IF' was always executed and didn't allow the rest to run because it was always true and fired first.

  • @sadanddepressed3463
    @sadanddepressed3463 6 ปีที่แล้ว

    watching your videos and I like them so much but I forget to like many videos

  • @Pixelon_
    @Pixelon_ 7 ปีที่แล้ว

    Amazing teacher!

  • @singhg529
    @singhg529 4 ปีที่แล้ว

    hey if suppose i wnt to move the ball vertically and after completing one round like(up->down),how we cn stop the ball at centre??

  • @alexx4992
    @alexx4992 6 หลายเดือนก่อน

    "If it's very hot, turn on the air conditioning. Otherwise, take a nap."

  • @沈仲元
    @沈仲元 2 ปีที่แล้ว

    Thanks for this session! It really solves my problems in practices. However, I really wonder why "100

  • @itsamelia4685
    @itsamelia4685 5 ปีที่แล้ว

    hi! i’m in a highschool coding class and we’re using your videos as a guide and i was wondering about the bouncing ball..how do you make the ball go up and down on the y axis? i’ve been trying to figure this out for so long 😂 thanks and please keep making these videos!

    • @TheCodingTrain
      @TheCodingTrain  5 ปีที่แล้ว

      Try adding a variable for y and also yspeed! (Here's a solution for when you need it: editor.p5js.org/icm/sketches/BJKWv5Tn)

  • @khalilkhan5335
    @khalilkhan5335 7 ปีที่แล้ว

    I have a question I was using brackets programing platform and I couldn't use && and I couldn't find what the replace mentioned for it was can someone tell me what the and equivalent is

  • @arvinroidoatienza7082
    @arvinroidoatienza7082 6 ปีที่แล้ว

    Pringles:
    var speed=5;
    function setup() {
    createCanvas(500, 500);
    background(255, 255,255);
    }
    function draw() {
    stroke(0);
    ellipse(height/2, width/2, mouseX, mouseY);
    if (mouseX > 2 || mouseX < 4) {
    fill(255,255,0);
    }
    if (mouseX > 200 && mouseX < 400) {
    speed = speed * -1;
    }
    mouseX=mouseX + speed;
    mouseY=mouseY + speed;
    }

  • @denot9063
    @denot9063 4 ปีที่แล้ว

    Ooo mmm ggg thank u so much sir you made my ball move😝😝😝

  • @sevdsakhalili5302
    @sevdsakhalili5302 ปีที่แล้ว

    heei . im from iran and i wanna say thank u there isn't ant good tutorial here u helped me a lot , i have a question dont u have any video about create custom function?

    • @TheCodingTrain
      @TheCodingTrain  ปีที่แล้ว

      Yes! The newest intro vidoe that covers everything (including defining your own functions) is here: th-cam.com/video/4JzDttgdILQ/w-d-xo.html check the timecodes for the part about functions!

  • @xianmoves6149
    @xianmoves6149 6 ปีที่แล้ว

    is there also a syntax to use case? can't seem to find anything on this.

  • @gros-calin
    @gros-calin 8 ปีที่แล้ว +2

    Hi Daniel,
    I'm watching your videos and it's really cool. So clear, funny and I learn a lot ! thank you :^)
    I saw you make some "live videos" on TH-cam (named Coding Rainbow) and that's a fantastic idea, but do you think you can do that on a plateform like Twitch (or other Live broadcaster) when people can actually ask you questions and remarks live ?
    It will be great to interact like that, especially for coding when there is always a different problem on different computers !
    Thank you again !

    • @TheCodingTrain
      @TheCodingTrain  8 ปีที่แล้ว +1

      +Michel Gangster Funny you should ask I was just going to try Twitch this week and see how that goes! With youtube I do take questions in the chat and answer them.

  • @markdibeh
    @markdibeh 5 ปีที่แล้ว

    Would you please guide us how to make draggable changable cloud to draw it on map or image please please

  • @ercimoisa4235
    @ercimoisa4235 6 ปีที่แล้ว

    This was awesome

  • @deepankverma
    @deepankverma 9 ปีที่แล้ว

    Why do we use if-else if we can do with 'if' statements alone? Is that because when we want our program to update its previous event with the new one, we use if-else; otherwise use only 'if', if we want to retain the outcomes of previous event plus the newer one. OR is there any other fundamental reason for it ?

    • @deepankverma
      @deepankverma 9 ปีที่แล้ว

      +Daniel Shiffman Thanks for explanation. That's why we fiddle with our codes and think bad about loops.

  • @JasonThomas-bv2yw
    @JasonThomas-bv2yw 8 ปีที่แล้ว +1

    I had no idea that you could * -1 to switch back and forth from neg. to pos. I don't get why it works, maybe it's too early for my brain to work, but cool.

    • @TheAliakbarazad
      @TheAliakbarazad 5 ปีที่แล้ว

      I know what you mean.. but the statement is about the space outside the Canvas not inside, as you might first think! Is not like it takes speed and multiple it with -1 for every pixle movement. :)

  • @ゾカリクゾ
    @ゾカリクゾ 6 ปีที่แล้ว +2

    10:28 Python users:
    Applaud my supreme power!

  • @seanjohnson2906
    @seanjohnson2906 3 ปีที่แล้ว +1

    3:48 I thought he was gonna say "Execute Order 66." :p

  • @einkommentierkanal5111
    @einkommentierkanal5111 8 ปีที่แล้ว

    First of all, thanks for the great series, really inspired me as someone who never coded before.
    One Question: I created a little random-image program. It constructs a picture pixel-by-pixel. I took a point with a variable that would increase by one and would go down row-by-row like a snake. But the problem ist that this system would take for ever on a large canvas.
    Is it possible to "speed" up the process of a variable getting increased? (I don't mean var = var + 1 to var= var + 3)

  • @zakidz6716
    @zakidz6716 5 ปีที่แล้ว

    to invert a variable just write
    speed = -speed;
    or
    speed *= -1;

  • @snownkc9749
    @snownkc9749 4 ปีที่แล้ว

    are the p5.js series in a playlist?

  • @stantoncomet
    @stantoncomet 4 ปีที่แล้ว +1

    Wait, what about the "NOT" function?

  • @BusyAsBee1738
    @BusyAsBee1738 5 ปีที่แล้ว

    ohhh snap to make the ball bounce back i just added another variable "edge" and set it equal to 0

  • @ch535
    @ch535 8 ปีที่แล้ว

    I still love your videos; they're absolutely amazing! I have another question though, because I'm a problem coder. I wanted to add a conditional fill to my draw for 300

  • @mikeyoung8547
    @mikeyoung8547 8 ปีที่แล้ว

    You said that only 1 Statement can be true, that it will jump to the next line of code.
    But what different makes it If 50 comes first, or if it is , 250,150,50 ?
    If you move the mouse, It will come to 50 and its True, shouldn't it jump then to the next code of line ? Because 1 Statement is true, or am i wrong ?

    • @stevensavoie856
      @stevensavoie856 6 ปีที่แล้ว

      when the mouse position is less than 250 and if 250 came first then the whole 'if chain' decided that its job was done and then the program jumped over the whole rest of the chain and continued executing any remaining code in the block. That means that though his mouse position is at 5px and 5 pixels is less than 50px and less than 150px, the if statement only reads as far as the first true statement in the chain, so it only checks to see that 5 is less than 250 and says, 'good enough'. if the mouse is at 51px, well 51 is greater than 50 but less than 150, but it doesn't matter because the chain is broken once the first condition is met, which has happened because 51 is still less than 250.
      If you invert the order, then it checks if the mouse position is less than 50 before it checks if its less than 150 and 250. if the mouse position is 5 then it recognizes that 5 is less than 50 and then draws the shape it is supposed to when this condition is met and doesn't evaluate the rest of the 'if chain'. but once the cursor is over 50px, for example, 51 pixels, it checks the first condition and says 51 is not less than 50. Then it moves on to the next conditional statement in the chain and evaluates: 51 is indeed less than 150. Then it draws the shape it should draw when that condition is met instead.
      I know that this question was over a year ago. But you asked and that means that others might wonder also.

  • @sunrising4931
    @sunrising4931 7 ปีที่แล้ว

    var x =0;
    var speed = 3;
    function setup() {
    createCanvas(600, 400);
    }
    function draw() {
    background(0);
    stroke(255);
    strokeWeight(4);
    noFill();
    ellipse(x, 200, 100, 100);
    if(x > width) {
    speed = -3;
    }else if(x = x;){
    x = x + speed;
    }
    x = x + speed;
    }
    the function is not working when i used if else statement...plz help

    • @khalilkhan5335
      @khalilkhan5335 7 ปีที่แล้ว +2

      take out the semicolon after the x in the else if statement

  • @stantoncomet
    @stantoncomet 4 ปีที่แล้ว +1

    Thanks to Minecraft's redstone, I got all this in the bag

  • @amanullahsohrabi3334
    @amanullahsohrabi3334 3 ปีที่แล้ว

    Can you do Java tutorials like this, couldn't find someone make programming fun and easy like you.......

  • @adriribau
    @adriribau 4 ปีที่แล้ว

    what does it mean the " * " that you put at the end of the video?

    • @TheCodingTrain
      @TheCodingTrain  4 ปีที่แล้ว

      Hi Adriano,
      The "*" at the end is a multiplication sign.
      ~ Coding Train Team 🚂

    • @adriribau
      @adriribau 4 ปีที่แล้ว

      @@TheCodingTrain but why puting “speed * -1”? Maybe there is something i miss :/

  • @arvindag
    @arvindag 7 ปีที่แล้ว

    It is a square not a rectangle @13:47

    • @julians.2597
      @julians.2597 7 ปีที่แล้ว

      a square is a special rectangle with equally long sides a and b .Thus a = b, so a*a = a*b. Thats why it's often described that way . ;)

    • @AHRienks
      @AHRienks 6 ปีที่แล้ว

      isn't a square a rectangle? yes, it is a special case where all sides are equal length!

  • @scottpanaro6077
    @scottpanaro6077 4 ปีที่แล้ว

    you are a genious

  • @itzspellon1330
    @itzspellon1330 2 ปีที่แล้ว

    i wanted to make if(valuble = valuble){rect()} make the rect apear when valuble = valuble

  • @jerickdefelipe12
    @jerickdefelipe12 5 ปีที่แล้ว +1

    Can I write "AND" instead of "&&"?

  • @ParadoxBassCube
    @ParadoxBassCube 8 ปีที่แล้ว +1

    That title. "else and else if and and or" :D

  • @quinnsugrue
    @quinnsugrue 6 ปีที่แล้ว

    I'm a bit confused the first "else if" i put in got an unexpected token on else and says its missing a semicolon can anybody help me out?

    • @Xnoob545
      @Xnoob545 5 ปีที่แล้ว

      I'll go on my pc && figure it out for you (&& for myself too cuz i'll need it)

    • @Xnoob545
      @Xnoob545 5 ปีที่แล้ว

      When i type else if
      It says
      Uncaught SyntaxError: Unexpected token else (sketch: line 12)
      Edit: if seems to work fine

  • @jerickdefelipe12
    @jerickdefelipe12 5 ปีที่แล้ว +1

    I think this is the hardest part of javascript for me hahah

    • @hasnainanis193
      @hasnainanis193 5 ปีที่แล้ว

      This is also my favourite part❤

    • @efa4442
      @efa4442 5 ปีที่แล้ว

      same bro

  • @ansh4966uhvtstr
    @ansh4966uhvtstr 4 ปีที่แล้ว

    thank you so much sir please define ( * )this symbol

  • @anandhurmenon3966
    @anandhurmenon3966 4 ปีที่แล้ว +1

    good class

  • @kyelwilliams4280
    @kyelwilliams4280 6 ปีที่แล้ว

    Does anybody know how to make it stay bouncing on the screen I can’t figure it out here’s what I have so far following the video instructions worked I just wish he had continued to show how it comes back and stays moving back and forth:
    Beast.x = beast.x + speed;
    If (beast.x > width) {
    Speed = -3;
    }
    This keeps just like the circle in the video but I need it to turn around again and I can’t figure out how PLEASE HELP

    • @canofsoda
      @canofsoda 5 ปีที่แล้ว

      i mean at least the if statements work for you

  • @kranefivem
    @kranefivem 6 ปีที่แล้ว

    i use switch every time i wanna make an if statement, i cant code python because of this

  • @phillipschristoph
    @phillipschristoph 6 ปีที่แล้ว

    That moment you think you understand conditionals, but don't don't.

  • @fatihatabassum2025
    @fatihatabassum2025 5 ปีที่แล้ว

    Edit:
    editor.p5js.org/tabassum.fatiha05/sketches/DUWZFS2yE

  • @lightingvulture
    @lightingvulture 8 ปีที่แล้ว

    How can i write the OR ? which buttons ?

  • @reanimationsinc.6880
    @reanimationsinc.6880 6 ปีที่แล้ว

    14 videos in and this is the only one i completely didn't understand

    • @Xnoob545
      @Xnoob545 5 ปีที่แล้ว

      3.1 and 3.2 were confusing this one is the least confusing

  • @KACZMARCZYK4369
    @KACZMARCZYK4369 3 ปีที่แล้ว

    lesson completed

  • @canofsoda
    @canofsoda 5 ปีที่แล้ว

    does this...
    only work on mac?

    • @TheCodingTrain
      @TheCodingTrain  5 ปีที่แล้ว

      You can do p5 on any platform! editor.p5js.org

  • @Bunglay
    @Bunglay 7 ปีที่แล้ว

    when i input the line of : else { point ( 300 , 200 ) }
    i get console error: unexpected keyword 'else' ... :(
    im like.. bro.. pls... don't do this to me... console is like..
    unexpected keyword 'else'
    and then im like brooooooooooooo!!!!!

    • @Bunglay
      @Bunglay 7 ปีที่แล้ว +2

      i fixed it im blind

  • @krunchan
    @krunchan 6 ปีที่แล้ว

    legend

  • @hunterfitzpatrick8389
    @hunterfitzpatrick8389 6 ปีที่แล้ว

    So I decided to write a script testing the randomness of p5.js. Here is the script editor.p5js.org/Wikiwikislimshady/sketches/S1svq2soQ . Basically var x is randomized between 0 and 400. Once a random value is given, it is sorted into a bar graph, raising the height value of the bar by one pixel, each bar corresponding to a range of possible random x values. Once the bar reaches the top of the canvas, the gray scale is increased and the bar size is reset. In theory the bars should rise at the same rate but this isn't observed. Did I write the code wrong? Is this a product of coded randomness? Any help anyone can give would be awesome.

  • @hugoandrade8691
    @hugoandrade8691 4 ปีที่แล้ว

    i wish i could like and subscribe to him more than one time. (without any fake account).

  • @anitam5159
    @anitam5159 8 ปีที่แล้ว

    noStroke();
    background(38, 89, 33);
    for(var i = 0; i

    • @TheCodingTrain
      @TheCodingTrain  8 ปีที่แล้ว

      +Anita Mirage I would suggest looking ahead at the videos on functions and objects. This would allow you to have a single function that you can call multiple times for the same design. Or making an object for that design would allow you to animate it independently. Good luck!

    • @anitam5159
      @anitam5159 8 ปีที่แล้ว

      Daniel Shiffman Thanks! I try to watch your vids in order but sometimes I skip around. Anyway this is the final code I used;
      noStroke();
      background(38, 89, 33);
      var drawFlower = function(x,y){
      for(var i = 0; i

    • @TheCodingTrain
      @TheCodingTrain  8 ปีที่แล้ว

      +Anita Mirage looks great! Just remember it's push() and pop() in p5 instead of pushMatrix() etc.

  • @shatteredbox3163
    @shatteredbox3163 6 ปีที่แล้ว

    bro how about y(height)

    • @BusyAsBee1738
      @BusyAsBee1738 5 ปีที่แล้ว

      idk all i did was just repeat what i did for X.

  • @divinebread338
    @divinebread338 5 ปีที่แล้ว

    if (mouseX > 300 && mouseX < 400 && mouseY>100 && mouseY

  • @louisdiblasi462
    @louisdiblasi462 7 ปีที่แล้ว +4

    Everything is working. However, you lost me with this "speed = speed * -1;" I am not sure why it works.

    • @binaybhushan1192
      @binaybhushan1192 7 ปีที่แล้ว +1

      Permission - its like if speed is +3 now and on hitting the screen width we have to reverse the speed which is by multiplying speed with negative -1 its like 3 * -1 now speed is =-3

    • @stevensavoie856
      @stevensavoie856 6 ปีที่แล้ว +4

      I haven't watched the series.. so try to correct anything wrong as you read. But my guess is that on each screen update, the ball moves from x position 0px to 3px, 6px, 9px and so on until it reaches the edge of the screen (let us assume the screen is 600px wide). Grab a calculator and try 3 multiplied by -1, you will see that the result is -3. then try -3 multiplied by -1 and you will see that -3 becomes 3 again. When you multiply a number by -1 it changes a positive number to a negative number and vice versa. That's what is happening when he writes speed = speed * -1, it means that the value of speed, which is in this case 3 will be changed to the result of 3 * -1 and now the value of speed is -3. Once speed (which is now 3) is multiplied by -1 again changes the value of speed back to -3.
      Back to his example: the ball moves from x position 0px to 3px to 6px to 9px and so on until it reaches 603px. Once it realizes it has gone over 600px then the conditional statement evaluates to true and sets the positive speed of 3 to the negative speed of -3 and then the x position proceeds like this: 603px, 600px, 597px, 594px and so on until it reaches -3px. Once the balls x position is at -3px, the conditional statement evaluates to true and then flips the speed from -3 to positive 3. Then it proceeds again from x position -3px to 0px, 3px, 6px and so on until 603px again.
      Remember that 'speed' is not the position of the ball, it is just how many pixels the ball moves on each iteration. The variable X is the current position of the ball. So if speed is 3 and if x is 9, then (x + speed) will be 12. if speed is -3 and x is 9 then (x + speed) will be 6, since 9 + -3 = 6.
      Hope that was clear enough and correct enough heh.
      edit: I know that I am late to the party, but just in case others are asking the same thing.

    • @TheAliakbarazad
      @TheAliakbarazad 5 ปีที่แล้ว

      I know what you mean.. but the statement is about the space outside the Canvas not inside, as you might first think! Is not like it takes speed and multiple it with -1 for every pixle movement. :)

  • @zyskah4499
    @zyskah4499 3 ปีที่แล้ว +1

    i love you

  • @jimmybuck1993
    @jimmybuck1993 4 ปีที่แล้ว +1

    Var x = food_in_kitchen
    If (money >hunger) && (hunger > Will_to_cook) {
    (Order = food);
    }
    else if ( hunger = cook) {
    (Random +x);
    }

  • @JasonThomas-bv2yw
    @JasonThomas-bv2yw 8 ปีที่แล้ว

    That 10 minutes never seems to quite work out. :)

  • @zonnovate8809
    @zonnovate8809 6 ปีที่แล้ว

    Check the box if you are learning to code xd editor.p5js.org/zoni/full/HkEr1D9hQ

  • @simisobhembe
    @simisobhembe 2 ปีที่แล้ว

    OMG... imagine getting 80 and 'B'

  • @notmyrealname5865
    @notmyrealname5865 3 ปีที่แล้ว

    I think p5.js mixed up AND and OR

  • @Reda_Am
    @Reda_Am 4 ปีที่แล้ว

    Uncaught ReferenceError: mouseX is not defined (sketch: line 10) honestly wtf is this

  • @mustafaerdem1862
    @mustafaerdem1862 7 ปีที่แล้ว

    burning IQ

  • @n0body-music934
    @n0body-music934 4 ปีที่แล้ว

    did anyone notice in the title is and and or LMAO

  • @terracoon9882
    @terracoon9882 3 ปีที่แล้ว

    the people who dislike are rats...

  • @supesoup5597
    @supesoup5597 5 ปีที่แล้ว

    hi