Gibberish
Gibberish
DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Variables for colors and theme */
:root {
--primary: #2196F3;
--background: #121212;
--surface: #1e1e1e;
--text: #ffffff;
--text-secondary: #aaaaaa;
--error: #cf6679;
--grid: #2c2c2c;
--axis: #404040;
--button: #2c2c2c;
--button-hover: #383838;
}
body {
font-family: system-ui, -apple-system, sans-serif;
background-color: var(--background);
color: var(--text);
min-height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
.container {
max-width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
}
.header {
text-align: center;
padding: 12px;
background-color: var(--surface);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 10;
}
.input-container {
background-color: var(--surface);
padding: 16px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 10;
position: relative;
}
.input-group {
display: flex;
gap: 8px;
margin-bottom: 12px;
}
input {
width: 100%;
padding: 12px;
font-size: 16px;
background-color: var(--button);
border: 1px solid var(--axis);
border-radius: 8px;
color: var(--text);
transition: all 0.3s ease;
}
.plot-button {
padding: 12px 24px;
font-size: 16px;
background-color: var(--primary);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
text-transform: uppercase;
font-weight: 500;
letter-spacing: 0.5px;
}
.canvas-container {
flex-grow: 1;
position: relative;
}
#graph3D {
width: 100%;
height: 100%;
}
.error {
color: var(--error);
margin-top: 8px;
font-size: 14px;
display: none;
animation: fadeIn 0.3s ease;
}
/* Keyboard styles */
.keyboard {
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
flex-wrap: wrap;
gap: 4px;
padding: 8px;
background-color: var(--surface);
box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.1);
z-index: 10;
overflow-y: auto;
max-height: 40vh;
}
.key {
padding: 8px;
font-size: 16px;
background-color: var(--button);
color: var(--text);
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
text-align: center;
user-select: none;
flex: 1 0 18%;
}
.key:hover {
background-color: var(--button-hover);
}
.key:active {
transform: scale(0.95);
}
.key.function {
background-color: #1e3a5f;
}
.key.operator {
background-color: #2c3a47;
}
.key.control {
background-color: #4a1e1e;
}
.key.erase {
background-color: #8b0000;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.key {
padding: 6px;
font-size: 14px;
flex: 1 0 18%;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>3D Graph Calculator</h2>
</div>
<div class="input-container">
<div class="input-group">
<input type="text" id="function" placeholder="Enter function" readonly />
<button class="plot-button" onclick="updateGraph()">Plot</button>
</div>
<div id="error" class="error"></div>
</div>
<div class="canvas-container">
<div id="graph3D"></div>
</div>
<script>
let scene, camera, renderer, graph, controls;
const functionInput = document.getElementById('function');
const errorDiv = document.getElementById('error');
function init() {
// Scene setup
scene = new THREE.Scene();
scene.background = new THREE.Color(0x121212);
// Camera setup
camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(5, 5, 5);
camera.lookAt(0, 0, 0);
// Renderer setup
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('graph3D').appendChild(renderer.domElement);
// Add grid
const gridHelper = new THREE.GridHelper(20, 20, 0x404040, 0x404040);
scene.add(gridHelper);
// Add axes
const axesHelper = new THREE.AxesHelper(10);
scene.add(axesHelper);
animate();
}
function createGraph(expression) {
try {
// Remove existing graph if any
if (graph) {
scene.remove(graph);
}
// Create geometry
const geometry = new THREE.BufferGeometry();
const vertices = [];
const resolution = 100;
const size = 10;
try {
const z = compiled.evaluate({ x: x, y: y });
if (isFinite(z)) {
// x, z, y swap for better 3D orientation
vertices.push(x, z, y);
}
} catch (error) {
continue;
}
}
}
geometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(vertices, 3)
);
// Create material
const material = new THREE.PointsMaterial({
size: 0.05,
color: 0x2196F3,
sizeAttenuation: true
});
errorDiv.style.display = 'none';
} catch (error) {
errorDiv.textContent = 'Invalid function expression. Please check your
syntax.';
errorDiv.style.display = 'block';
}
}
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
function updateGraph() {
const expression = functionInput.value;
if (expression) {
createGraph(expression);
}
}
function appendToInput(value) {
functionInput.value += value;
renderMath();
}
function eraseChar() {
functionInput.value = functionInput.value.slice(0, -1);
renderMath();
}
function renderMath() {
// Render the mathematical expression using MathJax
functionInput.innerHTML = functionInput.value;
MathJax.typesetPromise([functionInput]);
}
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});