-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.html
More file actions
772 lines (712 loc) · 30.7 KB
/
Copy pathtrain.html
File metadata and controls
772 lines (712 loc) · 30.7 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Задача о поезде — Арифметическая прогрессия</title>
<style>
:root {
--bg: #0f172a;
--bg2: #1e293b;
--card: #1e293b;
--border: #334155;
--border2: #1e293b;
--text: #e2e8f0;
--muted: #94a3b8;
--subtle: #64748b;
--track: #334155;
--btn2: #334155;
--btn2-text: #94a3b8;
}
html.light {
--bg: #f8fafc;
--bg2: #f1f5f9;
--card: #ffffff;
--border: #94a3b8;
--border2: #cbd5e1;
--text: #0f172a;
--muted: #374151;
--subtle: #334155;
--track: #94a3b8;
--btn2: #e2e8f0;
--btn2-text: #1e293b;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
background: var(--bg);
color: var(--text);
height: 100vh;
overflow: hidden;
transition: background 0.2s, color 0.2s;
}
.app {
display: grid;
grid-template-rows: auto 1fr auto;
height: 100vh;
}
.top-bar {
display: flex;
align-items: center;
gap: 16px;
padding: 10px 20px;
background: linear-gradient(135deg, var(--bg2) 0%, var(--bg) 100%);
border-bottom: 1px solid var(--border2);
flex-wrap: wrap;
}
.top-bar h1 {
font-size: 1.2em;
font-weight: 700;
background: linear-gradient(135deg, #f97316, #ef4444);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
white-space: nowrap;
}
.back-link {
text-decoration: none;
color: var(--muted);
font-size: 0.85em;
padding: 4px 10px;
border-radius: 6px;
border: 1px solid var(--border);
transition: color 0.15s, border-color 0.15s;
white-space: nowrap;
}
.back-link:hover { color: var(--text); border-color: var(--muted); }
html.light .top-bar h1 {
background: linear-gradient(135deg, #c2410c, #b91c1c);
-webkit-background-clip: text;
background-clip: text;
}
.top-controls {
display: flex;
align-items: center;
gap: 14px;
flex: 1;
flex-wrap: wrap;
}
.slider-group {
display: flex;
align-items: center;
gap: 6px;
}
.slider-group label {
font-size: 0.8em;
color: var(--muted);
text-transform: uppercase;
letter-spacing: 0.4px;
font-weight: 600;
}
.slider-group .val {
font-size: 1.3em;
font-weight: 700;
color: #f97316;
min-width: 36px;
text-align: center;
}
html.light .slider-group .val { color: #c2410c; }
input[type="range"] {
-webkit-appearance: none;
width: 110px;
height: 6px;
border-radius: 3px;
background: var(--track);
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #f97316;
cursor: pointer;
box-shadow: 0 0 8px rgba(249,115,22,0.4);
}
html.light input[type="range"]::-webkit-slider-thumb { background: #c2410c; }
.btn {
padding: 8px 16px;
border: none;
border-radius: 8px;
font-size: 0.85em;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
}
.btn-play { background: linear-gradient(135deg, #f97316, #ea580c); color: white; }
html.light .btn-play { background: linear-gradient(135deg, #c2410c, #991b1b); }
.btn-reset { background: var(--btn2); color: var(--btn2-text); }
.btn-speed { background: var(--btn2); color: var(--btn2-text); padding: 8px 12px; font-size: 0.8em; }
.btn-speed.active { background: #f97316; color: white; }
html.light .btn-speed.active { background: #c2410c; }
.btn-theme {
background: var(--btn2);
color: var(--btn2-text);
padding: 8px 14px;
font-size: 0.85em;
margin-left: auto;
border: 1px solid var(--border);
}
.main-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0;
min-height: 0;
overflow: hidden;
}
.scene-cell {
display: flex;
flex-direction: column;
border-right: 1px solid var(--border2);
min-height: 0;
overflow: hidden;
}
.cell-title {
font-size: 0.8em;
color: var(--subtle);
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 600;
padding: 8px 14px 4px;
}
.scene-wrap {
flex: 1;
min-height: 0;
position: relative;
}
canvas#sceneCanvas {
display: block;
width: 100%;
height: 100%;
}
.formulas-cell {
display: flex;
flex-direction: column;
gap: 10px;
padding: 14px 20px;
overflow-y: auto;
min-height: 0;
justify-content: center;
}
.formulas-cell::-webkit-scrollbar { width: 4px; }
.formulas-cell::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.formula-card {
background: var(--card);
border-radius: 12px;
padding: 14px 20px;
border: 1px solid var(--border);
}
.formula-card .card-title {
font-size: 0.85em;
color: var(--subtle);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 6px;
font-weight: 600;
}
.formula-card .formula {
font-size: 1.3em;
color: #a78bfa;
font-family: 'Courier New', monospace;
margin-bottom: 4px;
}
html.light .formula-card .formula { color: #6d28d9; }
.formula-card .calculation {
font-size: 1.2em;
color: var(--text);
font-weight: 600;
}
.formula-card .result {
font-size: 1.4em;
color: #4ade80;
font-weight: 700;
}
html.light .formula-card .result { color: #15803d; }
.formula-card .hl-orange { color: #f97316; }
.formula-card .hl-blue { color: #60a5fa; }
html.light .formula-card .hl-orange { color: #c2410c; }
html.light .formula-card .hl-blue { color: #1d4ed8; }
.terms-section {
background: var(--card);
border-radius: 12px;
padding: 12px 18px;
border: 1px solid var(--border);
}
.terms-title {
font-size: 0.8em;
color: var(--subtle);
text-transform: uppercase;
letter-spacing: 0.4px;
font-weight: 600;
margin-bottom: 6px;
}
.terms-list { display: flex; gap: 5px; flex-wrap: wrap; }
.term-badge {
padding: 4px 10px;
border-radius: 6px;
font-size: 0.95em;
font-weight: 600;
font-family: 'Courier New', monospace;
}
.term-badge.done {
background: rgba(74, 222, 128, 0.15);
color: #4ade80;
border: 1px solid rgba(74, 222, 128, 0.3);
}
html.light .term-badge.done { background: rgba(22,163,74,0.12); color: #15803d; border-color: rgba(22,163,74,0.35); }
.term-badge.active {
background: rgba(249, 115, 22, 0.2);
color: #fb923c;
border: 1px solid rgba(249, 115, 22, 0.4);
box-shadow: 0 0 6px rgba(249,115,22,0.2);
}
html.light .term-badge.active { background: rgba(194,65,12,0.12); color: #c2410c; border-color: rgba(194,65,12,0.4); }
.term-badge.future {
background: rgba(100, 116, 139, 0.15);
color: var(--muted);
border: 1px solid rgba(100, 116, 139, 0.2);
}
.bottom-bar {
display: flex;
align-items: stretch;
border-top: 1px solid var(--border2);
background: var(--bg2);
}
.status-items {
display: flex;
gap: 18px;
padding: 8px 20px;
align-items: center;
}
.status-item { display: flex; flex-direction: column; align-items: center; }
.status-item .label {
font-size: 0.7em;
color: var(--subtle);
text-transform: uppercase;
letter-spacing: 0.3px;
}
.status-item .value { font-size: 1.3em; font-weight: 700; }
.status-item .value.orange { color: #f97316; }
.status-item .value.green { color: #4ade80; }
.status-item .value.blue { color: #60a5fa; }
.status-item .value.purple { color: #a78bfa; }
html.light .status-item .value.orange { color: #c2410c; }
html.light .status-item .value.green { color: #15803d; }
html.light .status-item .value.blue { color: #1d4ed8; }
html.light .status-item .value.purple { color: #6d28d9; }
.comparison-items {
display: flex;
gap: 12px;
padding: 8px 20px;
flex: 1;
justify-content: center;
align-items: center;
}
.comp-card {
padding: 6px 16px;
border-radius: 8px;
border: 1px solid;
display: flex;
align-items: center;
gap: 10px;
}
.comp-card.manual { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.2); }
.comp-card.formula-method { background: rgba(74,222,128,0.08); border-color: rgba(74,222,128,0.2); }
html.light .comp-card.formula-method { background: rgba(22,163,74,0.06); }
.comp-card .comp-title { font-size: 0.75em; font-weight: 600; text-transform: uppercase; }
.comp-card.manual .comp-title { color: #f87171; }
.comp-card.formula-method .comp-title { color: #4ade80; }
html.light .comp-card.formula-method .comp-title { color: #15803d; }
.comp-card .comp-value { font-size: 1.05em; font-weight: 700; }
.comp-card.manual .comp-value { color: #ef4444; }
.comp-card.formula-method .comp-value { color: #22c55e; }
html.light .comp-card.formula-method .comp-value { color: #15803d; }
.insight-item {
padding: 8px 20px;
font-size: 0.9em;
color: #fdba74;
display: none;
align-items: center;
border-left: 1px solid var(--border);
max-width: 380px;
}
html.light .insight-item { color: #c2410c; }
.insight-item.visible { display: flex; }
/* ═══ МОБИЛЬНАЯ ВЕРСИЯ ═══ */
@media (max-width: 700px) {
html, body { height: auto; overflow-y: auto; }
.app { height: auto; min-height: 100svh; grid-template-rows: auto auto auto; }
.top-bar { padding: 8px 12px; gap: 8px; }
.top-bar h1 { font-size: 1em; white-space: normal; }
.top-controls { gap: 5px; flex-basis: 100%; }
.slider-group { gap: 4px; }
.slider-group .val { font-size: 1em; min-width: 20px; }
input[type="range"] { width: 60px; }
.btn { padding: 6px 10px; }
.btn-speed { padding: 5px 7px; }
.btn-theme { margin-left: 0; padding: 5px 8px; font-size: .76em; }
.main-grid { grid-template-columns: 1fr; overflow: visible; }
.canyon-cell, .canvas-cell, .left-cell, .amphi-cell, .scene-cell {
height: 56vw;
min-height: 220px;
max-height: 340px;
border-right: none;
border-bottom: 1px solid var(--border2);
}
.right-cell, .solution-cell, .formulas-cell {
overflow: visible;
height: auto;
padding: 12px 14px;
gap: 8px;
}
.terms-section { max-height: 200px; }
.bottom-bar { flex-wrap: wrap; }
.status-items { flex-wrap: wrap; gap: 10px; padding: 8px 12px; }
.comparison-items { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
.comp-card { padding: 5px 12px; }
.comp-card .comp-value { font-size: 0.95em; }
}
</style>
</head>
<body>
<div class="app">
<div class="top-bar">
<a href="index.html" class="back-link">← К задачам</a>
<h1>Поезд от станции</h1>
<div class="top-controls">
<div class="slider-group">
<label>N =</label>
<span class="val" id="displayN">10</span>
<input type="range" id="sliderN" min="1" max="40" value="10" step="1">
</div>
<div class="slider-group">
<label>a₁ =</label>
<span class="val" id="displayA1">0.2</span>
<input type="range" id="sliderA1" min="1" max="50" value="2" step="1">
</div>
<div class="slider-group">
<label>d =</label>
<span class="val" id="displayD">0.4</span>
<input type="range" id="sliderD" min="1" max="50" value="4" step="1">
</div>
<button class="btn btn-play" id="btnPlay">▶ Пуск</button>
<button class="btn btn-reset" id="btnReset">↺ Сброс</button>
<button class="btn btn-speed" data-speed="0.5">0.5×</button>
<button class="btn btn-speed active" data-speed="1">1×</button>
<button class="btn btn-speed" data-speed="2">2×</button>
<button class="btn btn-theme" id="btnTheme">☀ Светлая</button>
</div>
</div>
<div class="main-grid">
<div class="scene-cell">
<div class="cell-title">Движение поезда</div>
<div class="scene-wrap">
<canvas id="sceneCanvas"></canvas>
</div>
</div>
<div class="formulas-cell">
<div class="formula-card" style="border-left:4px solid #f97316">
<div class="card-title">📝 Задача</div>
<p style="font-size:.88em;color:var(--muted);line-height:1.55;margin-top:4px">Поезд начал движение от станции. За первую секунду состав сдвинулся на 0,2 м, а за каждую следующую секунду он проходил на 0,4 м больше, чем за предыдущую. Сколько метров состав прошёл за первые 10 секунд движения?</p>
</div>
<div class="formula-card">
<div class="card-title">Закономерность</div>
<div class="formula">a₁ = <span class="hl-orange">0.2</span> м, d = <span class="hl-blue">0.4</span> м</div>
<div class="calculation" id="formulaPattern">Каждую секунду на 0.4 м больше</div>
</div>
<div class="formula-card">
<div class="card-title">n-й член прогрессии</div>
<div class="formula">aₙ = a₁ + (n−1)·d</div>
<div class="calculation" id="formulaAn"></div>
</div>
<div class="formula-card">
<div class="card-title">Сумма — общий путь за N секунд</div>
<div class="formula">Sₙ = n·(a₁ + aₙ) / 2</div>
<div class="calculation" id="formulaSn"></div>
</div>
<div class="terms-section">
<div class="terms-title">Путь за каждую секунду (м)</div>
<div class="terms-list" id="termsList"></div>
</div>
</div>
</div>
<div class="bottom-bar">
<div class="status-items">
<div class="status-item">
<span class="label">Секунда</span>
<span class="value orange" id="statSecond">0 / 10</span>
</div>
<div class="status-item">
<span class="label">Пройдено</span>
<span class="value green" id="statDist">0 м</span>
</div>
<div class="status-item">
<span class="label">Сейчас</span>
<span class="value blue" id="statSpeed">0 м/с</span>
</div>
<div class="status-item">
<span class="label">Итого</span>
<span class="value purple" id="statTotal">20 м</span>
</div>
</div>
<div class="comparison-items">
<div class="comp-card manual">
<div class="comp-title">Перебор</div>
<div class="comp-value" id="compManual">10 сложений</div>
</div>
<div class="comp-card formula-method">
<div class="comp-title">Формула</div>
<div class="comp-value" id="compFormula">S = 20 м</div>
</div>
</div>
<div class="insight-item" id="insightBanner">
<span id="insightText"></span>
</div>
</div>
</div>
<script>
let N = 10, a1raw = 2, draw = 4;
let isPlaying = false, speed = 1, lastFrame = 0, animTime = 0;
function a1() { return a1raw / 10; }
function dd() { return draw / 10; }
function term(k) { return a1() + (k - 1) * dd(); }
function sumN(n) { return n * (2 * a1() + (n - 1) * dd()) / 2; }
function fmt(v) { return (Math.round(v * 100) / 100).toString(); }
const sliderN = document.getElementById('sliderN');
const sliderA1 = document.getElementById('sliderA1');
const sliderD = document.getElementById('sliderD');
const btnPlay = document.getElementById('btnPlay');
const btnReset = document.getElementById('btnReset');
const btnTheme = document.getElementById('btnTheme');
const sceneCanvas = document.getElementById('sceneCanvas');
const ctx = sceneCanvas.getContext('2d');
// ─── Theme ───────────────────────────────────────────────
const savedTheme = localStorage.getItem('ap-theme') || 'dark';
if (savedTheme === 'light') { document.documentElement.classList.add('light'); btnTheme.textContent = '🌙 Тёмная'; }
btnTheme.addEventListener('click', () => {
const isL = document.documentElement.classList.toggle('light');
localStorage.setItem('ap-theme', isL ? 'light' : 'dark');
btnTheme.textContent = isL ? '🌙 Тёмная' : '☀ Светлая';
render();
});
function isLight() { return document.documentElement.classList.contains('light'); }
function resizeCanvas(canvas) {
const rect = canvas.parentElement.getBoundingClientRect();
const dpr = window.devicePixelRatio || 1;
canvas.width = rect.width * dpr; canvas.height = rect.height * dpr;
canvas.getContext('2d').scale(dpr, dpr);
canvas.style.width = rect.width + 'px'; canvas.style.height = rect.height + 'px';
}
function resizeAll() { resizeCanvas(sceneCanvas); render(); }
function drawScene() {
const dpr = window.devicePixelRatio || 1;
const w = sceneCanvas.width / dpr, h = sceneCanvas.height / dpr;
const light = isLight();
ctx.clearRect(0, 0, w, h);
const nDone = Math.min(Math.floor(animTime), N);
const frac = animTime - nDone;
const distDone = sumN(nDone);
const vCurr = nDone < N ? term(nDone + 1) : 0;
const currentDist = distDone + vCurr * frac;
const totalDist = sumN(N);
const trackY = h * 0.55;
const stationX = 50;
const trackEnd = w - 30;
const trackLen = trackEnd - stationX;
const progress = totalDist > 0 ? currentDist / totalDist : 0;
// Sky
const sky = ctx.createLinearGradient(0, 0, 0, trackY - 30);
if (light) {
sky.addColorStop(0, '#bfdbfe'); sky.addColorStop(1, '#e0f2fe');
} else {
sky.addColorStop(0, '#1e3a5f'); sky.addColorStop(1, '#0f172a');
}
ctx.fillStyle = sky; ctx.fillRect(0, 0, w, trackY - 30);
// Ground
ctx.fillStyle = light ? '#bbf7d0' : '#1a3320';
ctx.fillRect(0, trackY - 30, w, h - trackY + 30);
// Track bed
ctx.fillStyle = light ? '#d4a96a' : '#3d2b1a';
ctx.fillRect(stationX - 10, trackY - 4, trackLen + 40, 8);
// Rails
ctx.strokeStyle = light ? '#64748b' : '#94a3b8'; ctx.lineWidth = 2;
ctx.beginPath(); ctx.moveTo(stationX - 10, trackY - 3); ctx.lineTo(trackEnd + 30, trackY - 3); ctx.stroke();
ctx.beginPath(); ctx.moveTo(stationX - 10, trackY + 3); ctx.lineTo(trackEnd + 30, trackY + 3); ctx.stroke();
// Sleepers
ctx.fillStyle = light ? '#92400e' : '#5a4030';
for (let x = stationX; x < trackEnd + 20; x += 16) {
ctx.fillRect(x, trackY - 6, 4, 12);
}
// Station
ctx.fillStyle = light ? '#94a3b8' : '#334155';
ctx.fillRect(stationX - 20, trackY - 50, 40, 46);
ctx.fillStyle = light ? '#64748b' : '#475569';
ctx.beginPath();
ctx.moveTo(stationX - 25, trackY - 50);
ctx.lineTo(stationX, trackY - 64);
ctx.lineTo(stationX + 25, trackY - 50);
ctx.closePath(); ctx.fill();
ctx.fillStyle = '#fbbf24';
ctx.fillRect(stationX - 8, trackY - 36, 6, 8);
ctx.fillRect(stationX + 2, trackY - 36, 6, 8);
ctx.fillStyle = light ? '#1e293b' : '#94a3b8';
ctx.font = '9px system-ui';
ctx.textAlign = 'center'; ctx.fillText('СТАНЦИЯ', stationX, trackY - 54);
// Segment markers
for (let k = 1; k <= nDone; k++) {
const markDist = sumN(k);
const markX = stationX + (markDist / totalDist) * trackLen;
ctx.strokeStyle = light ? 'rgba(146,64,14,0.35)' : 'rgba(251,191,36,0.3)'; ctx.lineWidth = 1;
ctx.setLineDash([3, 3]);
ctx.beginPath(); ctx.moveTo(markX, trackY - 20); ctx.lineTo(markX, trackY + 20); ctx.stroke();
ctx.setLineDash([]);
const prevDist = sumN(k - 1);
const prevX = stationX + (prevDist / totalDist) * trackLen;
const midX = (prevX + markX) / 2;
const segW = markX - prevX;
const hue = 25 + k * 8;
ctx.fillStyle = `hsla(${hue}, 80%, ${light ? 35 : 55}%, 0.15)`;
ctx.fillRect(prevX, trackY + 14, segW, 16);
ctx.strokeStyle = `hsla(${hue}, 80%, ${light ? 35 : 55}%, 0.4)`;
ctx.lineWidth = 1;
ctx.strokeRect(prevX, trackY + 14, segW, 16);
if (segW > 20) {
ctx.fillStyle = light ? '#92400e' : '#fbbf24';
ctx.font = `bold ${Math.min(11, segW * 0.4)}px system-ui`;
ctx.textAlign = 'center';
ctx.fillText('+' + fmt(term(k)), midX, trackY + 26);
}
ctx.fillStyle = light ? 'rgba(51,65,85,0.65)' : 'rgba(148,163,184,0.6)';
ctx.font = '8px system-ui'; ctx.textAlign = 'center';
ctx.fillText(fmt(markDist), markX, trackY - 24);
}
// Train
const trainX = stationX + progress * trackLen;
const trainW = Math.min(120, h * 0.25);
const trainH = Math.min(46, h * 0.10);
const wheelR = Math.max(5, Math.round(trainH * 0.20));
const tx = trainX - trainW / 2;
const ty = trackY - trainH - wheelR * 0.4;
const trainGrad = ctx.createLinearGradient(tx, ty, tx, ty + trainH);
trainGrad.addColorStop(0, '#dc2626'); trainGrad.addColorStop(1, '#991b1b');
ctx.fillStyle = trainGrad;
roundRect(ctx, tx, ty, trainW, trainH, 4); ctx.fill();
ctx.strokeStyle = '#7f1d1d'; ctx.lineWidth = 1.5; ctx.stroke();
ctx.fillStyle = light ? '#bfdbfe' : '#1e3a5f';
ctx.fillRect(tx + trainW * 0.55, ty + 3, trainW * 0.35, trainH * 0.5);
ctx.strokeStyle = light ? '#1d4ed8' : '#60a5fa'; ctx.lineWidth = 0.5; ctx.stroke();
const lightR = Math.max(3, Math.round(trainH * 0.12));
ctx.fillStyle = '#fbbf24';
ctx.beginPath(); ctx.arc(tx + trainW - 2, ty + trainH * 0.5, lightR, 0, Math.PI * 2); ctx.fill();
if (isPlaying) {
const bSpread = trainH * 0.26;
const bLen = trainW * 0.38;
ctx.fillStyle = 'rgba(251,191,36,0.15)';
ctx.beginPath();
ctx.moveTo(tx + trainW, ty + trainH * 0.5 - bSpread * 0.5);
ctx.lineTo(tx + trainW + bLen, ty + trainH * 0.5 - bSpread);
ctx.lineTo(tx + trainW + bLen, ty + trainH * 0.5 + bSpread);
ctx.lineTo(tx + trainW, ty + trainH * 0.5 + bSpread * 0.5);
ctx.closePath(); ctx.fill();
}
ctx.fillStyle = light ? '#6b7280' : '#374151';
ctx.strokeStyle = light ? '#4b5563' : '#6b7280'; ctx.lineWidth = 1.5;
for (let wx of [tx + trainW * 0.2, tx + trainW * 0.5, tx + trainW * 0.8]) {
ctx.beginPath(); ctx.arc(wx, trackY - wheelR * 0.4, wheelR, 0, Math.PI * 2); ctx.fill(); ctx.stroke();
}
if (isPlaying || animTime > 0) {
ctx.globalAlpha = light ? 0.15 : 0.2;
ctx.fillStyle = light ? '#64748b' : '#94a3b8';
const t = Date.now() / 600;
for (let i = 0; i < 4; i++) {
const sx = tx + trainW * 0.08 - i * trainW * 0.1 + Math.sin(t + i) * 3;
const sy = ty - trainH * 0.2 - i * trainH * 0.28 + Math.cos(t + i * 0.7) * 2;
const sr = trainH * 0.14 + i * trainH * 0.09;
ctx.beginPath(); ctx.arc(sx, sy, sr, 0, Math.PI * 2); ctx.fill();
}
ctx.globalAlpha = 1;
}
ctx.fillStyle = light ? '#c2410c' : '#f97316';
ctx.font = 'bold 14px system-ui';
ctx.textAlign = 'center';
ctx.fillText(fmt(currentDist) + ' м', trainX, ty - 14);
if (nDone > 0 && nDone <= N) {
ctx.fillStyle = light ? '#1d4ed8' : '#60a5fa';
ctx.font = '12px system-ui';
ctx.textAlign = 'center';
ctx.fillText('t = ' + nDone + ' с', trainX, ty - 28);
}
}
function roundRect(ctx, x, y, w, h, r) {
ctx.beginPath(); ctx.moveTo(x + r, y); ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r); ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h); ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r); ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y); ctx.closePath();
}
function updateUI() {
const nDone = Math.min(Math.floor(animTime), N);
const frac = animTime - nDone;
const distDone = sumN(nDone);
const vCurr = nDone < N ? term(nDone + 1) : 0;
const currentDist = distDone + vCurr * frac;
const totalDist = sumN(N);
const lastTerm = term(N);
document.getElementById('displayN').textContent = N;
document.getElementById('displayA1').textContent = fmt(a1());
document.getElementById('displayD').textContent = fmt(dd());
document.getElementById('statSecond').textContent = nDone + ' / ' + N;
document.getElementById('statDist').textContent = fmt(Math.round(currentDist * 100) / 100) + ' м';
document.getElementById('statSpeed').textContent = fmt(vCurr) + ' м/с';
document.getElementById('statTotal').textContent = fmt(totalDist) + ' м';
document.getElementById('formulaPattern').innerHTML =
`Каждую секунду на <span class="hl-blue">${fmt(dd())}</span> м больше`;
const sub = n => String(n).split('').map(c => '₀₁₂₃₄₅₆₇₈₉'[c] || c).join('');
document.getElementById('formulaAn').innerHTML =
`a${sub(N)} = ${fmt(a1())} + (${N}−1)·${fmt(dd())} = <span class="result">${fmt(lastTerm)} м</span>`;
document.getElementById('formulaSn').innerHTML =
`S${sub(N)} = ${N}·(${fmt(a1())} + ${fmt(lastTerm)}) / 2 = <span class="result">${fmt(totalDist)} м</span>`;
const list = document.getElementById('termsList');
let html = '';
const maxShow = 25;
for (let k = 1; k <= Math.min(N, maxShow); k++) {
const cls = k <= nDone ? 'done' : (k === nDone + 1 ? 'active' : 'future');
html += `<span class="term-badge ${cls}">${fmt(term(k))}</span>`;
}
if (N > maxShow) html += `<span class="term-badge future" style="border:none;background:none">…ещё ${N - maxShow}</span>`;
list.innerHTML = html;
document.getElementById('compManual').textContent = N + ' сложений';
document.getElementById('compFormula').textContent = 'S = ' + fmt(totalDist) + ' м';
const banner = document.getElementById('insightBanner'), txt = document.getElementById('insightText');
if (N > 15) { banner.classList.add('visible'); txt.textContent = `${N} слагаемых? Формула Sₙ даёт ${fmt(totalDist)} м мгновенно!`; }
else if (N > 8) { banner.classList.add('visible'); txt.textContent = `${N} секунд — складывать долго. Формула проще!`; }
else { banner.classList.remove('visible'); }
}
function render() { drawScene(); updateUI(); }
function animate(ts) {
if (!isPlaying) return;
if (lastFrame === 0) lastFrame = ts;
animTime += ((ts - lastFrame) / 1000) * speed * 0.8;
lastFrame = ts;
if (animTime >= N) { animTime = N; isPlaying = false; btnPlay.textContent = '▶ Пуск'; }
render();
if (isPlaying) requestAnimationFrame(animate);
}
sliderN.addEventListener('input', () => { N = parseInt(sliderN.value); animTime = Math.min(animTime, N); render(); });
sliderA1.addEventListener('input', () => { a1raw = parseInt(sliderA1.value); render(); });
sliderD.addEventListener('input', () => { draw = parseInt(sliderD.value); render(); });
btnPlay.addEventListener('click', () => {
if (isPlaying) { isPlaying = false; btnPlay.textContent = '▶ Пуск'; }
else { if (animTime >= N) animTime = 0; isPlaying = true; lastFrame = 0; btnPlay.textContent = '⏸ Пауза'; requestAnimationFrame(animate); }
});
btnReset.addEventListener('click', () => { isPlaying = false; animTime = 0; lastFrame = 0; btnPlay.textContent = '▶ Пуск'; render(); });
document.querySelectorAll('.btn-speed').forEach(btn => {
btn.addEventListener('click', () => { document.querySelectorAll('.btn-speed').forEach(b => b.classList.remove('active')); btn.classList.add('active'); speed = parseFloat(btn.dataset.speed); });
});
window.addEventListener('resize', resizeAll);
setTimeout(resizeAll, 50);
animTime = 0;
render();
</script>
</body>
</html>