From b01903067659ce6d5fac3324eeb2047880e8ddef Mon Sep 17 00:00:00 2001 From: gauthiier Date: Mon, 9 Jan 2023 11:03:47 +0100 Subject: [PATCH] 1.4 --- 1.Basics.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/1.Basics.md b/1.Basics.md index 20860d6..e069b2a 100644 --- a/1.Basics.md +++ b/1.Basics.md @@ -22,4 +22,44 @@ function draw() { background(220); print("Hello World"); // see the console below ↓ } -``` \ No newline at end of file +``` + +## 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 ↓ +} + +// Reference: https://p5js.org/reference/```