![]() While we can name your variable anything, it's good to name it descriptively. If you stick to letters, you will be in great shape. There are some rules, but they're somewhat complicated. You can name variables pretty much anything you want. In this case, we pick for the variable's name. JavaScript is case sensitive so you have to write var in all lowercase otherwise, it does not recognize it as this keyword. First is the keyword var, this keyword is what tells JavaScript that you're declaring a new variable with this statement. Let us take a minute to break down this syntax of this statement. Some languages do not require you to initialize variables, but it's a good idea to always do so. Initializing a variable means giving it the first value it should hold when you create it. Declaring a variable means telling JavaScript that you want it to make a new variable. Here is an example of a JavaScript statement which declares a variable called x and initializes it to 3. This is going to turn into an if else statement which you will also learn about soon. And finally, your algorithm looks at a condition, in this particular case whether a pixel is green or not, and makes a decision about what to do next based on that condition. You're going to need to learn how to write code that repeats steps which will be a for loop which you will learn about later. Your algorithm calls for you to repeat some steps for each pixels in an image. You need a way to operate on this images and their pixels looking at particular pixels see what color they are and setting the pixels in an image, you'll learn about this soon. You also need a way to make images, whether reading in an existing image or creating a blank image. These are going to turn into variables in your code, which you will learn about momentarily. In the English description, we refer to them as fgImage, bgImage, output and currentPixel. One thing you need is a way to give names to the values your algorithm comes up with. We'll switch to Java in the next course, and you'll see that much of this looks the same. ![]() We're going to learn these in JavaScript now, but the same basic concepts exist in pretty much any programming language. But you have a lot of different pieces of code that you need to learn. Now that you have the algorithm for green screening an image, you want to translate it into code.
0 Comments
Leave a Reply. |