gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Сделай чтобы этот код обрабатывал не только курсор мыши но и тап на экране телефона:…
- User
Сделай чтобы этот код обрабатывал не только курсор мыши но и тап на экране телефона:
code<script> const ant = document.getElementById('ant'); const stepSize = 2; const escapeDistance = 50; let directionX = (Math.random() < 0.5 ? -1 : 1) * stepSize; let directionY = (Math.random() < 0.5 ? -1 : 1) * stepSize; const moveAnt = () => { const antRect = ant.getBoundingClientRect(); let newAntX = antRect.left + directionX; let newAntY = antRect.top + directionY; // Уход от курсора document.onmousemove = (e) => { const dx = antRect.left - e.clientX; const dy = antRect.top - e.clientY; if ((dx * dx + dy * dy) < (escapeDistance * escapeDistance)) { directionX = dx > 0 ? stepSize : -stepSize; directionY = dy > 0 ? stepSize : -stepSize; } }; // Изменение направления при столкновении с границей if (newAntX <= 0 || newAntX >= window.innerWidth - antRect.width) { directionX = -directionX; directionX += (Math.random() - 0.5) * 2; // Некоторый случайный элемент } if (newAntY <= 0 || newAntY >= window.innerHeight - antRect.height) { directionY = -directionY; directionY += (Math.random() - 0.5) * 2; // Некоторый случайный элемент } ant.style.left = `${newAntX}px`; ant.style.top = `${newAntY}px`; } setInterval(moveAnt, 10); </script> - Assistant