gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
Can you please write html, css, js code for the following: I want a framework that can…
- User
Can you please write html, css, js code for the following: I want a framework that can do the following
- Show boxes with arrows between them
- Add sliders
- add a graph (use a framework)
- create a simulation loop that can be resetted
- Assistant
Absolutely! Here’s a simple framework that meets your requirements:
- Boxes with arrows between them (using SVG for arrows)
- Sliders (to control parameters)
- A graph (using Chart.js)
- A simulation loop (with start, pause, and reset functionality)
This is a minimal, extendable example. You can expand it as needed.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Simulation Framework</title> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <style> body { font-family: Arial, sans-serif; margin: 20px; } .container { display: flex; gap: 40px; } .diagram { position: relative; width: 300px; height: 200px; } .box { position: absolute; width: 80px; height: 40px; background: #e0e0e0; border: 2px solid #888; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: bold; } .box1 { top: 40px; left: 20px; } .box2 { top: 120px; left: 200px; } .sliders { margin-top: 20px; } .slider-group { margin-bottom: 10px; } .controls { margin-top: 20px; } canvas { background: #fff; border: 1px solid #ccc; } </style> </head> <body> <h2>Simulation Framework Example</h2> <div class="container"> <!-- Diagram with boxes and arrows --> <div> <div class="diagram" id="diagram"> <div class="box box1" id="box1">Box 1</div> <div class="box box2" id="box2">Box 2</div> <svg width="300" height="200" style="position:absolute;top:0;left:0;pointer-events:none;"> <defs> <marker id="arrowhead" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto"> <polygon points="0 0, 10 3.5, 0 7" fill="#333"/> </marker> </defs> <line x1="100" y1="60" x2="200" y2="140" stroke="#333" stroke-width="3" marker-end="url(#arrowhead)" /> </svg> </div> <!-- Sliders --> <div class="sliders"> <div class="slider-group"> <label>Parameter A: <span id="paramAValue">50</span></label><br> <input type="range" id="paramA" min="0" max="100" value="50"> </div> <div class="slider-group"> <label>Parameter B: <span id="paramBValue">25</span></label><br> <input type="range" id="paramB" min="0" max="50" value="25"> </div> </div> <!-- Controls --> <div class="controls"> <button id="startBtn">Start</button> <button id="pauseBtn">Pause</button> <button id="resetBtn">Reset</button> </div> </div> <!-- Graph --> <div> <canvas id="myChart" width="400" height="300"></canvas> </div> </div> <script> // Sliders const paramA = document.getElementById('paramA'); const paramB = document.getElementById('paramB'); const paramAValue = document.getElementById('paramAValue'); const paramBValue = document.getElementById('paramBValue'); paramA.oninput = () => paramAValue.textContent = paramA.value; paramB.oninput = () => paramBValue.textContent = paramB.value; // Chart.js setup const ctx = document.getElementById('myChart').getContext('2d'); const chartData = { labels: [], datasets: [{ label: 'Simulation Output', data: [], borderColor: 'blue', fill: false, tension: 0.1 }] }; const myChart = new Chart(ctx, { type: 'line', data: chartData, options: { animation: false, scales: { x: { title: { display: true, text: 'Time' } }, y: { title: { display: true, text: 'Value' } } } } }); // Simulation loop let running = false; let time = 0; let simInterval = null; function stepSimulation() { // Example: output = paramA * sin(time) + paramB const a = Number(paramA.value); const b = Number(paramB.value); const output = a * Math.sin(time / 10) + b; chartData.labels.push(time); chartData.datasets[0].data.push(output); myChart.update(); time++; if (chartData.labels.length > 50) { // keep last 50 points chartData.labels.shift(); chartData.datasets[0].data.shift(); } } function startSimulation() { if (!running) { running = true; simInterval = setInterval(stepSimulation, 100); } } function pauseSimulation() { running = false; clearInterval(simInterval); } function resetSimulation() { pauseSimulation(); time = 0; chartData.labels = []; chartData.datasets[0].data = []; myChart.update(); } document.getElementById('startBtn').onclick = startSimulation; document.getElementById('pauseBtn').onclick = pauseSimulation; document.getElementById('resetBtn').onclick = resetSimulation; // Optional: update simulation immediately when sliders change paramA.oninput = () => { paramAValue.textContent = paramA.value; }; paramB.oninput = () => { paramBValue.textContent = paramB.value; }; </script> </body> </html>
How it works:
- Boxes and arrows: Two boxes are positioned with an SVG arrow between them.
- Sliders: Two sliders control parameters A and B.
- Graph: Chart.js displays the simulation output.
- Simulation loop: Start, pause, and reset buttons control the simulation. The simulation uses the slider values to compute a value and plot it.
You can add more boxes, arrows, sliders, or change the simulation logic as needed!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.