Advertisement
Guest User

Codify codea keyboard

a guest
Nov 23rd, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. --keyboard
  2.  
  3. function setup()
  4.    -- instantiate the font
  5.    f=HersheyRomanSimplex()
  6.     --instantiate the keyboard
  7.    k=Keyboard()
  8.     tstring = "a"
  9. end
  10.  
  11. function draw()
  12.     rect(0,0,10,10)
  13.     background(0, 0, 0, 255)
  14.     strokeWidth(3)
  15.     stroke(255, 255, 255, 255)
  16.     noSmooth()
  17.     noFill()
  18.     k:draw()  
  19.     f:drawstring(tstring,300,600)  
  20. end
  21.  
  22. function touched(touch)
  23.     if touch.state == BEGAN then
  24.         tstring = tstring .. k:touched(touch)
  25.     end
  26. end
  27.  
  28.  
  29. Keyboard = class()
  30.  
  31. function Keyboard:init()
  32.     local s = WIDTH/13/4 --spacer
  33.     local k = WIDTH/13 --key
  34.     local a = {"Q","W","E","R","T","Y","U","I","O","P",
  35.          "A","S","D","F","G","H","J","K","L",
  36.          "^","Z","X","C","V","B","N","M","<x",
  37.          ".?123","space","done"}
  38.     local ac = 1 --alpha count
  39.     kb = {} --keyboard
  40.     for i = 1,10 do
  41.         local x = ((s+k)*i)-(k/2)
  42.         local y = (s+k)*4
  43.         kb[ac] = {k=a[ac],x=x,y=y}
  44.         ac = ac + 1
  45.     end    
  46.     for i = 1,9 do
  47.         x = (s+k)*i
  48.         y = (s+k)*3
  49.         kb[ac] = {k=a[ac],x=x,y=y}
  50.         ac = ac + 1
  51.     end    
  52.     for i = 1,8 do
  53.         x = ((s+k)*i)-(k/2)
  54.         y = (s+k)*2
  55.         kb[ac] = {k=a[ac],x=x,y=y}
  56.         ac = ac + 1
  57.     end
  58.     kb[ac] = {k=a[ac],x=(s+k)*9,y=(s+k)*2}
  59.     ac = ac + 1
  60.     kb[ac] = {k=a[ac],x=(s+k)*2,y=(s+k)}
  61.     ac = ac + 1
  62.     kb[ac] = {k=a[ac],x=(s+k)*5,y=(s+k)}
  63.     ac = ac + 1
  64.     kb[ac] = {k=a[ac],x=(s+k)*8,y=(s+k)} 
  65. end
  66.  
  67. function Keyboard:draw()
  68.     rectMode(CENTER)
  69.     local k = WIDTH/13 --key
  70.     for i = 1, 27 do
  71.         f:drawstring(kb[i].k,kb[i].x,kb[i].y)
  72.         rect(kb[i].x,kb[i].y,k,k)
  73.     end
  74.     f:drawstring(kb[28].k,kb[28].x,kb[28].y)
  75.     rect(kb[28].x,kb[28].y,k*2,k)
  76.     for i = 29, 31 do
  77.         f:drawstring(kb[i].k,kb[i].x,kb[i].y)
  78.         rect(kb[i].x,kb[i].y,k*3.5,k)
  79.     end
  80. end
  81.  
  82. function Keyboard:touched(touch)
  83.     local hk = WIDTH/13/2
  84.     for i = 1, 31 do
  85.         local k1 = vec2(kb[i].x,kb[i].y) 
  86.         local t1 = vec2(touch.x,touch.y)
  87.         if k1:dist(t1) < hk then
  88.             return kb[i].k
  89.         end    
  90.     end  
  91.     return ""  
  92. end
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement