Example: Color Tween

Tweens the color of the circle through HSB color space from one color to another, by way of Processing's lerpColor() function. The tween's position() is used as the amt parameter, which works particularly nicely since it is usually between 0 and 1.

This is very little different from the other examples and just speaks to the fact that a Tween can really animate between two states of any attribute, and not simply motion.

As a note when tweening between colors, the color space you are using, RGB or HSB, affects what the tweened colors would look like. HSB tends to create interpolated colors that seem more natural whereas RGB tends to tween through brown space.

import megamu.shapetween.*;

Tween ani;

void setup(){
  size( 200, 200 );
  colorMode( HSB );
  smooth();
  ani = new Tween(this, 1.3, Tween.SECONDS, Tween.REVERSE_REPEAT, Shaper.QUADRATIC);
  ani.start();
}

void draw(){
  background( ani.isTweening() ? 255 : 230 );
  
  color c1 = color(  45, 210, 240 );
  color c2 = color( 135, 130, 195 );
  
  color c = lerpColor( c1, c2, ani.position() );
  
  noStroke();
  fill( c );
  ellipse( 100, 100, 140, 140 );
}

void mousePressed(){
  if( ani.isTweening() )
    ani.pause();
  else
    ani.resume();
}