(5.3)部分プログラムを使って壁と底を描く

-- 5.3 部分プログラムを使って壁と底を描く

---部分プログラム(どこから, 1 辺いくつの正方形を, どの方向で, 何個描く, gc) -----
function drawBlocks(x, y, sideLen, direction, number, gc)
   local a; local b
   if direction == "tate"
      then a = 0; b = 1
   elseif direction == "yoko"
      then a = 1; b = 0
   end
   for i = 0, number - 1 do
      gc:fillRect(x + (sideLen * i) * a, y + (sideLen * i) * b, sideLen, sideLen)
   end
end
---------------------------------------------------------------------------------

function on.paint(gc)
   -- (10, 20) から、1 辺 10 の正方形を、縦方向に、10 個描く
   drawBlocks(10, 20, 10, "tate", 10, gc)
   
   -- (50, 50) から、1 辺 40 の正方形を、横方向に、3 個描く
   drawBlocks(50, 50, 40, "yoko", 3, gc)
end

ハンドへルド・ビュー:
f:id:ti-nspire:20150210072341j:plain


参考文献: