Advertisement
SifakaMon

Seg16

Dec 25th, 2011
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. -- Seg16 copyright 2011 JEM <SifakaMon@gmail.com>, reuse allowed under a modified MIT license term
  2. --  --- ---
  3. -- | \ | / |
  4. --  --- ---
  5. -- | / | \ |
  6. --  ---.---
  7. -- Markers:
  8. --   a   b
  9. -- c d e f g
  10. --   h   i
  11. -- j k l m n
  12. --   o q p
  13. -- notice I cheated and made it a 17 segment display (for decimal)
  14. -- version 2 adds a parameter for aspect ratio
  15.  
  16. function seg16draw(x, y, str, measure, aspect)
  17.     if aspect == nil then aspect = 1.4 end
  18.     sz = sz / aspect
  19.     for c in str:gmatch(".") do
  20.         local d = seg16char[c]
  21.         if d ~= nil then
  22.             for s in d:gmatch(".") do
  23.                 p = seg16seg[s]
  24.                 if p ~= nil and measure ~= true then
  25.                     line(x+p[1] * sz,y+p[2] * sz * aspect,x+p[3] * sz,y+p[4] * sz * aspect)
  26.                 end
  27.             end
  28.         end
  29.         x = x + 1.3 * sz
  30.     end
  31.     return x
  32. end
  33.  
  34. seg16seg = {
  35.     a = {0,1,.5,1},
  36.     b = {.5,1,1,1},
  37.     c = {0,1,0,.5},
  38.     d = {0,1,.5,.5},
  39.     e = {.5,1,.5,.5},
  40.     f = {.5,.5,1,1},
  41.     g = {1,1,1,.5},
  42.     h = {0,.5,.5,.5},
  43.     i = {.5,.5,1,.5},
  44.     j = {0,.5,0,0},
  45.     k = {0,0,.5,.5},
  46.     l = {.5,.5,.5,0},
  47.     m = {.5,.5,1,0},
  48.     n = {1,.5,1,0},
  49.     o = {0,0,.5,0},
  50.     p = {.5,0,1,0},
  51.     q = {.5,0,.5,0.1}
  52. }
  53.  
  54. seg16char = {
  55.     ["_"] = "op",
  56.     ["|"] = "el",
  57.     ["/"] = "kf",
  58.     ["\\"]= "md",
  59.     ["-"] = "hi",
  60.     ["="] = "ohpi",
  61.     ["."] = "q",
  62.     [","] = "k",
  63.     ["0"] = "kfabgnpojc",
  64.     ["1"] = "fgn",
  65.     ["2"] = "abgihjop",
  66.     ["3"] = "abgihnpo",
  67.     ["4"] = "chign",
  68.     ["5"] = "bachinpo",
  69.     ["6"] = "bacjopnih",
  70.     ["7"] = "abfk",
  71.     ["8"] = "abgnpojchi",
  72.     ["9"] = "ihcabgnpo",
  73.     A = "jcabgnhi",
  74.     B = "abgnopeil",
  75.     C = "bacjop",
  76.     D = "abgnopel",
  77.     E = "bachjop",
  78.     F = "bacjh",
  79.     G = "bacjopni",
  80.     H = "cjhign",
  81.     I = "abelop",
  82.     J = "bgnpoj",
  83.     K = "cjhfm",
  84.     L = "cjop",
  85.     M = "jcdfgn",
  86.     N = "jcdmng",
  87.     O = "abgnpojc",
  88.     P = "abjihcjg",
  89.     Q = "abgnmpojc",
  90.     R = "abjihcmjg",
  91.     S = "badinpo",
  92.     T = "abel",
  93.     U = "cjopng",
  94.     V = "dmng",
  95.     W = "cjkmng",
  96.     X = "dfkm",
  97.     Y = "dfl",
  98.     Z = "abfkop"
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement