aboutsummaryrefslogtreecommitdiff
path: root/p5.js/light.js
blob: 20eb1c0d0b6e16a0505f2689170f45bd4bddcfad (plain)
  1. // SPDX-FileCopyrightText: 2025 Noor Ahmad <noora@ruc.dk>
  2. // SPDX-License-Identifier: GPL-3.0-or-later
  3. let button;
  4. let bgColor; // a variable that keeps track of the background color
  5. let isBlack = true; // Starts with black
  6. function setup() {
  7. createCanvas(800, 500);
  8. bgColor = color(15, 15, 60);
  9. button = createButton("Color");
  10. button.mouseClicked(changeBackground);
  11. button.size(50, 50);
  12. button.position(350, 210);
  13. }
  14. function draw() {
  15. background(bgColor);
  16. }
  17. function changeBackground() {
  18. if (isBlack) {
  19. bgColor = color(255, 223, 0); // Yellow
  20. } else {
  21. bgColor = color(15, 15, 60); // Black
  22. }
  23. isBlack = !isBlack; // Changing between true and false
  24. }