gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
"<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport"…
- User
"
code<h1>Draw Circles in a Rectangle</h1> <label for="width">Width of Rectangle:</label> <input type="number" id="width" value="300"> <label for="height">Height of Rectangle:</label> <input type="number" id="height" value="200"> <button onclick="draw()">Draw Circles</button> <canvas id="canvas" width="500" height="400"></canvas> <script> const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); const radius = 10; function draw() { const width = parseInt(document.getElementById('width').value, 10); const height = parseInt(document.getElementById('height').value, 10); canvas.width = width; // Adding buffer for better visualization canvas.height = height; ctx.clearRect(0, 0, canvas.width, canvas.height); // Draw uniform grid drawUniformGrid(width, height); // Draw shifted grid drawShiftedGrid(width, height); } function drawUniformGrid(width, height) { ctx.strokeStyle = 'blue'; ctx.lineWidth = 1; for (let y = radius; y <= height-1; y += 2 * radius) { for (let x = radius; x <= width-1; x += 2 * radius) { ctx.beginPath(); ctx.arc(x, y, radius, 0, Math.PI * 2); ctx.stroke(); } } } function drawShiftedGrid(width, height) { ctx.strokeStyle = 'red'; ctx.lineWidth = 1; const verticalSpacing = 2 * radius * Math.sin(Math.PI / 3); for (let y = radius; y <= height-2; y += verticalSpacing) { for (let x = radius; x <= width-2; x += 2 * radius) { const offset = (Math.floor(y / verticalSpacing) % 2) * radius; ctx.beginPath(); ctx.arc(x + offset, y, radius, 0, Math.PI * 2); ctx.stroke(); } } } </script> - Assistant
- User
make lines thicker
- Assistant