ffonavia commited on
Commit
a06186a
·
verified ·
1 Parent(s): a605933

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +396 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Sub1
3
- emoji: 💻
4
- colorFrom: purple
5
- colorTo: purple
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: sub1
3
+ emoji: 🐳
4
+ colorFrom: gray
5
+ colorTo: gray
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,396 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="ru">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Визуализация сложения и вычитания чисел</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
9
+ <style>
10
+ .number-line {
11
+ position: relative;
12
+ height: 60px;
13
+ margin: 40px 0;
14
+ border-top: 2px solid #4b5563;
15
+ }
16
+ .number-tick {
17
+ position: absolute;
18
+ top: 0;
19
+ width: 1px;
20
+ height: 10px;
21
+ background-color: #4b5563;
22
+ transform: translateX(-50%);
23
+ }
24
+ .number-label {
25
+ position: absolute;
26
+ top: 15px;
27
+ transform: translateX(-50%);
28
+ font-size: 12px;
29
+ color: #4b5563;
30
+ }
31
+ .operation-arrow {
32
+ position: absolute;
33
+ height: 2px;
34
+ background-color: #3b82f6;
35
+ top: 30px;
36
+ }
37
+ .operation-arrow::after {
38
+ content: '';
39
+ position: absolute;
40
+ right: -6px;
41
+ top: -4px;
42
+ width: 0;
43
+ height: 0;
44
+ border-left: 6px solid #3b82f6;
45
+ border-top: 6px solid transparent;
46
+ border-bottom: 6px solid transparent;
47
+ }
48
+ .negative-arrow {
49
+ background-color: #ef4444;
50
+ }
51
+ .negative-arrow::after {
52
+ border-left-color: #ef4444;
53
+ }
54
+ .start-point {
55
+ position: absolute;
56
+ width: 10px;
57
+ height: 10px;
58
+ border-radius: 50%;
59
+ background-color: #10b981;
60
+ top: 26px;
61
+ transform: translateX(-50%);
62
+ }
63
+ .result-point {
64
+ position: absolute;
65
+ width: 10px;
66
+ height: 10px;
67
+ border-radius: 50%;
68
+ background-color: #8b5cf6;
69
+ top: 26px;
70
+ transform: translateX(-50%);
71
+ }
72
+ </style>
73
+ </head>
74
+ <body class="bg-gray-50 min-h-screen">
75
+ <div class="container mx-auto px-4 py-8">
76
+ <h1 class="text-3xl font-bold text-center text-gray-800 mb-6">Визуализация сложения и вычитания чисел</h1>
77
+
78
+ <div class="bg-white rounded-lg shadow-md p-6 mb-8">
79
+ <div class="flex flex-col md:flex-row gap-6 mb-6">
80
+ <div class="flex-1">
81
+ <label class="block text-sm font-medium text-gray-700 mb-1">Первое число</label>
82
+ <div class="flex">
83
+ <select id="firstSign" class="bg-gray-100 border border-gray-300 text-gray-700 py-2 px-3 rounded-l-md focus:outline-none focus:ring-2 focus:ring-blue-500">
84
+ <option value="+">+</option>
85
+ <option value="-">-</option>
86
+ </select>
87
+ <input type="number" id="firstNumber" value="5" class="flex-1 min-w-0 block w-full px-3 py-2 rounded-r-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500">
88
+ </div>
89
+ </div>
90
+
91
+ <div class="flex-1">
92
+ <label class="block text-sm font-medium text-gray-700 mb-1">Операция</label>
93
+ <select id="operation" class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
94
+ <option value="+">Сложение (+)</option>
95
+ <option value="-">Вычитание (-)</option>
96
+ </select>
97
+ </div>
98
+
99
+ <div class="flex-1">
100
+ <label class="block text-sm font-medium text-gray-700 mb-1">Второе число</label>
101
+ <div class="flex">
102
+ <select id="secondSign" class="bg-gray-100 border border-gray-300 text-gray-700 py-2 px-3 rounded-l-md focus:outline-none focus:ring-2 focus:ring-blue-500">
103
+ <option value="+">+</option>
104
+ <option value="-">-</option>
105
+ </select>
106
+ <input type="number" id="secondNumber" value="3" class="flex-1 min-w-0 block w-full px-3 py-2 rounded-r-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500">
107
+ </div>
108
+ </div>
109
+ </div>
110
+
111
+ <button id="calculateBtn" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md transition duration-150 ease-in-out transform hover:scale-105">
112
+ Показать на числовой оси
113
+ </button>
114
+ </div>
115
+
116
+ <div id="resultSection" class="bg-white rounded-lg shadow-md p-6 mb-8 hidden">
117
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">Результат:</h2>
118
+ <div class="mb-4">
119
+ <span id="calculationText" class="text-lg font-medium"></span>
120
+ <span id="resultText" class="text-2xl font-bold text-purple-600 ml-2"></span>
121
+ </div>
122
+
123
+ <div class="number-line-container overflow-x-auto py-4">
124
+ <div id="numberLine" class="number-line" style="width: 100%; min-width: 600px;"></div>
125
+ </div>
126
+
127
+ <div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-6">
128
+ <div>
129
+ <h3 class="text-lg font-medium text-gray-800 mb-2">Пошаговое объяснение:</h3>
130
+ <div id="explanation" class="prose prose-sm max-w-none text-gray-700"></div>
131
+ </div>
132
+
133
+ <div>
134
+ <h3 class="text-lg font-medium text-gray-800 mb-2">Графическое представление:</h3>
135
+ <canvas id="numberChart" height="200"></canvas>
136
+ </div>
137
+ </div>
138
+ </div>
139
+
140
+ <div class="bg-white rounded-lg shadow-md p-6">
141
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">Практические примеры</h2>
142
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
143
+ <button class="example-btn bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded-md transition" data-first="5" data-op="+" data-second="3">
144
+ 5 + 3
145
+ </button>
146
+ <button class="example-btn bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded-md transition" data-first="5" data-op="+" data-second="-3">
147
+ 5 + (-3)
148
+ </button>
149
+ <button class="example-btn bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded-md transition" data-first="-5" data-op="+" data-second="3">
150
+ -5 + 3
151
+ </button>
152
+ <button class="example-btn bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded-md transition" data-first="-5" data-op="+" data-second="-3">
153
+ -5 + (-3)
154
+ </button>
155
+ <button class="example-btn bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded-md transition" data-first="5" data-op="-" data-second="3">
156
+ 5 - 3
157
+ </button>
158
+ <button class="example-btn bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded-md transition" data-first="5" data-op="-" data-second="-3">
159
+ 5 - (-3)
160
+ </button>
161
+ <button class="example-btn bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded-md transition" data-first="-5" data-op="-" data-second="3">
162
+ -5 - 3
163
+ </button>
164
+ <button class="example-btn bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded-md transition" data-first="-5" data-op="-" data-second="-3">
165
+ -5 - (-3)
166
+ </button>
167
+ </div>
168
+ </div>
169
+ </div>
170
+
171
+ <script>
172
+ document.addEventListener('DOMContentLoaded', function() {
173
+ const calculateBtn = document.getElementById('calculateBtn');
174
+ const firstSign = document.getElementById('firstSign');
175
+ const firstNumber = document.getElementById('firstNumber');
176
+ const operation = document.getElementById('operation');
177
+ const secondSign = document.getElementById('secondSign');
178
+ const secondNumber = document.getElementById('secondNumber');
179
+ const resultSection = document.getElementById('resultSection');
180
+ const calculationText = document.getElementById('calculationText');
181
+ const resultText = document.getElementById('resultText');
182
+ const numberLine = document.getElementById('numberLine');
183
+ const explanation = document.getElementById('explanation');
184
+ const exampleBtns = document.querySelectorAll('.example-btn');
185
+ let numberChart = null;
186
+
187
+ // Обработчик для кнопки расчета
188
+ calculateBtn.addEventListener('click', visualizeCalculation);
189
+
190
+ // Обработчики для примеров
191
+ exampleBtns.forEach(btn => {
192
+ btn.addEventListener('click', function() {
193
+ const first = this.getAttribute('data-first');
194
+ const op = this.getAttribute('data-op');
195
+ const second = this.getAttribute('data-second');
196
+
197
+ // Устанавливаем значения в поля ввода
198
+ firstNumber.value = Math.abs(first);
199
+ firstSign.value = first.startsWith('-') ? '-' : '+';
200
+ operation.value = op;
201
+ secondNumber.value = Math.abs(second);
202
+ secondSign.value = second.startsWith('-') ? '-' : '+';
203
+
204
+ // Запускаем визуализацию
205
+ visualizeCalculation();
206
+ });
207
+ });
208
+
209
+ function visualizeCalculation() {
210
+ // Получаем значения из полей ввода
211
+ const firstNum = parseInt(firstNumber.value) * (firstSign.value === '-' ? -1 : 1);
212
+ const op = operation.value;
213
+ const secondNum = parseInt(secondNumber.value) * (secondSign.value === '-' ? -1 : 1);
214
+
215
+ // Вычисляем результат
216
+ let result;
217
+ if (op === '+') {
218
+ result = firstNum + secondNum;
219
+ } else {
220
+ result = firstNum - secondNum;
221
+ }
222
+
223
+ // Отображаем результат
224
+ calculationText.textContent = `${firstNum} ${op} ${secondNum} =`;
225
+ resultText.textContent = result;
226
+
227
+ // Показываем секцию с результатом
228
+ resultSection.classList.remove('hidden');
229
+
230
+ // Строим числовую ось
231
+ buildNumberLine(firstNum, op, secondNum, result);
232
+
233
+ // Генерируем объяснение
234
+ generateExplanation(firstNum, op, secondNum, result);
235
+
236
+ // Строим график
237
+ buildChart(firstNum, op, secondNum, result);
238
+ }
239
+
240
+ function buildNumberLine(firstNum, op, secondNum, result) {
241
+ // Очищаем числовую ось
242
+ numberLine.innerHTML = '';
243
+
244
+ // Определяем диапазон для отображения
245
+ const min = Math.min(firstNum, result, 0) - 2;
246
+ const max = Math.max(firstNum, result, 0) + 2;
247
+ const range = max - min;
248
+ const widthPerUnit = 600 / range;
249
+
250
+ // Устанавливаем ширину числовой оси
251
+ numberLine.style.width = `${range * widthPerUnit}px`;
252
+
253
+ // Добавляем деления и метки
254
+ for (let i = min; i <= max; i++) {
255
+ const tick = document.createElement('div');
256
+ tick.className = 'number-tick';
257
+ tick.style.left = `${((i - min) * widthPerUnit)}px`;
258
+ numberLine.appendChild(tick);
259
+
260
+ const label = document.createElement('div');
261
+ label.className = 'number-label';
262
+ label.textContent = i;
263
+ label.style.left = `${((i - min) * widthPerUnit)}px`;
264
+ numberLine.appendChild(label);
265
+ }
266
+
267
+ // Добавляем начальную точку
268
+ const startPoint = document.createElement('div');
269
+ startPoint.className = 'start-point';
270
+ startPoint.style.left = `${((firstNum - min) * widthPerUnit)}px`;
271
+ numberLine.appendChild(startPoint);
272
+
273
+ // Добавляем стрелку операции
274
+ const arrow = document.createElement('div');
275
+ arrow.className = 'operation-arrow';
276
+
277
+ let arrowLength, arrowLeft;
278
+ if (op === '+') {
279
+ // Для сложения
280
+ arrowLength = secondNum * widthPerUnit;
281
+ arrowLeft = (firstNum - min) * widthPerUnit;
282
+
283
+ if (secondNum < 0) {
284
+ arrow.classList.add('negative-arrow');
285
+ arrowLeft += arrowLength; // Для отрицательных чисел стрелка идет влево
286
+ }
287
+ } else {
288
+ // Для вычитания (это то же самое, что прибавить отрицательное)
289
+ arrowLength = -secondNum * widthPerUnit;
290
+ arrowLeft = (firstNum - min) * widthPerUnit;
291
+
292
+ if (secondNum > 0) {
293
+ arrow.classList.add('negative-arrow');
294
+ arrowLeft += arrowLength; // Для вычитания положительного числа стрелка идет влево
295
+ }
296
+ }
297
+
298
+ arrow.style.width = `${Math.abs(arrowLength)}px`;
299
+ arrow.style.left = `${arrowLeft}px`;
300
+ numberLine.appendChild(arrow);
301
+
302
+ // Добавляем результирующую точку
303
+ const resultPoint = document.createElement('div');
304
+ resultPoint.className = 'result-point';
305
+ resultPoint.style.left = `${((result - min) * widthPerUnit)}px`;
306
+ numberLine.appendChild(resultPoint);
307
+ }
308
+
309
+ function generateExplanation(firstNum, op, secondNum, result) {
310
+ let explanationText = '';
311
+
312
+ if (op === '+') {
313
+ explanationText = `
314
+ <p><strong>Шаг 1:</strong> Начинаем с числа ${firstNum} на числовой оси.</p>
315
+ <p><strong>Шаг 2:</strong> Выполняем сложение с числом ${secondNum}.</p>
316
+ ${secondNum >= 0 ?
317
+ `<p>Так как второе число положительное, двигаемся вправо на ${secondNum} единиц.</p>` :
318
+ `<p>Так как второе число отрицательное, двигаемся влево на ${Math.abs(secondNum)} единиц.</p>`
319
+ }
320
+ <p><strong>Шаг 3:</strong> Получаем результат: ${firstNum} ${op} ${secondNum} = ${result}.</p>
321
+ `;
322
+ } else {
323
+ explanationText = `
324
+ <p><strong>Шаг 1:</strong> Начинаем с числа ${firstNum} на числовой оси.</p>
325
+ <p><strong>Шаг 2:</strong> Выполняем вычитание числа ${secondNum}.</p>
326
+ <p><strong>Шаг 2.1:</strong> Вычитание числа ${secondNum} эквивалентно сложению с числом ${-secondNum}.</p>
327
+ ${-secondNum >= 0 ?
328
+ `<p>Так как ${-secondNum} положительное, двигаемся вправо на ${-secondNum} единиц.</p>` :
329
+ `<p>Так как ${-secondNum} отрицательное, двигаемся влево на ${Math.abs(secondNum)} единиц.</p>`
330
+ }
331
+ <p><strong>Шаг 3:</strong> Получаем результат: ${firstNum} ${op} ${secondNum} = ${result}.</p>
332
+ `;
333
+ }
334
+
335
+ explanation.innerHTML = explanationText;
336
+ }
337
+
338
+ function buildChart(firstNum, op, secondNum, result) {
339
+ const ctx = document.getElementById('numberChart').getContext('2d');
340
+
341
+ // Уничтожаем предыдущий график, если он существует
342
+ if (numberChart) {
343
+ numberChart.destroy();
344
+ }
345
+
346
+ // Создаем новый график
347
+ numberChart = new Chart(ctx, {
348
+ type: 'bar',
349
+ data: {
350
+ labels: ['Первое число', 'Второе число', 'Результат'],
351
+ datasets: [{
352
+ label: 'Значения',
353
+ data: [firstNum, op === '+' ? secondNum : -secondNum, result],
354
+ backgroundColor: [
355
+ 'rgba(16, 185, 129, 0.7)',
356
+ 'rgba(59, 130, 246, 0.7)',
357
+ 'rgba(139, 92, 246, 0.7)'
358
+ ],
359
+ borderColor: [
360
+ 'rgba(16, 185, 129, 1)',
361
+ 'rgba(59, 130, 246, 1)',
362
+ 'rgba(139, 92, 246, 1)'
363
+ ],
364
+ borderWidth: 1
365
+ }]
366
+ },
367
+ options: {
368
+ responsive: true,
369
+ scales: {
370
+ y: {
371
+ beginAtZero: false,
372
+ title: {
373
+ display: true,
374
+ text: 'Значение'
375
+ }
376
+ }
377
+ },
378
+ plugins: {
379
+ tooltip: {
380
+ callbacks: {
381
+ label: function(context) {
382
+ return `${context.dataset.label}: ${context.raw}`;
383
+ }
384
+ }
385
+ },
386
+ legend: {
387
+ display: false
388
+ }
389
+ }
390
+ }
391
+ });
392
+ }
393
+ });
394
+ </script>
395
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=ffonavia/sub1" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
396
+ </html>