2026年2月12日 星期四

[OTTO GO] 圖形測試-虎嘴

 


Arduino:





 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>

#define TFT_MOSI 19   // SDA (SPI MOSI)
#define TFT_SCLK 18   // SCL (SPI SCK)
#define TFT_CS    5
#define TFT_DC   16
#define TFT_RST  23

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

static inline uint16_t RGB565(uint8_t r, uint8_t g, uint8_t b) {
  return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}

// 只畫「虎嘴」(口鼻白毛 + 嘴線/陰影/鬍鬚點)
void drawTigerMouth(int cx, int cy) {
  // 黑底
  tft.fillScreen(ST77XX_BLACK);

  // 顏色
  uint16_t furLight = RGB565(235, 228, 210); // 口鼻白毛
  uint16_t shadow   = RGB565(160, 150, 135); // 下巴陰影
  uint16_t lineDark = RGB565(40,  40,  40);  // 嘴線
  uint16_t dotDark  = RGB565(70,  70,  70);  // 鬍鬚點

  // ===== 口鼻白毛區(兩個鬍鬚墊 + 中間一塊)=====
  tft.fillCircle(cx - 55, cy + 10, 55, furLight); // 左鬍鬚墊
  tft.fillCircle(cx + 55, cy + 10, 55, furLight); // 右鬍鬚墊
  tft.fillRoundRect(cx - 90, cy - 25, 180, 110, 28, furLight);

  // 下巴陰影(嘴下方那條暗)
  tft.fillRoundRect(cx - 85, cy + 60, 170, 22, 12, shadow);
  tft.fillRoundRect(cx - 40, cy + 55, 80, 10, 5, RGB565(120,110,100));

  // ===== 人中線(從上唇中間往下)=====
  tft.drawLine(cx,     cy - 5, cx,     cy + 20, lineDark);
  tft.drawLine(cx - 1, cy - 5, cx - 1, cy + 20, RGB565(80,80,80));

  // ===== 上唇虎嘴弧線(左右)=====
  int mouthY = cy + 18;

  // 左弧線:用很多點近似曲線
  for (int i = 0; i < 34; i++) {
    int x = cx - i;
    int y = mouthY + (i * i) / 95;   // i 越大越往下彎
    tft.drawPixel(x, y, lineDark);
    tft.drawPixel(x, y + 1, lineDark);
  }

  // 右弧線
  for (int i = 0; i < 34; i++) {
    int x = cx + i;
    int y = mouthY + (i * i) / 95;
    tft.drawPixel(x, y, lineDark);
    tft.drawPixel(x, y + 1, lineDark);
  }

  // 嘴角加深
  tft.fillCircle(cx - 36, mouthY + 12, 3, lineDark);
  tft.fillCircle(cx + 36, mouthY + 12, 3, lineDark);

  // 嘴中間小暗線(可選,讓嘴更像照片)
  tft.fillRoundRect(cx - 10, mouthY + 20, 20, 4, 2, RGB565(90,80,70));

  // ===== 鬍鬚點(虎鬚根部)=====
  int dotY1 = cy + 6;
  int dotY2 = cy + 26;
  for (int k = 0; k < 3; k++) {
    tft.fillCircle(cx - 55 - k * 12, dotY1 + k * 2, 2, dotDark);
    tft.fillCircle(cx - 55 - k * 12, dotY2 + k * 2, 2, dotDark);

    tft.fillCircle(cx + 55 + k * 12, dotY1 + k * 2, 2, dotDark);
    tft.fillCircle(cx + 55 + k * 12, dotY2 + k * 2, 2, dotDark);
  }
}

void setup() {
  SPI.begin(TFT_SCLK, -1, TFT_MOSI, TFT_CS);

  // 你的模組若是 240x320 就保持;若你之前確認是 170x320 再改
  tft.init(240, 320);
  tft.setRotation(1);

  int cx = tft.width() / 2;
  int cy = tft.height() / 2;

  drawTigerMouth(cx, cy);
}

void loop() {}

沒有留言:

張貼留言