Implementing effects. Closes #2 #19
@@ -35,19 +35,27 @@ export const MotionEffects = {
|
|||||||
let newHasHesitated = hasHesitated;
|
let newHasHesitated = hasHesitated;
|
||||||
|
|
||||||
if (target.mode === 'hesitant') {
|
if (target.mode === 'hesitant') {
|
||||||
if (target.fraction >= 0.4 && hasHesitated === false) {
|
if (target.fraction >= 0.35 && hasHesitated === false) {
|
||||||
// Slow down massively instead of stopping
|
// Slow down massively instead of stopping
|
||||||
if (BLE.isConnected()) {
|
if (BLE.isConnected()) {
|
||||||
try { await BLE.write(`SPD:${Math.floor(Math.max(50, Settings.speed * 0.2))}`); } catch(e){}
|
try { await BLE.write(`SPD:${Math.floor(Math.max(30, Settings.speed * 0.1))}`); } catch(e){}
|
||||||
}
|
}
|
||||||
newHasHesitated = true; // Started hesitation
|
newHasHesitated = true; // Started hesitation
|
||||||
} else if (target.fraction >= 0.7 && hasHesitated === true) {
|
} else if (target.fraction >= 0.55 && hasHesitated === true) {
|
||||||
// Speed back up
|
// Speed back up aggressively
|
||||||
if (BLE.isConnected()) {
|
if (BLE.isConnected()) {
|
||||||
try { await BLE.write(`SPD:${Settings.speed}`); } catch(e){}
|
try { await BLE.write(`SPD:${Math.floor(Settings.speed * 1.2)}`); } catch(e){}
|
||||||
}
|
}
|
||||||
newHasHesitated = 2; // Finished hesitation
|
newHasHesitated = 2; // Finished hesitation
|
||||||
}
|
}
|
||||||
|
} else if (target.mode === 'erratic') {
|
||||||
|
// Aggressive speed changes randomly during the move
|
||||||
|
if (Math.random() > 0.4) {
|
||||||
|
if (BLE.isConnected()) {
|
||||||
|
const spd = Math.floor(Math.max(30, Settings.speed * (0.1 + Math.random() * 1.5)));
|
||||||
|
try { await BLE.write(`SPD:${spd}`); } catch(e){}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (target.mode === 'overshoot_settle') {
|
} else if (target.mode === 'overshoot_settle') {
|
||||||
delay = 200; // Brief pause before returning
|
delay = 200; // Brief pause before returning
|
||||||
if (BLE.isConnected()) {
|
if (BLE.isConnected()) {
|
||||||
@@ -108,13 +116,13 @@ export const MotionEffects = {
|
|||||||
applyPerturbation(px, py, nx, ny, fraction, distance, mode) {
|
applyPerturbation(px, py, nx, ny, fraction, distance, mode) {
|
||||||
if (mode === 'snaky') {
|
if (mode === 'snaky') {
|
||||||
const cycles = Math.max(1, Math.floor(distance / 50));
|
const cycles = Math.max(1, Math.floor(distance / 50));
|
||||||
const offset = Math.sin(fraction * Math.PI * 2 * cycles) * 15;
|
const offset = Math.sin(fraction * Math.PI * 2 * cycles) * 30; // 30mm amplitude
|
||||||
px += nx * offset;
|
px += nx * offset;
|
||||||
py += ny * offset;
|
py += ny * offset;
|
||||||
} else if (mode === 'erratic') {
|
} else if (mode === 'erratic') {
|
||||||
// Meaningful jumps
|
// Meaningful, aggressive jumps
|
||||||
px += (Math.random() - 0.5) * 20;
|
px += (Math.random() - 0.5) * 40;
|
||||||
py += (Math.random() - 0.5) * 20;
|
py += (Math.random() - 0.5) * 40;
|
||||||
}
|
}
|
||||||
return { px, py };
|
return { px, py };
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user