MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / onReading

Function onReading

examples/drivers/atoms3-imu/main.js:68–100  ·  view source on GitHub ↗
(values, labelPrefix)

Source from the content-addressed store, hash-verified

66}
67
68function 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
102function formatValue(value) {
103 if (!value)

Callers 1

main.jsFile · 0.70

Calls 5

drawBarFunction · 0.70
moveBallToFunction · 0.70
beginMethod · 0.65
fillRectangleMethod · 0.65
endMethod · 0.65

Tested by

no test coverage detected