GT_box.lua 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. -- luacheck: globals T r disp millis lcg_rnd
  2. local M, module = {}, ...
  3. _G[module] = M
  4. function M.run()
  5. -- make this a volatile module:
  6. package.loaded[module] = nil
  7. print("Running component box...")
  8. local x, y, w, h
  9. local m
  10. disp:setColor(0, 0, 40, 80)
  11. disp:setColor(1, 60, 0, 40)
  12. disp:setColor(2, 128, 0, 140)
  13. disp:setColor(3, 0, 128, 140)
  14. disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
  15. disp:setColor(255, 255, 255)
  16. disp:setPrintPos(2,18)
  17. disp:setPrintDir(0)
  18. disp:print("Box")
  19. m = millis() + T
  20. while millis() < m do
  21. disp:setColor(bit.band(lcg_rnd(), 127)+127, bit.band(lcg_rnd(), 127)+64, bit.band(lcg_rnd(), 31))
  22. w = bit.band(lcg_rnd(), 31)
  23. h = bit.band(lcg_rnd(), 31)
  24. w = w + 10
  25. h = h + 10
  26. x = bit.rshift(lcg_rnd() * (disp:getWidth()-w), 8)
  27. y = bit.rshift(lcg_rnd() * (disp:getHeight()-h-20), 8)
  28. disp:drawBox(x, y+20, w, h)
  29. end
  30. print("...done")
  31. end
  32. return M