> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.GTA$0OkTnjl/rev.12
 * 
 * authors: 
 *   GoToLoop

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



/** 
 * Bouncy Words (v3.04)
 * by tfguy & jtwhite14 (2013/Aug)
 * mod GoToLoop
 * 
 * forum.processing.org/topic/animated-text
 * studio.processingtogether.com/sp/pad/export/ro.9eHY5Fel1e0Jr/latest
 */

static final int NUM = 3;
final BouncyWord[] words = new BouncyWord[NUM];

void setup() {
  size(300, 200, JAVA2D);
  smooth(4);

  fill(BouncyWord.INK);
  textAlign(LEFT, CENTER);

  textFont(createFont("Trebuchet MS Bold", BouncyWord.DIM, true));

  words[0] = new BouncyWord("History", -1.5, 0, 50);
  words[1] = new BouncyWord("Design", 2.3, 0, 100);
  words[2] = new BouncyWord("Studio", -3, 0, 150);
}

void draw() {
  background(-1);
  for (BouncyWord w : words)  w.bounce();
}

class BouncyWord {
  static final short DIM = 90;
  static final color INK = 0100 << 030;

  String word;
  float px, py, vx, vy;

  BouncyWord(String iword, float ivy, float ipx, float ipy) {
    word = iword;
    vy = ivy;
    px = ipx;
    py = ipy;
  }

  void bounce() {
    if ((py += vy) >= height - (DIM>>2) | py < (DIM>>2))  vy *= -1;
    text(word, px, py);
  }
}