Advertisement
hevohevo

CC: exercise9_2

May 19th, 2016
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. -- exercise9_2
  2. -- L字型を上下に動かす
  3.  
  4. -- Functions
  5. function init()
  6.   term.setTextColor(colors.white)
  7.   term.setBackgroundColor(colors.black)
  8.   term.clear()
  9. end
  10.  
  11. function drawPoint(x,y,color)
  12.   term.setBackgroundColor(color)
  13.   term.setCursorPos(x,y)
  14.   term.write(" ")
  15. end
  16.  
  17. function drawLShape(x,y,color)
  18.   drawPoint(x,y,color)
  19.   drawPoint(x,y+1,color)
  20.   drawPoint(x,y+2,color)
  21.   drawPoint(x+1,y+2,color)
  22.   drawPoint(x+2,y+2,color)
  23. end
  24.  
  25. -- Main
  26. local y = 1
  27.  
  28. while true do
  29.   init()  -- 画面を初期化する
  30.   drawLShape(2, y, colors.red)  -- 指定した座標に指定した色で点を描く
  31.  
  32.   local event, moji = os.pullEvent("char")
  33.   if moji == "z" then
  34.     y = y + 1
  35.   else
  36.     y = y - 1
  37.   end
  38.  
  39.   os.sleep(0.3)  -- 0.5秒待つ
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement