OLD | NEW |
(Empty) | |
| 1 function coroutine(generator) { |
| 2 var g = generator(); |
| 3 var promise = g.next().value; |
| 4 function result(r) { |
| 5 promise = g.next(r).value; |
| 6 promise && promise.then(result); |
| 7 } |
| 8 promise.then(result) |
| 9 } |
| 10 |
| 11 function clickOrTouch(x, y) { |
| 12 return new Promise(function(resolve, reject) { |
| 13 window.ontouchstart = function(e) { |
| 14 if (!window.eventSender) |
| 15 console.log('x: ' + e.pageX, ', y: ' + e.pageY, ', region: ' + e.region)
; |
| 16 resolve(e.targetTouches[0].region); |
| 17 }; |
| 18 |
| 19 window.onclick = function(e) { |
| 20 if (!window.eventSender) |
| 21 console.log('x: ' + e.pageX, ', y: ' + e.pageY, ', region: ' + e.region)
; |
| 22 resolve(e.region); |
| 23 }; |
| 24 |
| 25 if (window.eventSender) { |
| 26 eventSender.clearTouchPoints(); |
| 27 eventSender.addTouchPoint(x, y); |
| 28 eventSender.touchStart(); |
| 29 eventSender.touchEnd(); |
| 30 |
| 31 eventSender.mouseMoveTo(x, y); |
| 32 eventSender.mouseDown(); |
| 33 eventSender.mouseUp(); |
| 34 } |
| 35 }); |
| 36 } |
| 37 |
| 38 function createFace(context) { |
| 39 context.fillStyle = 'pink'; |
| 40 context.arc(200, 175, 150, 0, Math.PI * 2, true); |
| 41 context.fill(); |
| 42 context.addHitRegion({ id : 'face', control : document.getElementById('face')
}); |
| 43 |
| 44 context.beginPath(); |
| 45 context.fillStyle = 'black'; |
| 46 context.globalAlpha = .5; |
| 47 context.moveTo(200, 165); |
| 48 context.lineTo(240, 205); |
| 49 context.lineTo(160, 205); |
| 50 context.closePath(); |
| 51 context.fill(); |
| 52 context.addHitRegion({ id : 'nose' }); |
| 53 |
| 54 context.beginPath(); |
| 55 context.fillStyle = 'red'; |
| 56 context.rect(125, 240, 150, 20); |
| 57 context.fill(); |
| 58 context.addHitRegion({ id : 'mouth' }); |
| 59 |
| 60 context.beginPath(); |
| 61 context.globalAlpha = 1; |
| 62 context.fillStyle = 'blue'; |
| 63 context.arc(150, 125, 25, 0, Math.PI * 2, true); |
| 64 context.arc(250, 125, 25, 0, Math.PI * 2, true); |
| 65 context.fill(); |
| 66 context.addHitRegion({ id: 'eye', control : document.getElementById('eyes') })
; |
| 67 } |
OLD | NEW |