n_shinichi’s blog

日々の備忘録、 趣味のあれこれなど紹介 (すみません、メニュー、リンク、カテゴリー分けがうまくできてません、★記事一覧★で見てください...) NHK魔改造の夜ではDンソーのベテランアドバイザーってことで出ました♪

MENU

スティックくんの顔の描画

もう1年以上前からこの顔でスティックくんは変わってない・・・

 

Chieさんから可愛いってコメント頂いて、

どう描いてるって質問があったんだけど・・・

 

あまりこれといって考えてなくてかなり適当に作ってます。

そもそもArduinoの描画の関数はもっと気の利いたのがありそうだけど

調べてないです。。。

 

最初に見た線の描画、円の描画関数をただ組み合わせたべた書きです。。。^^;

だからあまり見せれるコードじゃないんですが

Chieさんに褒めて?もらったので顔描画の部分コードの紹介です。
M5stickCじゃなく、M5stickC-Plusじゃないと

画面のドット数の関係で同じようにはならないです。

www.youtube.com

//
// スティックくんの顔描画
//
#include "M5StickCPlus.h"

void setup() {
  M5.begin();
  M5.Lcd.setRotation(2);
  M5.Lcd.fillScreen(BLACK);
  draw_kao();
 }

void loop() {
    draw_henoji();
    delay(1000);        
    draw_smile();
    delay(1000);     
    draw_L_wink();
    delay(1000);
    draw_L_wink_reset();
    delay(1000);
    draw_R_wink();
    delay(1000);
    draw_R_wink_reset();
    delay(1000);
}


void draw_kao(){
M5.Lcd.fillRect(0, 100, 134, 239, WHITE);

// 目 M5.Lcd.fillEllipse(x0, y0, rx, ry, color);
  M5.Lcd.fillEllipse(62-27,160, 10, 20, BLACK);
  M5.Lcd.fillEllipse(62+27,160, 10, 20, BLACK);
  
// 口
  for(int i = 0; i < 5; i++){
    M5.Lcd.drawLine(62-15, 200+i, 62-10, 204+i, BLACK);
    M5.Lcd.drawLine(62-10, 204+i, 62, 206+i, BLACK);
    M5.Lcd.drawLine(62, 206+i, 62+10, 204+i, BLACK);
    M5.Lcd.drawLine(62+10, 204+i, 62+15, 200+i, BLACK);
  }

// 眉
  for(int i = 0; i < 5; i++){
    M5.Lcd.drawLine(62-25, 130+i, 62-45, 125+i, BLACK);
    M5.Lcd.drawLine(62+25, 130+i, 62+45, 125+i, BLACK);
  }
}
void draw_L_wink() {
    M5.Lcd.fillEllipse(62-27,160, 10, 20, WHITE);//L 白で目を消す
    draw_henoji_sub(62-27, 160,BLACK);//黒でwink
}
void draw_L_wink_reset() {
    draw_henoji_sub(62-27, 160,0xffff);//白でwink消す
    M5.Lcd.fillEllipse(62-27,160, 10, 20, BLACK);//L 黒で目を戻す
}
void draw_R_wink() {
    M5.Lcd.fillEllipse(62+27,160, 10, 20, WHITE);//R 白で目を消す
    draw_henoji_sub(62+27, 160,BLACK);//黒でwink
}
void draw_R_wink_reset() {
    draw_henoji_sub(62+27, 160,0xffff);//白でwink消す
    M5.Lcd.fillEllipse(62+27,160, 10, 20, BLACK);//R 黒で目を戻す
}
void draw_henoji_sub(unsigned char x,unsigned char y,unsigned short color) {
  for(int i = 0; i < 5; i++){
    M5.Lcd.drawLine(x-15,  y+6+i, x-10, y+4+i, color);
    M5.Lcd.drawLine(x-10,  y+4+i, x,    y+i, color);
    M5.Lcd.drawLine(x,     y+i, x+10,   y+4+i, color);
    M5.Lcd.drawLine(x+10,  y+4+i, x+15, y+6+i, color);
  }  
}
void draw_henoji(){
// 白で消す
  for(int i = 0; i < 5; i++){
    M5.Lcd.drawLine(62-15, 200+i,   62-10,  204+i, WHITE);
    M5.Lcd.drawLine(62-10, 204+i,   62,     206+i, WHITE);
    M5.Lcd.drawLine(62, 206+i,      62+10,  204+i, WHITE);
    M5.Lcd.drawLine(62+10, 204+i,   62+15,  200+i, WHITE);
  }

// への字
  for(int i = 0; i < 5; i++){
    M5.Lcd.drawLine(62-15,  206+i, 62-10,   204+i, BLACK);
    M5.Lcd.drawLine(62-10,  204+i, 62,      200+i, BLACK);
    M5.Lcd.drawLine(62,     200+i, 62+10,   204+i, BLACK);
    M5.Lcd.drawLine(62+10,  204+i, 62+15,   206+i, BLACK);
  }
}
void draw_smile(){
// 白への字で消す
  for(int i = 0; i < 5; i++){
    M5.Lcd.drawLine(62-15,  206+i, 62-10,   204+i, WHITE);
    M5.Lcd.drawLine(62-10,  204+i, 62,      200+i, WHITE);
    M5.Lcd.drawLine(62,     200+i, 62+10,   204+i, WHITE);
    M5.Lcd.drawLine(62+10,  204+i, 62+15,   206+i, WHITE);
  }

// 黒でスマイル
  for(int i = 0; i < 5; i++){
    M5.Lcd.drawLine(62-15, 200+i,   62-10,  204+i, BLACK);
    M5.Lcd.drawLine(62-10, 204+i,   62,     206+i, BLACK);
    M5.Lcd.drawLine(62, 206+i,      62+10,  204+i, BLACK);
    M5.Lcd.drawLine(62+10, 204+i,   62+15,  200+i, BLACK);
  }
}