Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

キーボードから入力した文字を電光掲示板風に表示する

/**
* Display of Character Like Electronic Signboard
*
* @author aa_debdeb
* @date 2015/11/14
*/

void setup(){
  size(500, 500);
  smooth();
  background(0);
  textSize(400);
  textAlign(CENTER);
}

void draw(){

}

void keyPressed(){
  background(0);
  fill(255);
  char keys[] = {key};
  text(new String(keys), 0, 0, width, height);
  
  boolean[][] dots = new boolean[50][50];
  loadPixels();
  for(int x = 0; x < 50; x++){
    for(int y = 0; y < 50; y++){
      color c = pixels[y * 10 * width + x * 10];
      dots[x][y] = red(c) > 127 ? true: false;
    }
  }
  background(30);
  stroke(10);
  for(int x = 0; x < 50; x++){
    for(int y = 0; y < 50; y++){
      if(dots[x][y]){
        fill(255, 140, 0);  
      } else {
        fill(0);
      }
      ellipse(x * 10, y* 10, 10, 10);        
    }
  }
}