How to make a word change to a different word every 10 seconds?

edited June 2017 in Library Questions

Hi everyone,

At the moment I have a word that reacts to sound input from an external mic. The title really explains what I'm looking to do. I've been looking at 'delay()' as a a possible way to change the word every 10 seconds, but I honestly don't know where to start. I've looked at tutorials and other threads to no avail.

I'm thinking I create a string of words I want the sketch to cycle through, but as to how I link that to time I don't know. Or is it a case of creating separate classes?

Thanks for any help or pointers to tutorials that could help me!

Here's what I've done so far:

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim; 
BeatDetect beat;
AudioInput in;
FFT fft;

float angle = 0;

PFont font1;
PFont font2;
PFont font3;


void setup()
{


  noCursor();
  fullScreen();
  smooth();
  minim = new Minim(this);
  in = minim.getLineIn();
  fft = new FFT(in.bufferSize(), in.sampleRate());

  frameRate(60);

  beat = new BeatDetect();
   beat.setSensitivity(100);


  font1=loadFont("Simplon.vlw");
  font2=loadFont("Simplon 50.vlw");
  font3=loadFont("Simplon 80.vlw");


}

void draw()
{
  noFill();
  background(255);
  fft.forward(in.mix);
  for (int i = 0; i < in.mix.size() - 1; i++) {
    angle = radians(i);
     textFont(font3);
    textSize(80);
    textAlign(CENTER, CENTER);
    fill(0);
    text("John", 
    width/2 +1000 *cos(angle)*(10*in.mix.get(i)), 
    height/2 -1000 *sin(angle)*(10*in.mix.get(i)));
  }


}

void keyPressed() {

  if (key == 's') {
    saveFrame("wallpapers/wallpaper-####.tif");
  }

}

Answers

  • edited June 2017 Answer ✓

    @TypeCoding -- Don't use delay() -- that freezes your sketch.. Use a timer that checks millis() or frameCount().

    For example:

    if(millis()-lastWordTime > 10000){
      lastWordTime = millis();
      nextWord();
    } // ~10 secs
    

    Or:

    if(frameCount-lastWordFrame > 600){
      lastWordFrame = frameCount;
      nextWord();
    } // ~10 secs at 60fps
    
  • String[] wordsList= {
      "Hello", 
      "You", 
      "There", 
      "Here"
    };
    
    int index=0; // for wordsList
    
    int lastWordTime; // for timer  
    
    void setup() {
      size(500, 500);
      // frameRate(15);
      background(0); 
      lastWordTime = millis();
    }
    
    void draw() {
      background(0); 
    
      text (wordsList[index], 222, 222);  
    
      if (millis()-lastWordTime > 1000) {  // ~1 sec
        lastWordTime = millis();
        nextWord();
      } //if
    }//func 
    
    void nextWord() {
      index++;
      if (index>=wordsList.length) {
        index=0;
      }//if
    }//func
    //
    
Sign In or Register to comment.