NOBのArduino日記!

NOBのArduino日記!

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

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

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

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

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

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

 

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

■パラメータ
 x        :円の中心の水平座標
 y        :円の中心の垂直座標
 r        :円の半径
 corner:描画するコーナー( 1:左上、2:右上、4:右下、8:左下)

■戻り値
 ありません
 

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

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