NOBのArduino日記!

NOBのArduino日記!

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

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

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

■使用例
 gb.display.fillCircleHelper関数を使ったArduinoIDEのプログラム例は図1の通りです。
 このプログラムを実行するとsetup関数中のgb.begin関数でGamebuinoオブジェクトを初期化し、gb.titleScreen関数で画面に「display.fillCircleHelper」と表示します。
 スタート画面でキーボードの「K」(GamebuinoのA)ボタンを押すとgb.display.fillCircleHelper関数によって画面上に移動する半円図形が描画され、画面枠で反射を繰り返します。
 参考に図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.fillCircleHelper"));
}

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.fillCircleHelper(ball_x, ball_y, ball_size, 1, 5);
   }
}
イメージ 1
図1:プログラム例
 

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

 

■構文
 gb.display.fillCircleHelper(x,y,r,corner,delta)

■パラメータ
 x        :円の中心の水平座標
 y        :円の中心の垂直座標
 r        :円の半径
 corner:どの部分を描画するか(1:左半分、2:右半分)
 delta  :指定した長さが半円の中央に追加され長い半円となります。

■戻り値
 ありません  

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

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