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...
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.
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!
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!!!
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!
to fill the rectangle(x,y): function setup() { createCanvas(400, 400); } function draw() { background(220); strokeWeight(4); noFill(); if ((mouseX >= 150) & (mouseX = 150) & (mouseY
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
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!!
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!!
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;"
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) } }
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.
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 :(
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.
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.
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.
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!
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
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?
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!
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 !
+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.
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 ?
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.
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. :)
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)
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
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 ?
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.
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
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
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!!!!!
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.
+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!
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
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
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.
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. :)
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!
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...
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.
Thank you so much!
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!
+kemikalreakt thank you so much. Makes me happy to hear and motivation to make more videos!
the thing that amazes me is that when i feel like im half of the video done its already over, your tutorials are great!!!!!
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!!!
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!
Daniel how in the world do you teach us without making us get bored. You are a excellent teacher.
to fill the rectangle(x,y):
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
strokeWeight(4);
noFill();
if ((mouseX >= 150) & (mouseX = 150) & (mouseY
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
You are really a God sent teacher!! Makes it so interesting and simple!!
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!!
haha, so true.
this man deserves a noble prize in pedagogy!
I second that!
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!!
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!!
By FAB i’m fench too
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;"
best teacher ever !
thanks !!
Great tutorial !!!
Greetings from Spain
I thought we were gona be threatening the computer when it misbehaves
that would be for training artificial intelligence lol
thats for another video
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)
}
}
This is such a good series i love it so much thankyou for making it
Love your channel!!!!!!!!!!!!!!
great solution, I should say Genial!!!!! min 15:50
best teaching skills 💗
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.
dan you are amazingggggggg
sir thank u for giving us this education
and also thank u for making our future bright
mgbu
like the way u explain keep the good work thx
10:00 AND, OR explanaition.
Your class is very nice😊
Your class is very nice
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!
Thanks for the nice feedback!
the 🕹 p5.js Web Editor Sketchs dont work anymore. i dont have the sketch as an example anymore
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 :(
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.
if ( you love programming ) {
Do it
} else {
Try to love it !
}
SyntaxError: expected expression, got keyword 'else' (sketch: line 3)
Compiler: Error Do you like programming is not defined
var yes I love coding = 0,
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.
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.
watching your videos and I like them so much but I forget to like many videos
Amazing teacher!
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??
"If it's very hot, turn on the air conditioning. Otherwise, take a nap."
Thanks for this session! It really solves my problems in practices. However, I really wonder why "100
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!
Try adding a variable for y and also yspeed! (Here's a solution for when you need it: editor.p5js.org/icm/sketches/BJKWv5Tn)
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
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;
}
Ooo mmm ggg thank u so much sir you made my ball move😝😝😝
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?
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!
is there also a syntax to use case? can't seem to find anything on this.
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 !
+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.
Would you please guide us how to make draggable changable cloud to draw it on map or image please please
This was awesome
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 ?
+Daniel Shiffman Thanks for explanation. That's why we fiddle with our codes and think bad about loops.
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.
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. :)
10:28 Python users:
Applaud my supreme power!
3:48 I thought he was gonna say "Execute Order 66." :p
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)
to invert a variable just write
speed = -speed;
or
speed *= -1;
are the p5.js series in a playlist?
Wait, what about the "NOT" function?
ohhh snap to make the ball bounce back i just added another variable "edge" and set it equal to 0
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
6 years later no reply
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 ?
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.
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
take out the semicolon after the x in the else if statement
Thanks to Minecraft's redstone, I got all this in the bag
Can you do Java tutorials like this, couldn't find someone make programming fun and easy like you.......
what does it mean the " * " that you put at the end of the video?
Hi Adriano,
The "*" at the end is a multiplication sign.
~ Coding Train Team 🚂
@@TheCodingTrain but why puting “speed * -1”? Maybe there is something i miss :/
It is a square not a rectangle @13:47
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 . ;)
isn't a square a rectangle? yes, it is a special case where all sides are equal length!
you are a genious
i wanted to make if(valuble = valuble){rect()} make the rect apear when valuble = valuble
Can I write "AND" instead of "&&"?
Unfortunately no! 😭
That title. "else and else if and and or" :D
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?
I'll go on my pc && figure it out for you (&& for myself too cuz i'll need it)
When i type else if
It says
Uncaught SyntaxError: Unexpected token else (sketch: line 12)
Edit: if seems to work fine
I think this is the hardest part of javascript for me hahah
This is also my favourite part❤
same bro
thank you so much sir please define ( * )this symbol
good class
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
i mean at least the if statements work for you
i use switch every time i wanna make an if statement, i cant code python because of this
That moment you think you understand conditionals, but don't don't.
Edit:
editor.p5js.org/tabassum.fatiha05/sketches/DUWZFS2yE
How can i write the OR ? which buttons ?
it's "shift backslash" on my laptop.
ok thanks daniel
14 videos in and this is the only one i completely didn't understand
3.1 and 3.2 were confusing this one is the least confusing
lesson completed
does this...
only work on mac?
You can do p5 on any platform! editor.p5js.org
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!!!!!
i fixed it im blind
legend
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.
i wish i could like and subscribe to him more than one time. (without any fake account).
noStroke();
background(38, 89, 33);
for(var i = 0; i
+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!
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
+Anita Mirage looks great! Just remember it's push() and pop() in p5 instead of pushMatrix() etc.
bro how about y(height)
idk all i did was just repeat what i did for X.
if (mouseX > 300 && mouseX < 400 && mouseY>100 && mouseY
I am smart!
Everything is working. However, you lost me with this "speed = speed * -1;" I am not sure why it works.
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
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.
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. :)
i love you
Var x = food_in_kitchen
If (money >hunger) && (hunger > Will_to_cook) {
(Order = food);
}
else if ( hunger = cook) {
(Random +x);
}
😂
That 10 minutes never seems to quite work out. :)
Check the box if you are learning to code xd editor.p5js.org/zoni/full/HkEr1D9hQ
OMG... imagine getting 80 and 'B'
I think p5.js mixed up AND and OR
Uncaught ReferenceError: mouseX is not defined (sketch: line 10) honestly wtf is this
burning IQ
did anyone notice in the title is and and or LMAO
the people who dislike are rats...
hi