ピクセル指向プログラミング言語 Pixilang (3)

アニメーション

グラフィックスを動かしてみる。

while 1
{
  t_rotate( 1, 0, 0, 1 )

  clear()

  dot( 0, 0, WHITE )
  line( 0, 100, 100, 0, ORANGE )
  box( -100, -100, 50, 100, RED )
  fbox( 100, -100, 100, 50, #ffeecc )
  frame()

  while get_event()
  {
    if EVT[ EVT_TYPE ] == EVT_QUIT { halt }
  }
}

t_rotate関数は描画するものを回転する。回転はt_rotateの後の描画命令に適用されることに注意。

t_rotate( $angle, $x, $y, $z )
描画するものを回転する。
$angle: 回転角。度数法で指定。
$x: 回転軸の向きのx成分。
$y: 回転軸の向きのy成分。
$z: 回転軸の向きのz成分。

clear関数は画面を消去する。引数に消去する色を指定する。引数を省略すると黒になる。

clear( $c = 0 )
画面を消去する。
$c: 画面を消去する色。

これで、図形は1フレームごとに1度時計回りに回転する。

残像エフェクト

while 1
{
  t_rotate( 1, 0, 0, 1 )

  transp( 16 )
  clear( 0 )
  transp( 255 )

  dot( 0, 0, WHITE )
  line( 0, 100, 100, 0, ORANGE )
  box( -100, -100, 50, 100, RED )
  fbox( 100, -100, 100, 50, #ffeecc )
  frame()

  while get_event()
  {
    if EVT[ EVT_TYPE ] == EVT_QUIT { halt }
  }
}

clear関数の前後でtransp関数を使った。transp関数は描画の不透明度*1を指定する。0は完全に透明、255は完全に不透明になる。

transp( $t )
$t: 不透明度。0 = 完全に透明、255 = 完全に不透明。

clear関数で画面を完全に消さず、前のフレームの画像を残すことで、残像効果になる。
f:id:mandel59:20130603103648p:plain

*1:transparencyは透明度で、不透明度はopacity。