119 lines
2.8 KiB
Markdown
Raw Normal View History

2023-01-09 10:42:32 +01:00
# Basics 101
2023-01-09 11:59:35 +01:00
## 👋 p5js Editor
2023-01-09 11:17:46 +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/editor.p5js.png" alt="autopilot creativity" height="650"/>
</p>
2023-01-09 11:26:02 +01:00
## 🤔 How does code work/act?
2023-01-09 10:49:57 +01:00
<p align="center">
<img src="https://git.le-club-des-sans-sujets.org/gauthiier/Revisiting-Concepts-Notations-Software-Art/raw/branch/main/img/compiler.svg" alt="autopilot creativity" height="150"/>
</p>
2023-01-09 10:42:32 +01:00
2023-01-09 10:49:57 +01:00
<p align="center">
<img src="https://git.le-club-des-sans-sujets.org/gauthiier/Revisiting-Concepts-Notations-Software-Art/raw/branch/main/img/interpreter.svg" height="150"/>
2023-01-09 10:52:12 +01:00
</p>
## Sketch: 0. Hello World
2023-01-09 10:52:44 +01:00
2023-01-09 10:54:32 +01:00
```javascript
2023-01-09 10:52:12 +01:00
// Hello world!
2023-01-09 11:06:34 +01:00
// This is a comment
2023-01-09 10:52:12 +01:00
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
print("Hello World"); // see the console below ↓
}
2023-01-09 11:03:47 +01:00
```
2023-01-09 11:26:02 +01:00
## 🤔 What kind of "Errors"?
<p align="center">
<img src="https://git.le-club-des-sans-sujets.org/gauthiier/Revisiting-Concepts-Notations-Software-Art/media/branch/main/img/error.png" height="200"/>
</p>
2023-01-09 11:03:47 +01:00
## Sketch: 1.0 Key Events
```javascript
// Key Events!
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
// Only when keyIsPressed?
print("Hello World");
}
// Reference: https://p5js.org/reference/
```
## Sketch: 1.1 Mouse Events
```javascript
// Mouse Events!
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
if(mouseIsPressed) {
print("Pressed: " + mouseX + " - " + mouseY) ; // see the console below ↓
}
}
// this is a special p5 function
function mouseMoved() {
print("Moved: " + mouseX + " - " + mouseY) ; // see the console below ↓
}
2023-01-09 11:05:04 +01:00
// Reference: https://p5js.org/reference/
```
2023-01-09 11:50:50 +01:00
2023-01-09 11:59:35 +01:00
## 🤔 What are (x,y) coordinates (in p5js)?
<p align="center">
2023-01-09 12:00:32 +01:00
<img src="https://gitlab.com/aesthetic-programming/book/-/raw/master/source/1-GettingStarted/ch1_11.png" height="450"/>
2023-01-09 11:59:35 +01:00
</p>
2023-01-09 11:50:50 +01:00
## Sketch: 1.2 Variables
```javascript
// Variables!
var previous_mouseX_pressed = 0; // global "var" variable
var previous_mouseY_pressed = 0; // global "var" variable
function setup() {
createCanvas(400, 400);
}
function draw() {
// background(220);
if(mouseIsPressed) {
let current_mouseX_pressed = mouseX; // local "let" variable valid within "{" brackets "}"
let current_mouseY_pressed = mouseY; // local "let" variable valid within "{" brackets "}"
print("Pressed: " + current_mouseX_pressed + " - " + current_mouseY_pressed) ;
previous_mouseX_pressed = current_mouseX_pressed;
previous_mouseY_pressed = current_mouseY_pressed;
}
}
// this is a special p5 function
function mouseMoved() {
print("Moved: " + mouseX + " - " + mouseY) ; // see the console below ↓
}
// Reference: https://p5js.org/reference/```