(values, labelPrefix)
| 98 | } |
| 99 | |
| 100 | function onReading(values, labelPrefix){ |
| 101 | let { x, y, z } = values; |
| 102 | |
| 103 | render.begin(0, 0, width, ball.yMin); |
| 104 | render.fillRectangle(backgroundColor, 0, 0, width, height); |
| 105 | |
| 106 | drawBar(labelPrefix + "X", x, 0, 0, width, font.height); |
| 107 | drawBar(labelPrefix + "Y", y, 0, font.height, width, font.height); |
| 108 | drawBar(labelPrefix + "Z", z, 0, font.height * 2, width, font.height); |
| 109 | render.end(); |
| 110 | |
| 111 | ball.vx = (ball.vx - y) * 0.98; |
| 112 | ball.vy = (ball.vy + x) * 0.98; |
| 113 | let nx = ball.x + ball.vx; |
| 114 | let ny = ball.y + ball.vy; |
| 115 | if (nx < 0) { |
| 116 | nx = -nx; |
| 117 | ball.vx = -ball.vx; |
| 118 | } |
| 119 | else if (nx > (width - ball.width)) { |
| 120 | nx = width - ball.width; |
| 121 | ball.vx = -ball.vx; |
| 122 | } |
| 123 | if (ny < ball.yMin) { |
| 124 | ny = ball.yMin; |
| 125 | ball.vy = -ball.vy; |
| 126 | } |
| 127 | else if (ny > (height - ball.height)) { |
| 128 | ny = height - ball.height; |
| 129 | ball.vy = -ball.vy; |
| 130 | } |
| 131 | moveBallTo(nx, ny) |
| 132 | } |
| 133 | |
| 134 | |
| 135 | function formatValue(value) { |
no test coverage detected