-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphing.html
More file actions
284 lines (239 loc) · 9.1 KB
/
graphing.html
File metadata and controls
284 lines (239 loc) · 9.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>نقطة بنقطة</title>
<link rel="manifest" href="/manifest.json" />
<script src="https://www.desmos.com/api/v1.10/calculator.js?apiKey=dcb31709b452b1cf9dc26972add0fda6"></script>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"/>
<style>
body {
font-family: 'Cairo', sans-serif;
transition: background-color 0.3s ease, color 0.3s ease;
}
#calculator {
height: 500px;
}
#error-toast {
transition: all 0.3s ease-in-out;
}
.dark-mode {
background-color: #1f2937;
color: #f9fafb;
}
.dark-mode .bg-white {
background-color: #374151 !important;
}
.dark-mode .text-blue-700 {
color: #60a5fa !important;
}
.dark-mode textarea,
.dark-mode .border {
background-color: #4b5563;
color: white;
}
.dark-mode footer {
color: #9ca3af;
}
</style>
</head>
<body class="text-right p-6 bg-gray-50" id="body">
<div class="max-w-3xl mx-auto bg-white rounded-2xl shadow-lg p-6 space-y-6">
<div class="flex justify-between items-center">
<h1 class="text-3xl font-bold text-blue-700">نقطة بنقطة</h1>
<button onclick="toggleDarkMode()" class="text-sm text-gray-600 bg-gray-200 px-3 py-1 rounded-full hover:bg-gray-300">
🌓 وضع الليل
</button>
</div>
<div class="mt-6 bg-blue-50 p-4 rounded-lg text-base leading-relaxed text-gray-800">
<h3 class="text-xl font-semibold text-blue-700 mb-2">حول الموقع</h3>
<p>
موقع <span class="font-bold">نقطة بنقطة</span> أداة رسومية تعليمية من إعداد الطالب عمر أبو بكر، تسهّل فهم المعادلات بالعربية وبأسلوب بسيط، مصممة خصيصاً لطلاب مدرسة الإسراء النموذجية.
</p>
</div>
<div>
<label for="equations" class="block text-lg font-semibold mb-2">أدخل المعادلات (واحدة في كل سطر):</label>
<textarea id="equations" rows="4" placeholder="مثال:\nص = س^2 - 3\nص > 2س + 1"
class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
<p id="equation-count" class="text-sm text-gray-500 mt-2">عدد المعادلات: 0</p>
<div class="flex items-center space-x-2 text-sm text-gray-600 mt-2">
<input type="checkbox" id="auto-plot" class="form-checkbox text-blue-600">
<label for="auto-plot">رسم تلقائي أثناء الكتابة</label>
</div>
</div>
<div class="flex justify-center gap-4">
<button onclick="plotEquations()"
class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-full shadow">
رسم المعادلات
</button>
<button onclick="clearEquations()"
class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-6 rounded-full shadow">
مسح الرسومات
</button>
</div>
<div class="flex justify-center gap-4">
<button onclick="redrawEquations()"
class="bg-yellow-500 hover:bg-yellow-600 text-white font-bold py-2 px-6 rounded-full shadow">
إعادة الرسم
</button>
<button onclick="downloadImage()"
class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-6 rounded-full shadow">
حفظ كصورة
</button>
<button onclick="exportEquations()"
class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-6 rounded-full shadow">
تصدير المعادلات
</button>
</div>
<div class="mt-4 text-sm text-gray-600 text-center">
<p>إصدار 2.2: تحسين أداء الموقع وحل المشكلات </p>
</div>
<div id="calculator" class="rounded-lg border shadow-inner bg-white"></div>
</div>
<div id="error-toast" class="hidden fixed bottom-4 right-4 bg-red-500 text-white py-2 px-4 rounded shadow-lg text-sm z-50">
⚠️ يوجد خطأ في إحدى المعادلات. يرجى التحقق منها.
</div>
<footer class="mt-10 text-center text-xs text-gray-400">
موقع <span class="font-semibold">نقطة بنقطة</span> تم تطويره من الطالب عمر أبو بكر ✨
</footer>
<script>
let calculator;
function initializeCalculator() {
const elt = document.getElementById('calculator');
calculator = Desmos.GraphingCalculator(elt, {
expressions: true,
settingsMenu: false,
keypad: true,
language: 'ar'
});
}
function convertArabicToLatex(arabicInput) {
let converted = arabicInput
.replace(/[\u200E\u200F]/g, '')
.replace(/س/g, 'x')
.replace(/ص/g, 'y')
.replace(/\^/g, '^');
converted = converted
.replace(/([xy])\s*>=\s*([^\n]+)/g, '$1 \\ge $2')
.replace(/([xy])\s*<=\s*([^\n]+)/g, '$1 \\le $2')
.replace(/([xy])\s*>\s*([^\n]+)/g, '$1 > $2')
.replace(/([xy])\s*<\s*([^\n]+)/g, '$1 < $2')
.replace(/=/g, '=');
return converted.trim();
}
function plotEquations() {
calculator.setExpressions([]);
const input = document.getElementById('equations').value.trim();
const lines = input.split('\n');
let hasError = false;
lines.forEach((line, index) => {
const converted = convertArabicToLatex(line);
if (converted) {
try {
calculator.setExpression({
id: 'eq' + index,
latex: converted
});
} catch (e) {
hasError = true;
}
}
});
if (hasError) showErrorToast();
}
function clearEquations() {
document.getElementById('equations').value = '';
document.getElementById('equation-count').innerText = "عدد المعادلات: 0";
const all = calculator.getExpressions();
all.forEach(expr => calculator.removeExpression(expr));
}
function updateEquationCount() {
const lines = document.getElementById('equations').value.trim().split('\n').filter(line => line.trim() !== '');
document.getElementById('equation-count').innerText = `عدد المعادلات: ${lines.length}`;
}
function showErrorToast() {
const toast = document.getElementById('error-toast');
toast.classList.remove('hidden');
setTimeout(() => toast.classList.add('hidden'), 3000);
}
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
}
window.onload = () => {
initializeCalculator();
updateEquationCount();
};
document.getElementById('equations').addEventListener('input', () => {
updateEquationCount();
if (document.getElementById('auto-plot').checked) {
plotEquations();
}
});
function redrawEquations() {
plotEquations();
}
function redrawEquations() {
if (calculator) plotEquations();
}
function downloadImage() {
if (!calculator) return;
setTimeout(() => {
try {
const img = calculator.screenshot({ width: 600, height: 400 });
const a = document.createElement('a');
a.href = img;
a.download = 'nqtah-graph.png';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} catch (e) {
alert('حدث خطأ أثناء حفظ الصورة');
}
}, 100);
}
function exportEquations() {
const input = document.getElementById('equations').value.trim();
const blob = new Blob([input], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'معادلات.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
function getRandomColor() {
const colors = [
'#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
'#17becf', '#bcbd22', '#f39c12', '#e74c3c'
];
return colors[Math.floor(Math.random() * colors.length)];
}
function redrawEquations() {
const input = document.getElementById('equations').value.trim();
if (!input) return;
calculator.setExpressions([]);
const lines = input.split('\n');
let hasError = false;
lines.forEach((line, index) => {
const converted = convertArabicToLatex(line);
if (converted) {
try {
calculator.setExpression({
id: 'eq' + index,
latex: converted,
color: getRandomColor()
});
} catch (e) {
hasError = true;
}
}
});
if (hasError) showErrorToast();
}
</script>
</body>
</html>