Arduino用コアグラフィックライブラリ。Processing APIを基にしている。
これは、グラフィックプリミティブを使い、画面に描画したり書いたりすることができるライブラリである。利用しているスクリーンをドライブする特定のハードウェアインターフェイスライブラリが必要である。このため、それぞれのスクリーン自身のハードウェアに依存したライブラリが必要である。
このライブラリを使うためには、以下を宣言する。
|
|
グラフィックプリミティブの使用方法を簡単に理解するために、YourScreenという名前のダミーのスクリーンオブジェクトを使っている。これは、実際のもの、例えば、MATRIXやOLED、TFTなど実際のものに置き換える必要がある。詳細は、利用するスクリーンのハードウェアインターフェイスライブラリを参照すること。
このライブラリのスタイルと文法は、Processing 3に触発されている。我々は、Arduinoベースのハードウェアの多様性とPCベースのグラフィックインターフェイスを組み合わせた複雑なアプリケーションを開発するには、Processingを学ぶことが役に立つと信じている。
フォントからビットマップを生成する方法
|
|
このライブラリを使うためには、Arduino IDEでライブラリマネージャを開きインストールする。
- 1.1.5(最新)
ArduinoGraphics::begin()
説明
グラフィックデバイスを初期化する。
書式
int ArduinoGraphics::begin()
引数
なし
戻り値
成功したら1、失敗したら0。
使用例
|
|
ArduinoGraphics::end()
説明
グラフィックデバイスを停止する。
書式
void ArduinoGraphics::end()
引数
なし
戻り値
なし
使用例
|
|
ArduinoGraphics::width()
説明
グラフィックデバイスの幅(ピクセル)を返却する。
書式
int ArduinoGraphics::width()
引数
なし
戻り値
グラフィックデバイスの幅(ピクセル)を返却する。
使用例
|
|
ArduinoGraphics::height()
説明
グラフィックデバイスの高さ(ピクセル)を返却する。
書式
int ArduinoGraphics::height()
引数
なし
戻り値
グラフィックデバイスの高さ(ピクセル)を返却する。
使用例
|
|
ArduinoGraphics::beginDraw()
説明
描画操作を開始する。
書式
void ArduinoGraphics::beginDraw()
引数
なし
戻り値
なし
使用例
|
|
ArduinoGraphics::endDraw()
説明
描画操作を終了する。beginDraw()以降に呼び出された描画操作がスクリーンに表示される。
書式
void ArduinoGraphics::endDraw()
引数
なし
戻り値
なし
使用例
|
|
ArduinoGraphics::background()
説明
描画操作の背景色を設定する。clear()の呼び出しやテキストを書くときに利用される。
書式
void ArduinoGraphics::background(uint8_t r, uint8_t g, uint8_t b)
void ArduinoGraphics::background(uint32_t color)
uint32_t ArduinoGraphics::background()
引数
| r | 赤色の値(0-255) |
| g | 緑色の値(0-255) |
| b | 青色の値(0-255) |
| color | 24ビットのRGB、0xrrggbb |
戻り値
なし
訳者註: 引数を与えないときは、現在の設定値(24ビット)が返却される。
使用例
|
|
ArduinoGraphics::clear()
説明
スクリーンの内容を消去する。background()で設定した背景色を利用する。
書式
void ArduinoGraphics::clear()
引数
なし
戻り値
なし
使用例
|
|
ArduinoGraphics::fill()
説明
描画操作の塗りつぶし色を設定する。
書式
void ArduinoGraphics::fill(uint8_t r, uint8_t g, uint8_t b)
void ArduinoGraphics::fill(uint32_t color)
引数
| r | 赤色の値(0-255) |
| g | 緑色の値(0-255) |
| b | 青色の値(0-255) |
| color | 24ビットのRGB、0xrrggbb |
戻り値
なし
使用例
|
|
ArduinoGraphics::noFill()
説明
描画操作の塗りつぶし色を解除する。
書式
void ArduinoGraphics::noFill()
引数
なし
戻り値
なし
使用例
|
|
ArduinoGraphics::stroke()
説明
描画操作の描画色を設定する。
書式
void ArduinoGraphics::stroke(uint8_t r, uint8_t g, uint8_t b)
void ArduinoGraphics::stroke(uint32_t color)
引数
| r | 赤色の値(0-255) |
| g | 緑色の値(0-255) |
| b | 青色の値(0-255) |
| color | 24ビットのRGB、0xrrggbb |
戻り値
なし
使用例
|
|
ArduinoGraphics::noStroke()
説明
描画操作の描画色を解除する。
書式
void ArduinoGraphics::noStroke()
引数
なし
戻り値
なし
使用例
|
|
ArduinoGraphics::line()
説明
直線を描画する。stroke()で設定した描画色を利用する。
書式
void ArduinoGraphics::line(int x1, int y1, int x2, int y2)
引数
| x1 | 直線の始点のX座標 |
| y1 | 直線の始点のY座標 |
| x2 | 直線の終点のX座標 |
| y2 | 直線の終点のY座標 |
戻り値
なし
使用例
|
|
ArduinoGraphics::point()
説明
点を描画する。stroke()で設定した描画色を利用する。
書式
void ArduinoGraphics::point(int x, int y)
引数
| x | 直線の始点のX座標 |
| y | 直線の始点のY座標 |
戻り値
なし
使用例
YourScreen.beginDraw();
YourScreen.clear();
YourScreen.stroke(0, 255, 0);
YourScreen.point(1, 1);
YourScreen.endDraw();ArduinoGraphics::rect()
説明
長方形を描画し、塗りつぶす。stroke()で設定した描画色と、fill()で設定した塗りつぶし色を利用する。
書式
void ArduinoGraphics::rect(int x, int y, int width, int height)
引数
| x | 長方形のX座標 |
| y | 長方形のY座標 |
| width | 長方形の幅 |
| height | 長方形の高さ |
戻り値
なし
使用例
YourScreen.beginDraw();
YourScreen.clear();
YourScreen.noStroke();
YourScreen.fill(255, 255, 0);
YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height());
YourScreen.endDraw();ArduinoGraphics::circle()
説明
円を描画し、塗りつぶす。stroke()で設定した描画色と、fill()で設定した塗りつぶし色を利用する。
書式
void ArduinoGraphics::circle(int x, int y, int diameter)
引数
| x | 円の中心のX座標 |
| y | 円の中心のY座標 |
| diameter | 円の直径 |
戻り値
なし
使用例
YourScreen.beginDraw();
YourScreen.clear();
YourScreen.noStroke();
YourScreen.fill(255, 255, 0);
YourScreen.circle(YourScreen.width()/2, YourScreen.height()/2, YourScreen.height());
YourScreen.endDraw();ArduinoGraphics::ellipse()
説明
楕円を描画し、塗りつぶす。stroke()で設定した描画色と、fill()で設定した塗りつぶし色を利用する。
書式
void ArduinoGraphics::ellipse(int x, int y, int width, int height)
引数
| x | 楕円の中心のX座標 |
| y | 楕円の中心のY座標 |
| width | 楕円の幅 |
| height | 楕円の高さ |
戻り値
なし
使用例
YourScreen.beginDraw();
YourScreen.clear();
YourScreen.noStroke();
YourScreen.fill(255, 255, 0);
YourScreen.ellipse(YourScreen.width()/2, YourScreen.height()/2, YourScreen.width(), YourScreen.height());
YourScreen.endDraw();ArduinoGraphics::text()
説明
文字を書く。stroke()で設定した描画色と、background()で設定した背景色を利用する。
書式
void ArduinoGraphics::text(const char* str, int x = 0, int y = 0)
void ArduinoGraphics::text(const String& str, int x = 0, int y = 0)
引数
| str | 各文字列 |
| x | 文字の開始位置のX座標 |
| y | 文字の開始位置のY座標 |
戻り値
なし
使用例
YourScreen.beginDraw();
YourScreen.clear();
YourScreen.stroke(255, 255, 255);
YourScreen.text("abc", 0, 1);
YourScreen.endDraw();ArduinoGraphics::textFont()
説明
文字を書くときのフォントを設定する。現状、ライブラリは、Font_4x6とFont_5x7を組み込んでいる。
書式
void ArduinoGraphics::textFont(const Font& which)
引数
| which | 設定するフォント |
戻り値
なし
使用例
YourScreen.beginDraw();
YourScreen.clear();
YourScreen.stroke(255, 255, 255);
YourScreen.textFont(Font_5x7);
YourScreen.text("abc", 0, 1);
YourScreen.endDraw();ArduinoGraphics::textFontWidth()
説明
現在のフォントの幅をピクセルで返却する。
書式
int ArduinoGraphics::textFontWidth()
引数
なし
戻り値
現在のフォントの幅(ピクセル)
使用例
int w = YourScreen.textFontWidth();ArduinoGraphics::textFontHeight()
説明
現在のフォントの高さをピクセルで返却する。
書式
int ArduinoGraphics::textFontHeight()
引数
なし
戻り値
現在のフォントの高さ(ピクセル)
使用例
int h = YourScreen.textFontHeight();ArduinoGraphics::textSize()
説明
文字の倍率を設定する。
書式
void ArduinoGraphics::textSize(uint8_t s)
void ArduinoGraphics::textSize(uint8_t sx, uint8_t sy)
引数
| s | x、y双方に利用する倍率。 |
| sx | xに利用する倍率。 |
| sy | yに利用する倍率。 |
戻り値
なし
使用例
YourScreen.beginDraw();
YourScreen.clear();
YourScreen.stroke(255, 255, 255);
YourScreen.textFont(Font_5x7);
YourScreen.textSize(5);
YourScreen.text("abc", 0, 1);
YourScreen.endDraw();ArduinoGraphics::set()
説明
ピクセルの色の値を設定する。
書式
void ArduinoGraphics::set(int x, int y, uint8_t r, uint8_t g, uint8_t b)
void ArduinoGraphics::set(int x, int y, uint32_t color)
引数
| x | ピクセルのX座標 |
| y | ピクセルのY座標 |
| r | 赤色の値(0-255) |
| g | 緑色の値(0-255) |
| b | 青色の値(0-255) |
| color | 24ビットのRGB、0xrrggbb |
戻り値
なし
使用例
YourScreen.beginDraw();
YourScreen.point(1, 1, 0, 255, 0);
YourScreen.endDraw();ArduinoGraphics::beginText()
説明
文字の表示とオプションのスクロール処理を開始する。文字を設定するのにはPrintインターフェイスが利用できる。
書式
void ArduinoGraphics::beginText(int x, int y)
void ArduinoGraphics::beginText(int x, int y, uint8_t r, uint8_t g, uint8_t b)
void ArduinoGraphics::beginText(int x, int y, uint32_t color)
引数
| x | 文字のX座標 |
| y | 文字のY座標 |
| r | 赤色の値(0-255) |
| g | 緑色の値(0-255) |
| b | 青色の値(0-255) |
| color | 24ビットのRGB、0xrrggbb |
戻り値
なし
使用例
YourScreen.beginText(0, 0, 127, 0, 0);
YourScreen.print("Hi");
YourScreen.endText();ArduinoGraphics::endText()
説明
文字の表示とオプションのスクロール処理を終了する。
書式
void ArduinoGraphics::endText(int scrollDirection)
引数
| scrollDirection | スクロール方向(オプション)。デフォルトはNO_SCROLL。有効なオプションは、デフォルトはNO_SCROLL、SCROLL_LEFT、SCROLL_RIGHT、SCROLL_UP、SCROLL_DOWN。 |
戻り値
なし
使用例
YourScreen.beginText(0, 0, 127, 0, 0);
YourScreen.print("Hi");
YourScreen.endText();ArduinoGraphics::textScrollSpeed()
説明
文字のスクロール速度を設定する。各ピクセルをスクロールする際の遅延をミリ秒単位で制御する。
書式
void ArduinoGraphics::textScrollSpeed(unsigned long speed)
引数
| speed | スクロール速度 |
戻り値
なし
使用例
YourScreen.beginText(0, 0, 127, 0, 0);
YourScreen.textScrollSpeed(500);
YourScreen.print("Hello There!");
YourScreen.endText(true);