How do I get the mousePressed function to change to different words each time on p5.js?

Hi everyone!
Was wondering how do I get the text to change every time I mousePress it. E.g. Sunday, then to Monday, then to Tuesday and so forth until it get to Saturday?
Any help will be much appreciated
Would I use an array to do this?

here is the code for now

var xPos;
var yPos;
//var d = 36;
//var day: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday];
var r; //radius
var angle
var step // distance between steps in radians
var timer = 5;
var countDownSwitch = false;

function setup() {
  createCanvas (windowWidth, windowHeight);
  r = (100);
  angle = 0;
  step = TWO_PI/20;
  
  frameRate (3);
  textSize (70);
  textFont ("Futura");
  text ('Sunday',600,600);
  
//for (var i = 0; i > 10; i++){
  

}

function draw (){

  translate (width/2, height/2);
  xPos = random(r*sin(angle));
  yPos = random(r*cos(angle));
  
 
  noStroke();
  fill (20, 40, 50, 30);
  ellipse (xPos,yPos,30);
  
  angle = angle + step;

  
  //for (var i=0; i<circle.length; i++) {
  //  circles[i].circle();
  //  circles[i].display();  
  //} 
}

//this allows you to pause the sketch with just pressing any key on the keyboard. 
function keyPressed (){
  noLoop();
}
function keyReleased (){
  loop();
}
  
function mousePressed (){
  background (255);
  if (mousePressed) {
    fill (0);
    textSize (70);
  textFont ("Futura");
  text ('Monday', 600-width/2,600-height/2);
    
  }
}
1 Like

Hello @sam101

First, a friendly tip: format your code by highlighting it and press the code button (it looks like </> ) in the editor. Easy to read code will most certainly attract more people to help you out. :blush: (There’s more great tips here.)

To answer your original first question (top post has been edited):

This worked at the beginning, but then I added the keyPressed function and somehow the word “Monday” it stoped showing up?

Have you made sure the code is executing alright without throwing errors? You could look for problems using the developer console in your browser.

2 Likes

aaahhh thanks for the suggestions!

This is probaly a harder way to do it but:

int counter = 1;
void setup(){
  fullScreen();
  
}
void draw(){
  background(0);
  textSize(100);
  if(mousePressed){
    counter = counter+1;
  }
  if(counter > 7){
    counter = 1;
  }
  if(counter == 1){
    text ("Sunday",600,600);
  }
  if(counter == 2){
    text ("Monday",600,600);
  }
  if(counter == 3){
    text ("Tuesday",600,600);
  }
  if(counter == 4){
    text ("Wednesday",600,600);
  }
  if(counter == 5){
    text ("Thursday",600,600);
  }
  if(counter == 6){
    text ("Friday",600,600);
  }
  if(counter == 7){
   text ("Saturday",600,600);
  }
}
2 Likes

Hello,

You are incrementing counter multiple times with each mousePress.
println() is useful to see this:
https://processing.org/reference/println_.html
println(counter) will print the value of counter to the console.

Consider this:
https://processing.org/reference/mousePressed_.html

:)

2 Likes