JavaScript and p5.js basics PDF

Title JavaScript and p5.js basics
Course Processing with Artificial Intelligence
Institution EM Lyon Business School
Pages 9
File Size 210.3 KB
File Type PDF
Total Downloads 9
Total Views 130

Summary

Introduction aux langages JavaScript et p5.JS...


Description

Processing with Artifitial Intelligence A. JavaScript reminders Programming is the process of designing a computer programfor accomplishing a specific computing task. It generally involves coding in a specific programming language by writing down lines of code. Don't mix up programming and development, which rather refers to the larger process of testing, debugging (removing bugs), documenting code, managing the program's environment, and so on Many programming languages exist for different purposes and personal preferences of developers. The most famous ones include Python, C (along with C++ and C#), Java, PHP, and many more. JavaScript is one of the three languages of the web with HTML and CSS, and therefore can be executed by any browser. Watch out, HTML and CSS are not programming languages but respectively markup and style sheetlanguages. A JavaScript library is a file (or a set of multiple files) of pre-written JavaScript, which allows for easier development of JavaScript-based applications. It allows you to write down working code quicker, starting with a basis that you pick depending on your needs. Basically, a library consists in a set of helpful pre-defined functions and variables that you can use on-the-fly without having to build them from scratch, like p5.js (that we will discover in the next chapter).

1. FUNCTIONS A function is a block of code that defines a small… function! It starts with the keyword function , followed by its name, two parentheses () then two curly-brackets {} Between these brackets is some code, that will be executed each time this function is called. Now that our function is defined, we can execute its code by writing its name followed by two parentheses anywhere in our code. A function can take one or more arguments, they are variables that are passed to the function. In that case, when calling the function we will need to provide the value of these arguments in the parentheses Sometimes, when programmers talk about code, to specify they are talking about a function, they write their name followed by two parentheses. For example "The function that we just saw, called print_arguments() , prints three lines in the console".

2. CONDITIONS if - else - else if conditions are very often used, you will need them to add some interactions:

If a is bigger than b , write "A is above B" in the console, else, write "A is inferior or equal to B" in the console". Have a look at the p5.js reference page about If-Else to learn more about how to use it. We suggest you watch this video of The Coding Train about all the if-else rules. p5.js provides a shortcut for console.log() , a function simply called… print()

3. LOGICAL OPERATORS && (and), || (or) are two logic operators you can use in your if - else - else if conditions: If a is bigger than b and a is bigger than c write "A is above B and C" in the console Also, if b is bigger than a or c is bigger than a write "A is inferior or equal to B or C " in the console. We suggest you watch this video of The Coding Train about if/else-if and JS conditions.

4. COMPARISON OPERATORS Here are the basic comparison operators you can use in your code:



== : equal



!= : different



> : greater than



>= : greater or equal to



< : less than

...


Similar Free PDFs