aboutsummaryrefslogtreecommitdiff
path: root/P5
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-18 00:59:39 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-18 01:04:41 +0200
commit64e93d863d322a9d9e60fe102a494a7cef98e65f (patch)
tree61e67f0e3b06b455025bbc2677a52a8d8901f3e1 /P5
parent031240f883a2822dee70760dc3f76e643978256b (diff)
add P5.js sketch light as appendix
Diffstat (limited to 'P5')
-rw-r--r--P5/light.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/P5/light.js b/P5/light.js
new file mode 100644
index 0000000..c60d225
--- /dev/null
+++ b/P5/light.js
@@ -0,0 +1,28 @@
+// SPDX-FileCopyrightText: 2025 Noor Ahmad <noora@ruc.dk>
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+let button;
+let bgColor; //a variable that keeps track of the background color
+let isBlack = true; //Starts with black
+
+function setup() {
+ createCanvas(800, 500);
+ bgColor = color(15,15,60);
+ button = createButton("Color");
+ button.mouseClicked(changeBackground);
+ button.size(50, 50);
+ button.position(350, 210);
+}
+
+function draw() {
+ background(bgColor);
+}
+
+function changeBackground() {
+ if (isBlack) {
+ bgColor = color(255, 223, 0); //Yellow
+ }else {
+ bgColor = color(15,15,60); //Black
+ }
+ isBlack = !isBlack; //Changing between true and false
+} \ No newline at end of file