図形描画(サンプル)

10秒毎に違う図形サンプルを描画します。

f_SetTitle('図形サンプル')
f_SetInterval(10000)
gra = f_Graphics()
require('color')
cw = f_GetClientWidth()
ch = f_GetClientHeight()
no = no or 0
gra:Clear(Color.DarkGray)

function sample_00()
  x = "DrawRectangles"
  p  = gdi:Pen(Color.Red,2)
  r1 = gdi:Rectangle(20, 20, 140, 120)
  r2 = gdi:Rectangle(30, 25, 120, 150)
  r3 = gdi:Rectangle(25, 30, 150, 140)
  gra:DrawRectangles(p, {r1, r2, r3})
end
function sample_01()
  x = "DrawPolygon"
  p1 = gdi:Point(30, 30)
  p2 = gdi:Point(180, 80)
  p3 = gdi:Point(110, 140)
  p4 = gdi:Point(130, 180)
  gra:DrawPolygon(p, {p1, p2, p3, p4})
end
function sample_02()
  x = "円、円弧"
--位置(10, 20)に100x80の四角を赤色で描く
  gra:DrawRectangle(Pens.Red, 10, 20, 100, 80)
--先に描いた四角に内接する楕円を黒で描く
  gra:DrawEllipse(Pens.Black, 10, 20, 100, 80)

  gra:TranslateTransform(110, 0);

  gra:DrawRectangle(Pens.Red, 10, 20, 100, 80)
--先に描いた四角に内接する楕円の一部
-- (開始角度 0度、スイープ角度 90度)を黒で描く
  gra:DrawArc(Pens.Black, 10, 20, 100, 80, 0, 90)

  gra:TranslateTransform(110, 0);

--位置(10, 20)に100x80の四角を赤色で描く
  gra:DrawRectangle(Pens.Red, 10, 20, 100, 80)
--先に描いた四角に内接する楕円の一部の扇形
-- (開始角度 0度、スイープ角度 90度)を黒で描く
  gra:DrawPie(Pens.Black, 10, 20, 100, 80, 0, 90)

--(10,20)の位置に100x80サイズの黒で塗りつぶされた長方形を描画する
--  gra:FillRectangle(Brushes.Black, 10, 20, 100, 80)

  gra:TranslateTransform(-220, 0);
end
function sample_03()
  x = "塗りつぶしモード"
  points = {
    gdi:Point(90, 10),
    gdi:Point(20, 180),
    gdi:Point(190, 50),
    gdi:Point(10, 70) ,
    gdi:Point(160, 120)
  }
  gra:FillPolygon(Brushes.Red, points, 1)
  gra:TranslateTransform(190, 0);
  gra:FillPolygon(Brushes.Red, points, 0)
  gra:TranslateTransform(-190, 0);
end

function sample_04()
  x = "DrawEllipse,FillEllipse"
  gra:DrawRectangle(Pens.White, 20, 50, 0.1, 0.1)
  gra:FillRectangle(Brushes.White, 20, 80, 0.1, 0.1)
  gra:DrawEllipse(Pens.White, 20, 110, 0.1, 0.1)
  gra:FillEllipse(Brushes.White, 20, 140, 0.1, 0.1)
  for i = 0 , 10 do
    gra:DrawRectangle(Pens.White, 30 + (10 + i) * i, 50, i, i)
    gra:FillRectangle(Brushes.White, 30 + (10 + i) * i, 80, i, i)
    gra:DrawEllipse(Pens.White, 30 + (10 + i) * i, 110,i, i)
    gra:FillEllipse(Brushes.White, 30 + (10 + i) * i, 140, i, i)
  end
  for i = 1, 60 do
   gra:DrawRectangle(Pens.White, 10 + 10 * i, 170, 0.1 *i,0.1 * i)
   gra:FillRectangle(Brushes.White, 10 + 10 * i, 200, 0.1 * i, 0.1 * i)
   gra:DrawEllipse(Pens.White, 10 + 10 * i, 230, 0.1 * i, 0.1 * i)
   gra:FillEllipse(Brushes.White, 10 + 10 * i, 260, 0.1 * i, 0.1 * i)
  end
end

function sample_05()
  x = "グラデーションブラシ"
  p1 = gdi:Point(10, 10)
  p2 = gdi:Point(200, 100)
  c1 = Color.Red
  c2 = Color.Blue
  br = gdi:Brush(p1, p2, c1, c2)
  gra:FillPolygon(br, points, 1)
  gra:TranslateTransform(190, 0);
  gra:FillPolygon(br, points, 0)
  gra:TranslateTransform(-190, 0);
end

function sample_06()
  x = "ハッチブラシ"
  hs = gdi:HatchStyle(1)
  br = gdi:Brush(hs, Color.Red)
  gra:FillPolygon(br, points, 1)
  gra:TranslateTransform(190, 0);
  gra:FillPolygon(br, points, 0)
  gra:TranslateTransform(-190, 0);
end

function sample_07()
  x = "フォント"
  fon = gdi:Font('MS P明朝', 36)
  br = gdi:Brush(Color.Blue)
  gra:DrawString('文字のサンプル', fon, br, 10, 50)
end

function sample_09()
end

function sample(n)
  n = n % 8
  if (n == 0) then
    sample_00()
  elseif (n == 1) then
    sample_01()
  elseif (n == 2) then
    sample_02()
  elseif (n == 3) then
    sample_03()
  elseif (n == 4) then
    sample_04()
  elseif (n == 5) then
    sample_05()
  elseif (n == 6) then
    sample_06()
  elseif (n == 7) then
    sample_07()
  end
end
sample(no)
no = no + 1
 
comments powered by Disqus