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