deepseek-v3-0324· DeepSeek LMArena Human Preference 140K
code an html app with different shapes that i can pull out of a dropdown menu and into…
- User
code an html app with different shapes that i can pull out of a dropdown menu and into the main screen area. the shapes can be edited by right clicking, including changing size and color, also with a delete button. the main area has gravity physics applied, so shapes fall to rest at the bottom edge of the screen
- Assistant
HTML Shape Editor with Physics
Here's an interactive HTML app that allows you to:
- Select shapes from a dropdown menu
- Drag them into the main area
- Right-click to edit (size, color, delete)
- Has gravity physics where shapes fall to the bottom
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Shape Editor with Physics</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 20px; overflow: hidden; background-color: #f0f0f0; } #controls { margin-bottom: 20px; padding: 10px; background-color: #fff; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); } #shape-selector { padding: 8px; font-size: 16px; border-radius: 4px; border: 1px solid #ccc; } #canvas { width: 100%; height: calc(100vh - 150px); background-color: white; border: 1px solid #ccc; position: relative; overflow: hidden; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); } .shape { position: absolute; cursor: move; user-select: none; box-shadow: 0 2px 5px rgba(0,0,0,0.2); } .circle { border-radius: 50%; } .square { border-radius: 0; } .triangle { width: 0; height: 0; background-color: transparent !important; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid; } .context-menu { position: absolute; background-color: white; border: 1px solid #ccc; box-shadow: 0 2px 10px rgba(0,0,0,0.2); z-index: 1000; padding: 10px; border-radius: 5px; display: none; } .context-menu button { display: block; width: 100%; padding: 8px 12px; margin: 5px 0; text-align: left; background: none; border: none; cursor: pointer; } .context-menu button:hover { background-color: #f0f0f0; } .color-picker { width: 100%; margin: 5px 0; } .size-slider { width: 100%; margin: 5px 0; } </style> </head> <body> <div id="controls"> <h2>Shape Editor with Physics</h2> <select id="shape-selector"> <option value="circle">Circle</option> <option value="square">Square</option> <option value="triangle">Triangle</option> </select> <button id="add-shape">Add Shape</button> </div> <div id="canvas"></div> <div id="context-menu" class="context-menu"> <h3>Edit Shape</h3> <label>Color:</label> <input type="color" class="color-picker" value="#ff0000"> <label>Size:</label> <input type="range" class="size-slider" min="20" max="200" value="50"> <button id="delete-shape">Delete</button> </div> <script> document.addEventListener('DOMContentLoaded', function() { const canvas = document.getElementById('canvas'); const shapeSelector = document.getElementById('shape-selector'); const addShapeBtn = document.getElementById('add-shape'); const contextMenu = document.getElementById('context-menu'); const colorPicker = contextMenu.querySelector('.color-picker'); const sizeSlider = contextMenu.querySelector('.size-slider'); const deleteBtn = contextMenu.querySelector('#delete-shape'); let selectedShape = null; let shapes = []; let isDragging = false; let dragOffsetX = 0; let dragOffsetY = 0; // Physics variables const gravity = 0.2; const friction = 0.98; const bounce = 0.7; let animationId; // Add shape button click handler addShapeBtn.addEventListener('click', function() { const shapeType = shapeSelector.value; addShape(shapeType); }); // Add a new shape function addShape(shapeType) { const shape = document.createElement('div'); shape.className = `shape ${shapeType}`; // Random position near the top const x = Math.random() * (canvas.offsetWidth - 100) + 50; const y = 50; // Random color const color = `hsl(${Math.random() * 360}, 70%, 60%)`; // Set initial properties shape.style.left = `${x}px`; shape.style.top = `${y}px`; shape.style.backgroundColor = color; if (shapeType === 'circle' || shapeType === 'square') { shape.style.width = '50px'; shape.style.height = '50px'; } else if (shapeType === 'triangle') { shape.style.borderBottomColor = color; } // Add physics properties shape.physics = { x: x, y: y, vx: 0, vy: 0, width: 50, height: shapeType === 'triangle' ? 100 : 50, type: shapeType }; // Add event listeners shape.addEventListener('mousedown', startDrag); shape.addEventListener('contextmenu', showContextMenu); canvas.appendChild(shape); shapes.push(shape); // Start physics if not already running if (!animationId) { updatePhysics(); } } // Start dragging a shape function startDrag(e) { if (e.button !== 0) return; // Only left mouse button selectedShape = e.target; isDragging = true; // Calculate offset from mouse to shape corner const rect = selectedShape.getBoundingClientRect(); dragOffsetX = e.clientX - rect.left; dragOffsetY = e.clientY - rect.top; // Bring to front selectedShape.style.zIndex = '100'; e.preventDefault(); } // Show context menu for shape editing function showContextMenu(e) { e.preventDefault(); selectedShape = e.target; // Position the context menu contextMenu.style.left = `${e.clientX}px`; contextMenu.style.top = `${e.clientY}px`; contextMenu.style.display = 'block'; // Set current values if (selectedShape.physics.type === 'triangle') { colorPicker.value = rgbToHex(selectedShape.style.borderBottomColor); sizeSlider.value = parseInt(selectedShape.style.borderBottomWidth) * 2; } else { colorPicker.value = rgbToHex(selectedShape.style.backgroundColor); sizeSlider.value = parseInt(selectedShape.style.width); } } // Convert RGB color to hex function rgbToHex(rgb) { if (!rgb) return '#000000'; // Match rgb(r, g, b) format const match = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); if (!match) return rgb; // Return as-is if already hex function hex(x) { return ("0" + parseInt(x).toString(16)).slice(-2); } return "#" + hex(match[1]) + hex(match[2]) + hex(match[3]); } // Hide context menu when clicking elsewhere document.addEventListener('click', function(e) { if (e.target !== contextMenu && !contextMenu.contains(e.target)) { contextMenu.style.display = 'none'; } }); // Update shape color colorPicker.addEventListener('input', function() { if (!selectedShape) return; if (selectedShape.physics.type === 'triangle') { selectedShape.style.borderBottomColor = colorPicker.value; } else { selectedShape.style.backgroundColor = colorPicker.value; } }); // Update shape size sizeSlider.addEventListener('input', function() { if (!selectedShape) return; const size = parseInt(sizeSlider.value); if (selectedShape.physics.type === 'circle' || selectedShape.physics.type === 'square') { selectedShape.style.width = `${
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.