(values, labelPrefix)
| 66 | } |
| 67 | |
| 68 | function onReading(values, labelPrefix){ |
| 69 | const { x, y, z } = values; |
| 70 | // trace(`${labelPrefix}X: ${formatValue(x)} - ${labelPrefix}Y: ${formatValue(y)} - ${labelPrefix}Z: ${formatValue(z)}\n`); |
| 71 | render.begin(0, 0, width, ball.yMin); |
| 72 | render.fillRectangle(backgroundColor, 0, 0, width, height); |
| 73 | |
| 74 | drawBar(`${labelPrefix}X`, x, 0, 0, width, font.height); |
| 75 | drawBar(`${labelPrefix}Y`, y, 0, font.height, width, font.height); |
| 76 | drawBar(`${labelPrefix}Z`, z, 0, font.height * 2, width, font.height); |
| 77 | render.end(); |
| 78 | |
| 79 | ball.vx = (ball.vx + x) * 0.98; |
| 80 | ball.vy = (ball.vy - y) * 0.98; |
| 81 | let nx = ball.x + ball.vx; |
| 82 | let ny = ball.y + ball.vy; |
| 83 | if (nx < 0) { |
| 84 | nx = -nx; |
| 85 | ball.vx = -ball.vx * 0.7; |
| 86 | } |
| 87 | else if (nx > (width - ball.width)) { |
| 88 | nx = width - ball.width; |
| 89 | ball.vx = -ball.vx * 0.7; |
| 90 | } |
| 91 | if (ny < ball.yMin) { |
| 92 | ny = ball.yMin; |
| 93 | ball.vy = -ball.vy * 0.7; |
| 94 | } |
| 95 | else if (ny > (height - ball.height)) { |
| 96 | ny = height - ball.height; |
| 97 | ball.vy = -ball.vy * 0.7; |
| 98 | } |
| 99 | moveBallTo(nx, ny) |
| 100 | } |
| 101 | |
| 102 | function formatValue(value) { |
| 103 | if (!value) |
no test coverage detected