Calling functions with variables

An object-oriented approach.
Not sure this would be more efficient as there would still be indirect access to the objects.

Handler[] scenes;

void settings()
{
  size(256,256);
  noLoop();
}

void setup()
{
  scenes = new Handler[2];
  scenes[0] = new Scene1();
  scenes[1] = new Scene2();
}

void mouseClicked()
{
  redraw();
}

void draw()
{
  background(0);
  int selected = (int) random(0,scenes.length);
  scenes[selected].show();
}

class Handler
{
  Handler() { }
  void show() { }
}

class Scene1 extends Handler
{
  void show() {
    noFill();
    stroke(0,0,255);
    rect(50,50, 150,50);
    fill(255);
    text("Showing Scene 1", 60,70);
  }
}

class Scene2 extends Handler
{
  void show() {
    noFill();
    stroke(255,0,0);
    rect(50,50, 150,50);
    fill(255);
    text("Showing Scene 2", 60,70);
  }
}

4 Likes