Added preset button handlers
This commit is contained in:
38
script.js
38
script.js
@ -78,8 +78,8 @@ class SwerveDrive {
|
||||
// Preset robot generators
|
||||
const PresetConfigs = {
|
||||
twoWheel: (size) => [
|
||||
{ x: 0, y: size / 2, name: "Left" },
|
||||
{ x: 0, y: -size / 2, name: "Right" }
|
||||
{ x: size / 2, y: 0, name: "Left" },
|
||||
{ x: -size / 2, y: 0, name: "Right" }
|
||||
],
|
||||
|
||||
threeWheel: (size) => {
|
||||
@ -287,7 +287,8 @@ function drawRobot(ctx, robot) {
|
||||
|
||||
|
||||
// Initialize Variables
|
||||
const robot = new SwerveDrive(PresetConfigs.eightWheel(200));
|
||||
const robotSize = 200;
|
||||
const robot = new SwerveDrive(PresetConfigs.fourWheelSquare(robotSize));
|
||||
let xSpeed = 0;
|
||||
let ySpeed = 0;
|
||||
let turnSpeed = -1;
|
||||
@ -298,6 +299,37 @@ let xGridOffset = 0;
|
||||
let yGridOffset = 0;
|
||||
robot.drive(xSpeed, ySpeed, 0, 500);
|
||||
|
||||
// Preset button event listeners
|
||||
preset2WheelBtn.addEventListener('click', () => {
|
||||
const positions = PresetConfigs.twoWheel(robotSize);
|
||||
robot.setModules(positions);
|
||||
});
|
||||
|
||||
preset3WheelBtn.addEventListener('click', () => {
|
||||
const positions = PresetConfigs.threeWheel(robotSize);
|
||||
robot.setModules(positions);
|
||||
});
|
||||
|
||||
preset4WheelBtn.addEventListener('click', () => {
|
||||
const positions = PresetConfigs.fourWheelSquare(robotSize);
|
||||
robot.setModules(positions);
|
||||
});
|
||||
|
||||
preset4RectBtn.addEventListener('click', () => {
|
||||
const positions = PresetConfigs.fourWheelRectangle(robotSize);
|
||||
robot.setModules(positions);
|
||||
});
|
||||
|
||||
preset6WheelBtn.addEventListener('click', () => {
|
||||
const positions = PresetConfigs.sixWheel(robotSize);
|
||||
robot.setModules(positions);
|
||||
});
|
||||
|
||||
preset8WheelBtn.addEventListener('click', () => {
|
||||
const positions = PresetConfigs.eightWheel(robotSize);
|
||||
robot.setModules(positions);
|
||||
});
|
||||
|
||||
function animate() {
|
||||
// Clear and set up canvas
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
Reference in New Issue
Block a user