aboutsummaryrefslogtreecommitdiff
path: root/P5/light.js
blob: c60d225b66fc681102981deb35d20ee99d19ea5c (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. }