-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add VEX Robotics Autonomous Path Planner page
The commit adds a new HTML page for the VEX Robotics Autonomous Path Planner. It includes the necessary HTML, CSS, and JavaScript code to create a canvas where users can draw a path and generate corresponding code. The page also includes buttons to clear the path and generate the code. Note: The commit message has been generated based on the provided code changes and recent repository commits.
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Path Planner</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background-color: #f0f0f0; | ||
} | ||
#container { | ||
text-align: center; | ||
} | ||
canvas { | ||
border: 2px solid #333; | ||
} | ||
button { | ||
margin: 10px; | ||
padding: 5px 10px; | ||
font-size: 16px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<h1>VEX Robotics Autonomous Path Planner</h1> | ||
<div id="canvas-container"></div> | ||
<button onclick="clearPath()">Clear Path</button> | ||
<button onclick="generateCode()">Generate Code</button> | ||
<pre id="code-output"></pre> | ||
</div> | ||
|
||
<script> | ||
let path = []; | ||
const gridSize = 20; | ||
const canvasSize = 400; | ||
|
||
function setup() { | ||
let canvas = createCanvas(canvasSize, canvasSize); | ||
canvas.parent('canvas-container'); | ||
background(220); | ||
drawGrid(); | ||
} | ||
|
||
function draw() { | ||
if (mouseIsPressed) { | ||
let x = Math.floor(mouseX / gridSize) * gridSize; | ||
let y = Math.floor(mouseY / gridSize) * gridSize; | ||
if (!path.some(p => p.x === x && p.y === y)) { | ||
path.push({ x, y }); | ||
} | ||
} | ||
|
||
background(220); | ||
drawGrid(); | ||
drawPath(); | ||
} | ||
|
||
function drawGrid() { | ||
stroke(200); | ||
for (let i = 0; i <= canvasSize; i += gridSize) { | ||
line(i, 0, i, canvasSize); | ||
line(0, i, canvasSize, i); | ||
} | ||
} | ||
|
||
function drawPath() { | ||
if (path.length > 0) { | ||
stroke(0, 0, 255); | ||
strokeWeight(3); | ||
noFill(); | ||
beginShape(); | ||
for (let point of path) { | ||
vertex(point.x + gridSize / 2, point.y + gridSize / 2); | ||
} | ||
endShape(); | ||
|
||
fill(255, 0, 0); | ||
noStroke(); | ||
for (let i = 0; i < path.length; i++) { | ||
ellipse(path[i].x + gridSize / 2, path[i].y + gridSize / 2, 10); | ||
textAlign(CENTER, CENTER); | ||
fill(0); | ||
text(i + 1, path[i].x + gridSize / 2, path[i].y + gridSize / 2); | ||
} | ||
} | ||
} | ||
|
||
function clearPath() { | ||
path = []; | ||
} | ||
|
||
function generateCode() { | ||
let code = "// Exported snippet - v1 format\n"; | ||
code += "void autonomous() {\n"; | ||
|
||
for (let i = 1; i < path.length; i++) { | ||
let dx = path[i].x - path[i-1].x; | ||
let dy = path[i].y - path[i-1].y; | ||
let distance = Math.sqrt(dx*dx + dy*dy); | ||
let angle = Math.atan2(dy, dx) * 180 / Math.PI; | ||
|
||
code += ` // Move to point ${i+1}\n`; | ||
code += ` turnToAngle(${angle});\n`; | ||
code += ` moveForward(${distance});\n`; | ||
} | ||
|
||
code += "}\n"; | ||
|
||
document.getElementById('code-output').textContent = code; | ||
} | ||
</script> | ||
</body> | ||
</html> |