NOBのArduino日記!

NOBのArduino日記!

趣味は車・バイク・自転車・ラジコン・電子工作です。

Arduino IDE(gb.display.fillTriangle関数の使い方)

■gb.display.fillTriangle関数
  Gamebuimo.hライブラリのgb.display.fillTriangle関数は、指定された場所に三角形を描画して塗りつぶします。
 使用される色はgb.display.setColor関数を使用して定義されます。
 三角形の一部が画面外になるような値を指定すると、レンダリングされません。

■使用例
 gb.display.fillTriangle関数を使ったArduinoIDEのプログラム例は図1の通りです。
 このプログラムを実行するとsetup関数中のgb.begin関数でGamebuinoオブジェクトを初期化し、gb.titleScreen関数で画面に「display.fillTriangle」と表示します。
 スタート画面でキーボードの「K」(GamebuinoのA)ボタンを押すとgb.display.fillTriangle関数によって画面上に移動する三角形が描画され、画面枠で反射を繰り返します。
 参考に図1プログラムをHEXファイルに変換し、それをSimbuino4Webエミュレートした結果を図2に示します。

#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
int ball_x = LCDWIDTH / 2; //set the horizontal position to the middle of the screen
int ball_y = LCDHEIGHT / 2; //vertical position
int ball_vx = 1; //horizontal velocity
int ball_vy = 1; //vertical velocity
int ball_size = 8; //the size of the ball in number of pixels

void setup() {
   gb.begin();
   gb.titleScreen(F("display.fillTriangle"));
}

void loop() {
   if (gb.update()) {
       ball_x = ball_x + ball_vx;
       ball_y = ball_y + ball_vy;
       if (ball_x < 0) {
           ball_vx = -ball_vx;
           gb.sound.playTick();
       }
       if ((ball_x + ball_size) > LCDWIDTH) {
           ball_vx = -ball_vx;
           gb.sound.playTick();
       }
       if (ball_y < 0) {
           ball_vy = -ball_vy;
           gb.sound.playTick();
       }
       if ((ball_y + ball_size) > LCDHEIGHT) {
           ball_vy = -ball_vy;
           gb.sound.playTick();
       }
       gb.display.fillTriangle(ball_x, ball_y - 8, ball_x + 7, ball_y + 4, ball_x - 7, ball_y + 4);
   }
}
イメージ 1
図1:プログラム例
 

 イメージ 1
図2:プログラム実行結果

 

■構文
 gb. display.fillTriangle(x0,y0,x1,y1,x2,y2)関数のパラメータ 

■パラメータ
 x0:1番目の角の水平座標
 y0:1番目の角の垂直座標
 x1:2番目の角の水平座標
 y1:2番目の角の垂直座標
 x2:3番目の角の水平座標
 y2:3番目の角の垂直座標 

■戻り値
 ありません。

 

イメージ 1 イメージ 3
励みになりますのでよければクリック下さい(^o^)/

↩【Gamebuinoリファレンス】目次に戻る