Agent generated a plotter wooohooo

This commit is contained in:
antonl 2026-02-01 16:42:53 +01:00
parent ea6bb1f353
commit 03a272f059
10 changed files with 455 additions and 0 deletions

9
.gitignore vendored
View File

@ -220,3 +220,12 @@ build-iPhoneSimulator/
# Go workspace file # Go workspace file
go.work go.work
# ---> Python
__pycache__/
*.py[cod]
# ---> Simulation Data
*.bin
simulation.bin

38
generate_mock_data.py Normal file
View File

@ -0,0 +1,38 @@
import struct
import math
import random
def generate_bin(filename="simulation.bin", points=200):
# Magic Number: 0xFEAA01
MAGIC = 0xFEAA01
x_data = []
y_data = []
# Generate Sine Wave with random noise/phase to show updates
phase_shift = random.random() * math.pi
for i in range(points):
x = (i / points) * (4 * math.pi)
y = math.sin(x + phase_shift)
x_data.append(x)
y_data.append(y)
# Pack Data
# Header: Magic (I), Count (I)
header = struct.pack('<II', MAGIC, points)
# Body: X floats (f), Y floats (f)
body_x = struct.pack(f'<{points}f', *x_data)
body_y = struct.pack(f'<{points}f', *y_data)
with open(filename, 'wb') as f:
f.write(header)
f.write(body_x)
f.write(body_y)
print(f"Generated {filename} with {points} points (Phase: {phase_shift:.2f})")
if __name__ == "__main__":
generate_bin()

38
index.html Normal file
View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Antigravity Plotter</title>
<link rel="stylesheet" href="style.css">
<!-- Load Chart.js from local lib folder (UMD Build) -->
<script src="lib/chart.js"></script>
<!-- Load App Scripts (Order Matters for Non-Modules) -->
<script src="js/data.js"></script>
<script src="js/plotter.js"></script>
<script src="js/main.js"></script>
</head>
<body>
<header>
<h1>Finite Element Interface</h1>
<div id="status-text" class="status">System Ready</div>
<button onclick="window.refreshPlot()"
style="margin-top: 10px; padding: 5px 10px; cursor: pointer; background: var(--accent-cyan); border: none; border-radius: 4px; font-weight: bold;">Refresh
Data</button>
</header>
<main>
<div id="loading">Initializing...</div>
<canvas id="plotCanvas"></canvas>
</main>
<!-- Load App Scripts -->
<script src="js/data.js"></script> <!-- Optional fallback -->
<script src="js/data_loader.js"></script>
<script src="js/plotter.js"></script>
<script src="js/main.js"></script>
</html>

22
js/data.js Normal file
View File

@ -0,0 +1,22 @@
/**
* Generates sine wave data.
* Attached to window to avoid ES Module CORS issues on file:// protocol.
*/
(function (global) {
global.DataGenerator = {
generateSineWave(points = 100, cycles = 2 * Math.PI) {
const labels = [];
const data = [];
for (let i = 0; i <= points; i++) {
const x = (i / points) * cycles;
const y = Math.sin(x);
labels.push(x.toFixed(2));
data.push(y);
}
return { labels, data };
}
};
})(window);

62
js/data_loader.js Normal file
View File

@ -0,0 +1,62 @@
/**
* Handles Binary Data Ingestion via Fetch.
*/
(function (global) {
global.DataLoader = {
/**
* Fetches and parses the binary simulation data.
* @param {string} url - URL to the binary file.
* @returns {Promise<Object>} - { labels, data } or error.
*/
async loadBinary(url = 'simulation.bin') {
try {
const response = await fetch(url, { cache: "no-store" });
if (!response.ok) throw new Error(`HTTP Error: ${response.status}`);
const buffer = await response.arrayBuffer();
return this.parseBuffer(buffer);
} catch (err) {
console.error("Load Failed:", err);
throw err;
}
},
parseBuffer(buffer) {
const dataView = new DataView(buffer);
let offset = 0;
// 1. Read Header
const magic = dataView.getUint32(offset, true); // Little Endian
offset += 4;
const count = dataView.getUint32(offset, true);
offset += 4;
if (magic !== 0xFEAA01) {
throw new Error(`Invalid Magic Number: 0x${magic.toString(16)}`);
}
// 2. Read X Data
const xData = [];
for (let i = 0; i < count; i++) {
xData.push(dataView.getFloat32(offset, true));
offset += 4;
}
// 3. Read Y Data
const yData = [];
for (let i = 0; i < count; i++) {
yData.push(dataView.getFloat32(offset, true));
offset += 4;
}
// Format for Plotter (Labels as strings/numbers, Data as numbers)
// Plotter expects labels, but for scatter/line with x,y numbers we might adjust plotter.
// For now, mapping X to labels is fine for simple line plots.
return {
labels: xData.map(x => x.toFixed(2)),
data: yData
};
}
};
})(window);

43
js/main.js Normal file
View File

@ -0,0 +1,43 @@
/**
* Main Application Entry Point.
* Non-module version.
*/
document.addEventListener('DOMContentLoaded', () => {
console.log('Antigravity Plotter Initializing...');
// Basic error check for dependencies
if (typeof DataGenerator === 'undefined' || typeof Plotter === 'undefined') {
document.getElementById('loading').innerHTML = "Script Error: JS files not loaded correctly.<br>Check console (F12) for details.";
return;
}
try {
// Initialize Plotter
const plotter = new Plotter('plotCanvas');
// Data Load Logic
const loadData = async () => {
try {
document.getElementById('status-text').textContent = "Status: Loading Data...";
const { labels, data } = await DataLoader.loadBinary('simulation.bin');
plotter.update(labels, data);
document.getElementById('status-text').textContent = "Status: Data Loaded (" + data.length + " points)";
} catch (err) {
console.error(err);
document.getElementById('status-text').textContent = "Error: " + err.message;
}
};
// Initial Load
loadData();
// Expose refresh for button
window.refreshPlot = loadData;
} catch (e) {
console.error(e);
document.getElementById('loading').textContent = "Runtime Error: " + e.message;
}
});

115
js/plotter.js Normal file
View File

@ -0,0 +1,115 @@
/**
* Wrapper around Chart.js.
* Attached to window to avoid ES Module CORS issues on file:// protocol.
*/
(function (global) {
class Plotter {
constructor(canvasId) {
this.canvas = document.getElementById(canvasId);
this.ctx = this.canvas.getContext('2d');
this.chart = null;
this.init();
}
init() {
// Check if Chart is loaded
if (typeof Chart === 'undefined') {
console.error("Chart.js is not loaded!");
document.getElementById('loading').textContent = "Error: Chart.js library not found in lib/chart.js";
return;
}
// Gradient for the line
const gradient = this.ctx.createLinearGradient(0, 0, this.canvas.width, 0);
gradient.addColorStop(0, '#00f2ff'); // Cyan
gradient.addColorStop(1, '#bd00ff'); // Purple
Chart.defaults.color = '#8888aa';
Chart.defaults.font.family = "'Inter', 'Roboto', sans-serif";
this.chart = new Chart(this.ctx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Sine Wave',
data: [],
borderColor: '#00f2ff', // Fallback
backgroundColor: 'rgba(0, 242, 255, 0.1)',
borderWidth: 3,
tension: 0.4,
pointRadius: 0,
pointHoverRadius: 6,
fill: true,
shadowColor: 'rgba(0, 242, 255, 0.5)',
shadowBlur: 10
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
interaction: {
mode: 'index',
intersect: false,
},
plugins: {
legend: { display: false },
tooltip: {
backgroundColor: 'rgba(10, 10, 16, 0.8)',
titleColor: '#fff',
bodyColor: '#ccc',
borderColor: 'rgba(0, 242, 255, 0.3)',
borderWidth: 1,
backdropFilter: 'blur(4px)'
}
},
scales: {
x: {
grid: { color: 'rgba(255, 255, 255, 0.05)', borderColor: 'transparent' },
ticks: { maxTicksLimit: 10 }
},
y: {
grid: { color: 'rgba(255, 255, 255, 0.05)', borderColor: 'transparent' },
min: -1.2,
max: 1.2
}
},
animation: {
duration: 1500,
easing: 'easeOutQuart'
}
}
});
}
update(labels, data) {
if (!this.chart) return;
this.chart.data.labels = labels;
this.chart.data.datasets[0].data = data;
const gradient = this.ctx.createLinearGradient(0, 0, this.ctx.canvas.width, 0);
gradient.addColorStop(0, '#00f2ff');
gradient.addColorStop(0.5, '#7000ff');
gradient.addColorStop(1, '#ff0055');
this.chart.data.datasets[0].borderColor = gradient;
this.chart.data.datasets[0].backgroundColor = (context) => {
const ctx = context.chart.ctx;
const gradient = ctx.createLinearGradient(0, 0, 0, ctx.canvas.height);
gradient.addColorStop(0, 'rgba(0, 242, 255, 0.2)');
gradient.addColorStop(1, 'rgba(0, 242, 255, 0)');
return gradient;
};
this.chart.update();
// Hide loading text on first successful update
const loading = document.getElementById('loading');
if (loading) loading.style.display = 'none';
}
}
global.Plotter = Plotter;
})(window);

20
lib/chart.js Normal file

File diff suppressed because one or more lines are too long

15
setup_instructions.md Normal file
View File

@ -0,0 +1,15 @@
# Setup Instructions
Since we are not using a package manager, you need to manually download the Chart.js library.
1. **Download Chart.js**
- Click this link: [Chart.js UMD Build](https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js)
- Right-click the page/code and select "Save Page As..." (or "Save As...").
- Save the file as `chart.js` inside the `lib` folder of your project.
- **Path**: `e:\dev\antigrav_lab\lib\chart.js`
2. **Verify**
- Ensure the file exists at `lib\chart.js`.
3. **Run**
- Open `index.html` in your browser.

93
style.css Normal file
View File

@ -0,0 +1,93 @@
:root {
--bg-color: #050508;
--panel-bg: rgba(20, 20, 30, 0.4);
--text-primary: #ffffff;
--text-secondary: #8888aa;
--accent-cyan: #00f2ff;
--accent-purple: #bd00ff;
--glass-border: rgba(255, 255, 255, 0.08);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: var(--bg-color);
color: var(--text-primary);
width: 100vw;
height: 100vh;
overflow: hidden;
display: flex;
flex-direction: column;
}
/* Header / Controls Overlay */
header {
position: absolute;
top: 20px;
left: 20px;
z-index: 10;
background: var(--panel-bg);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
padding: 1rem 1.5rem;
border-radius: 12px;
border: 1px solid var(--glass-border);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
h1 {
font-size: 1rem;
font-weight: 500;
letter-spacing: 0.05em;
color: var(--text-primary);
text-transform: uppercase;
display: flex;
align-items: center;
gap: 10px;
}
h1::before {
content: '';
display: block;
width: 8px;
height: 8px;
background-color: var(--accent-cyan);
border-radius: 50%;
box-shadow: 0 0 10px var(--accent-cyan);
}
.status {
font-size: 0.75rem;
color: var(--text-secondary);
margin-top: 4px;
}
/* Main Canvas Area */
main {
flex: 1;
position: relative;
width: 100%;
/* User requested 20% margin top/bottom, 10% left/right */
padding: 20vh 10vw;
}
canvas {
display: block;
width: 100%;
height: 100%;
}
/* Instructions Overlay (if js fails or loading) */
#loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: var(--text-secondary);
pointer-events: none;
}