Skip to content

Latest commit

 

History

History
89 lines (61 loc) · 1.74 KB

File metadata and controls

89 lines (61 loc) · 1.74 KB
layout page
title Variables
permalink variables.html

Les variables dans P5.js

Les variables sont des symboles qui associent un nom (l'identifiant) à une valeur.

Exemple:

Dans une vidéo :

2.1: Variables in p5.js (mouseX, mouseY) - p5.js Tutorial

<iframe width="100%" style="aspect-ratio:16/9" src="https://www.youtube-nocookie.com/embed/7A5tKW9HGoM?si=ATvcQKcJw_k8fQfT" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

Les variables dans Processing

// easy version
noFill();
int diam = 10; // diam for "diameter",
circle(50,50, diam);
diam = diam + 10;
circle(50,50, diam);
diam += 10; // "a += b" is a shortcut for "a = a + b"
circle(50,50, diam);
// etc...

ensuite…

// Version using 2 variables
noFill();
int diam = 10;
int step = 8;
circle(50,50, diam);
diam += step;
circle(50,50, diam);
diam += step;  circle(50,50, diam);
diam += step;  circle(50,50, diam);
diam += step;  circle(50,50, diam);
diam += step;  circle(50,50, diam);

Declarer une variable

// I need to remember a number. 
// Call it ‘lucky’. 
// It’s 7.

int lucky = 7;
  • int : pour enregistrer un nombre entier
  • lucky : le nom de notre variable
  • = : l'opérateur permettant d'assigner une valeur à la variable
  • 7 : la valeur

Modifier une variable

// I changed my mind, my lucky number is now 9.

lucky = 9;

// No, wait, my lucky number is now whatever it was minus 3.

lucky = lucky - 3;

// Add 2 to my lucky number.

lucky += 2;

// Your lucky number is 5.

int yourNum = 5;

// Let’s add your number to my number.

lucky += yourNum;