Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --keyboard
- function setup()
- -- instantiate the font
- f=HersheyRomanSimplex()
- --instantiate the keyboard
- k=Keyboard()
- tstring = "a"
- end
- function draw()
- rect(0,0,10,10)
- background(0, 0, 0, 255)
- strokeWidth(3)
- stroke(255, 255, 255, 255)
- noSmooth()
- noFill()
- k:draw()
- f:drawstring(tstring,300,600)
- end
- function touched(touch)
- if touch.state == BEGAN then
- tstring = tstring .. k:touched(touch)
- end
- end
- Keyboard = class()
- function Keyboard:init()
- local s = WIDTH/13/4 --spacer
- local k = WIDTH/13 --key
- local a = {"Q","W","E","R","T","Y","U","I","O","P",
- "A","S","D","F","G","H","J","K","L",
- "^","Z","X","C","V","B","N","M","<x",
- ".?123","space","done"}
- local ac = 1 --alpha count
- kb = {} --keyboard
- for i = 1,10 do
- local x = ((s+k)*i)-(k/2)
- local y = (s+k)*4
- kb[ac] = {k=a[ac],x=x,y=y}
- ac = ac + 1
- end
- for i = 1,9 do
- x = (s+k)*i
- y = (s+k)*3
- kb[ac] = {k=a[ac],x=x,y=y}
- ac = ac + 1
- end
- for i = 1,8 do
- x = ((s+k)*i)-(k/2)
- y = (s+k)*2
- kb[ac] = {k=a[ac],x=x,y=y}
- ac = ac + 1
- end
- kb[ac] = {k=a[ac],x=(s+k)*9,y=(s+k)*2}
- ac = ac + 1
- kb[ac] = {k=a[ac],x=(s+k)*2,y=(s+k)}
- ac = ac + 1
- kb[ac] = {k=a[ac],x=(s+k)*5,y=(s+k)}
- ac = ac + 1
- kb[ac] = {k=a[ac],x=(s+k)*8,y=(s+k)}
- end
- function Keyboard:draw()
- rectMode(CENTER)
- local k = WIDTH/13 --key
- for i = 1, 27 do
- f:drawstring(kb[i].k,kb[i].x,kb[i].y)
- rect(kb[i].x,kb[i].y,k,k)
- end
- f:drawstring(kb[28].k,kb[28].x,kb[28].y)
- rect(kb[28].x,kb[28].y,k*2,k)
- for i = 29, 31 do
- f:drawstring(kb[i].k,kb[i].x,kb[i].y)
- rect(kb[i].x,kb[i].y,k*3.5,k)
- end
- end
- function Keyboard:touched(touch)
- local hk = WIDTH/13/2
- for i = 1, 31 do
- local k1 = vec2(kb[i].x,kb[i].y)
- local t1 = vec2(touch.x,touch.y)
- if k1:dist(t1) < hk then
- return kb[i].k
- end
- end
- return ""
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement