aboutsummaryrefslogtreecommitdiff
path: root/p5.js
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-19 10:30:57 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-19 10:31:05 +0200
commit217819954fa3ee999e837dafd26817f69b5746b9 (patch)
treedb95897201f8949d1281352dfdc6c9a4e0b6dda0 /p5.js
parent9a51836f416d4bdbd28e085e51bc0dfa6d83d89b (diff)
rename directory P5 -> p5.js; update report content
Diffstat (limited to 'p5.js')
-rw-r--r--p5.js/light.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/p5.js/light.js b/p5.js/light.js
new file mode 100644
index 0000000..20eb1c0
--- /dev/null
+++ b/p5.js/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