Revisiting-Concepts-Notatio.../2.Ghost-Writing.md

57 lines
1.6 KiB
Markdown
Raw Normal View History

2023-01-15 11:13:49 +01:00
# Ghost Writing: Text, Arrays, Randomness
2023-01-15 11:17:06 +01:00
<p align="center">
<img src="https://git.le-club-des-sans-sujets.org/gauthiier/Revisiting-Concepts-Notations-Software-Art/media/branch/main/img/love-letter.png" alt="autopilot creativity" width="80%"/>
</p>
2023-01-15 11:32:42 +01:00
## Sketch: 2.0 Array + Index
2023-01-15 11:13:49 +01:00
```javascript
// Array + Index!
var NAMES = ["David", "Karin", "Sigrid", "Nanna", "Laura", "Maaike"];
var INDEX = 0;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
}
function keyTyped() {
if(key == 'x') {
print("Hi " + NAMES[0] + "!");
}
}
// Reference: https://p5js.org/reference/
```
2023-01-15 11:32:42 +01:00
### 🤔 What are indices?
2023-01-15 11:13:49 +01:00
```javascript
["David", "Karin", "Sigrid", "Nanna", "Laura", "Maaikke"] <--- Array (var NAMES)
| | | | | |
0 1 2 3 4 5 <--- indices (var INDEX)
2023-01-15 11:32:42 +01:00
```
### 📚 Exercice
1. Modify sketch 2.0 so that:
* When key 'k' is pressed then "Hi Karin!" is printed on the console
* When key 's' is pressed then "Hi Sigrid!" is printed on the console
* When key 'n' is pressed then "Hi Nanna!" is printed on the console
* When key 'm' is pressed then "Hi Maaike!" is printed on the console
2. Modify sketch 2.0 so that:
2023-01-15 11:40:47 +01:00
* Every time key 'x' is pressed then print the name of the following person in the array ("Hi David!", "Hi Karin!", "Hi Sigrid!", and so forth)
### 🤔 Who/what is "undefined"?
<p align="center">
<img src="https://git.le-club-des-sans-sujets.org/gauthiier/Revisiting-Concepts-Notations-Software-Art/media/branch/main/img/undefined.png">
</p>