Data visualization with own images

// Discourse.Processing.org/t/data-visualization-with-own-images/2452/7
// GoToLoop (2018/Aug/07)

static final int EMOTICONS = 5, MAX_EMOTION = 100;
static final color OPAQ = PImage.ALPHA_MASK;
static final color RED = 020, REDDISH = 0x100 / EMOTICONS;

final PImage[] emoticons = new PImage[EMOTICONS];
int emotion, intensity;

void setup() {
  noLoop();

  for (int i = 0; i < EMOTICONS; ) {
    final PImage img = emoticons[i++] = createImage(width, height, ARGB);
    java.util.Arrays.fill(img.pixels, i*REDDISH << RED | OPAQ);
    img.updatePixels();
  }

  keyPressed();
}

void draw() {
  final PImage chosen = emoticons[intensity];
  set(0, 0, chosen);
}

void mousePressed() {
  keyPressed();
}

void keyPressed() {
  emotion = (int) random(MAX_EMOTION);
  println("Emotion: " + emotion);

  intensity = emotion * EMOTICONS / MAX_EMOTION;
  println("Intensity: " + intensity);

  redraw();
}
1 Like