Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Touch demo
- -- by @beezing
- sin = math.sin
- cos = math.cos
- random = math.random
- drawText = writeTextAtPosition
- x0 = -1
- y0 = -1
- function setRandomColors(val)
- setColor(random(val), random(val), random(val))
- end
- function rectangle(x, y, width, height)
- move(x, y)
- draw(x+width, y)
- draw(x+width, y+height)
- draw(x, y+height)
- draw(x, y)
- end
- function circle(x, y, r)
- move(x+r, y)
- for i = 0, 3.14*2+0.1, 0.1 do
- draw(x+r*cos(i), y+r*sin(i))
- end
- end
- function follow(x,y)
- setLineWidth(2)
- setColor(255,255,255)
- circle(x0,y0,29)
- circle(x0,y0,30)
- circle(x0,y0,31)
- setLineWidth(1)
- setColor(0,0,0)
- circle(x,y,30)
- end
- function doodle(x,y)
- --drawPoint(x,y)
- draw(x,y)
- end
- function dot(x,y)
- setRandomColors(192)
- setLineWidth(25)
- circle(x,y,1)
- setLineWidth(random(3))
- end
- function drawButton(x,y,w,h,t)
- setLineWidth(2)
- rectangle(x,y,w,h)
- drawText(t,x+28,y+24)
- drawText(t,x+29,y+24)
- end
- function setupCanvas()
- clearCanvas()
- setColor(0,0,0)
- drawButton(100,110,124,30,'C L E A R')
- drawText('Touch and doodle...', 100,100)
- move(384,384)
- setRandomColors(192)
- end
- function touched(x, y)
- return (x > 0) and (y > 0)
- end
- function touch()
- x,y = currentTouch()
- if touched(x,y) then
- --draw(x,y)
- --move(x,y)
- if (x > 100) and (x < 224) and
- (y > 110) and (y < 140) then
- setColor(192,0,0)
- drawButton(100,110,124,30,'C L E A R')
- else
- doodle(x,y)
- --follow(x,y)
- end
- x0 = x
- y0 = y
- end
- end
- function tap()
- x,y = lastTouch()
- if touched(x,y) then
- --draw(x,y)
- move(x,y)
- if (x > 100) and (x < 224) and
- (y > 110) and (y < 140) then
- setupCanvas()
- else
- dot(x,y)
- end
- x0 = x
- y0 = y
- end
- end
- setupCanvas()
- while true do
- disableScreenRefresh()
- touch()
- tap()
- enableScreenRefresh()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement