-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchem.html
More file actions
1224 lines (1071 loc) · 47.6 KB
/
chem.html
File metadata and controls
1224 lines (1071 loc) · 47.6 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
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>化学实验模拟器 - By DS</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.header {
background: linear-gradient(120deg, #3498db, #2c3e50);
color: white;
padding: 25px 30px;
text-align: center;
border-bottom: 1px solid #eee;
}
.header h1 {
font-size: 2.4rem;
margin-bottom: 10px;
font-weight: 700;
}
.header p {
font-size: 1.1rem;
opacity: 0.9;
max-width: 800px;
margin: 0 auto;
}
.content {
display: flex;
min-height: 600px;
}
.control-panel {
width: 320px;
background: #f8f9fa;
border-right: 1px solid #e9ecef;
display: flex;
flex-direction: column;
padding: 20px;
overflow-y: auto;
}
.simulation-area {
flex: 1;
display: flex;
flex-direction: column;
background: #fff;
position: relative;
}
.canvas-container {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
background: #f0f2f5;
border-bottom: 1px solid #e9ecef;
}
#simulationCanvas {
background: white;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.panel-section {
margin-bottom: 25px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
overflow: hidden;
}
.panel-section h2 {
background: #2c3e50;
color: white;
padding: 12px 15px;
font-size: 1.1rem;
margin: 0;
}
.panel-content {
padding: 15px;
}
.chemical-list {
max-height: 200px;
overflow-y: auto;
border: 1px solid #e9ecef;
border-radius: 6px;
}
.chemical-item {
padding: 10px 12px;
cursor: pointer;
border-bottom: 1px solid #f1f3f4;
transition: all 0.2s;
display: flex;
justify-content: space-between;
}
.chemical-item:hover {
background-color: #e3f2fd;
}
.chemical-item.selected {
background-color: #2196f3;
color: white;
}
.chemical-name {
font-weight: 500;
}
.chemical-formula {
font-style: italic;
color: #666;
}
.chemical-item.selected .chemical-formula {
color: rgba(255, 255, 255, 0.8);
}
.info-display {
min-height: 120px;
max-height: 200px;
border: 1px solid #e9ecef;
border-radius: 6px;
padding: 12px;
background: white;
overflow-y: auto;
font-size: 0.9rem;
}
.info-item {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
padding-bottom: 8px;
border-bottom: 1px dashed #eee;
}
.info-name {
font-weight: 500;
}
.info-value {
color: #666;
}
button {
padding: 10px 15px;
background: #3498db;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: all 0.3s;
width: 100%;
margin-top: 10px;
}
button:hover {
background: #2980b9;
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
button.clear {
background: #e74c3c;
}
button.clear:hover {
background: #c0392b;
}
.status-bar {
display: flex;
justify-content: space-between;
padding: 15px 20px;
background: #f8f9fa;
border-top: 1px solid #e9ecef;
font-size: 0.9rem;
color: #666;
}
.instructions {
background: #e8f4fd;
border-left: 4px solid #3498db;
padding: 15px;
border-radius: 4px;
margin-top: 20px;
}
.instructions h3 {
margin-bottom: 10px;
color: #2c3e50;
}
.instructions ul {
padding-left: 20px;
}
.instructions li {
margin-bottom: 8px;
}
.empty-state {
text-align: center;
padding: 20px;
color: #7f8c8d;
font-style: italic;
}
.reaction-log {
max-height: 150px;
overflow-y: auto;
border: 1px solid #e9ecef;
border-radius: 6px;
padding: 10px;
background: #f8f9fa;
margin-top: 10px;
font-size: 0.85rem;
}
.log-entry {
padding: 5px 0;
border-bottom: 1px dotted #ddd;
}
@media (max-width: 1100px) {
.content {
flex-direction: column;
}
.control-panel {
width: 100%;
border-right: none;
border-bottom: 1px solid #e9ecef;
}
.panel-sections {
display: flex;
flex-wrap: wrap;
gap: 15px;
}
.panel-section {
flex: 1;
min-width: 250px;
}
}
.reaction-type {
display: inline-block;
padding: 2px 6px;
border-radius: 3px;
font-size: 0.75rem;
margin-left: 5px;
}
.redox {
background: #ffebee;
color: #c62828;
}
.precipitation {
background: #e8eaf6;
color: #303f9f;
}
.gas {
background: #e0f2f1;
color: #00695c;
}
.complex {
background: #f3e5f5;
color: #7b1fa2;
}
.amphoteric {
background: #fff8e1;
color: #ff8f00;
}
.decomposition {
background: #e0f7fa;
color: #00838f;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>化学实验模拟器 - 完整反应模拟</h1>
<p>选择药品添加到烧杯中,观察完整的化学反应过程</p>
</div>
<div class="content">
<div class="control-panel">
<div class="panel-sections">
<div class="panel-section">
<h2>选择药品</h2>
<div class="panel-content">
<div class="chemical-list" id="chemicalList">
<!-- 药品列表将通过JavaScript动态生成 -->
</div>
</div>
</div>
<div class="panel-section">
<h2>溶液状态</h2>
<div class="panel-content">
<div class="info-display" id="solutionInfo">
<div class="empty-state">当前溶液为空</div>
</div>
<button id="clearSolutionBtn">清除溶液</button>
</div>
</div>
<div class="panel-section">
<h2>沉淀状态</h2>
<div class="panel-content">
<div class="info-display" id="precipitateInfo">
<div class="empty-state">无沉淀</div>
</div>
<button id="clearPrecipitateBtn" class="clear">清除沉淀</button>
</div>
</div>
</div>
<div class="instructions">
<h3>操作说明</h3>
<ul>
<li>从左侧选择药品</li>
<li>点击烧杯区域添加药品</li>
<li>观察所有可能的化学反应</li>
<li>沉淀会自然沉降到底部</li>
<li>气泡表示气体生成反应</li>
<li>使用按钮清除溶液或沉淀</li>
</ul>
</div>
<div class="reaction-log" id="reactionLog">
<div class="log-entry">系统就绪,请开始实验...</div>
</div>
</div>
<div class="simulation-area">
<div class="canvas-container">
<canvas id="simulationCanvas" width="800" height="500"></canvas>
</div>
<div class="status-bar">
<div id="selectedChemical">当前选择: 无</div>
<div id="particleCount">粒子数: 0</div>
<div id="reactionCount">反应次数: 0</div>
</div>
</div>
</div>
</div>
<script>
// 化学药品数据
const chemicals = [
{name: "硝酸", formula: "HNO₃", ions: ["H⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "盐酸", formula: "HCl", ions: ["H⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "硫酸", formula: "H₂SO₄", ions: ["H⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [2, 1], color: null},
{name: "碳酸", formula: "H₂CO₃", ions: ["H⁺", "CO₃²⁻"], solubility: "溶", strength: "弱", ratio: [2, 1], color: null},
{name: "一水合氨", formula: "NH₃·H₂O", ions: ["NH₄⁺", "OH⁻"], solubility: "溶", strength: "弱", ratio: [1, 1], color: null},
{name: "硝酸铵", formula: "NH₄NO₃", ions: ["NH₄⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "氯化铵", formula: "NH₄Cl", ions: ["NH₄⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "硫酸铵", formula: "(NH₄)₂SO₄", ions: ["NH₄⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [2, 1], color: null},
{name: "碳酸铵", formula: "(NH₄)₂CO₃", ions: ["NH₄⁺", "CO₃²⁻"], solubility: "溶", strength: "强", ratio: [2, 1], color: null},
{name: "氢氧化钾", formula: "KOH", ions: ["K⁺", "OH⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "硝酸钾", formula: "KNO₃", ions: ["K⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "氯化钾", formula: "KCl", ions: ["K⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "硫酸钾", formula: "K₂SO₄", ions: ["K⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [2, 1], color: null},
{name: "碳酸钾", formula: "K₂CO₃", ions: ["K⁺", "CO₃²⁻"], solubility: "溶", strength: "强", ratio: [2, 1], color: null},
{name: "氢氧化钠", formula: "NaOH", ions: ["Na⁺", "OH⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "硝酸钠", formula: "NaNO₃", ions: ["Na⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "氯化钠", formula: "NaCl", ions: ["Na⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "硫酸钠", formula: "Na₂SO₄", ions: ["Na⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [2, 1], color: null},
{name: "碳酸钠", formula: "Na₂CO₃", ions: ["Na⁺", "CO₃²⁻"], solubility: "溶", strength: "强", ratio: [2, 1], color: null},
{name: "氢氧化钡", formula: "Ba(OH)₂", ions: ["Ba²⁺", "OH⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "硝酸钡", formula: "Ba(NO₃)₂", ions: ["Ba²⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "氯化钡", formula: "BaCl₂", ions: ["Ba²⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "硫酸钡", formula: "BaSO₄", ions: ["Ba²⁺", "SO₄²⁻"], solubility: "不", strength: "强", ratio: [1, 1], color: [240, 240, 240]},
{name: "碳酸钡", formula: "BaCO₃", ions: ["Ba²⁺", "CO₃²⁻"], solubility: "不", strength: "强", ratio: [1, 1], color: [240, 240, 240]},
{name: "氢氧化钙", formula: "Ca(OH)₂", ions: ["Ca²⁺", "OH⁻"], solubility: "微", strength: "强", ratio: [1, 2], color: [240, 240, 240]},
{name: "硝酸钙", formula: "Ca(NO₃)₂", ions: ["Ca²⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "氯化钙", formula: "CaCl₂", ions: ["Ca²⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "硫酸钙", formula: "CaSO₄", ions: ["Ca²⁺", "SO₄²⁻"], solubility: "微", strength: "强", ratio: [1, 1], color: [240, 240, 240]},
{name: "碳酸钙", formula: "CaCO₃", ions: ["Ca²⁺", "CO₃²⁻"], solubility: "不", strength: "强", ratio: [1, 1], color: [240, 240, 240]},
{name: "氢氧化镁", formula: "Mg(OH)₂", ions: ["Mg²⁺", "OH⁻"], solubility: "不", strength: "弱", ratio: [1, 2], color: [240, 240, 240]},
{name: "硝酸镁", formula: "Mg(NO₃)₂", ions: ["Mg²⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "氯化镁", formula: "MgCl₂", ions: ["Mg²⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "硫酸镁", formula: "MgSO₄", ions: ["Mg²⁺", "SO₄²⁻"], solubility: "不", strength: "强", ratio: [1, 1], color: [240, 240, 240]},
{name: "碳酸镁", formula: "MgCO₃", ions: ["Mg²⁺", "CO₃²⁻"], solubility: "微", strength: "强", ratio: [1, 1], color: [240, 240, 240]},
{name: "氢氧化铝", formula: "Al(OH)₃", ions: ["Al³⁺", "OH⁻"], solubility: "不", strength: "弱", ratio: [1, 3], color: [240, 240, 240]},
{name: "硝酸铝", formula: "Al(NO₃)₃", ions: ["Al³⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 3], color: null},
{name: "氯化铝", formula: "AlCl₃", ions: ["Al³⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 3], color: null},
{name: "硫酸铝", formula: "Al₂(SO₄)₃", ions: ["Al³⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [2, 3], color: null},
{name: "氢氧化锰", formula: "Mn(OH)₂", ions: ["Mn²⁺", "OH⁻"], solubility: "不", strength: "弱", ratio: [1, 2], color: [255, 200, 200]},
{name: "硝酸锰", formula: "Mn(NO₃)₂", ions: ["Mn²⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "氯化锰", formula: "MnCl₂", ions: ["Mn²⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "硫酸锰", formula: "MnSO₄", ions: ["Mn²⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "碳酸锰", formula: "MnCO₃", ions: ["Mn²⁺", "CO₃²⁻"], solubility: "不", strength: "强", ratio: [1, 1], color: [255, 200, 200]},
{name: "氢氧化锌", formula: "Zn(OH)₂", ions: ["Zn²⁺", "OH⁻"], solubility: "不", strength: "弱", ratio: [1, 2], color: [240, 240, 240]},
{name: "硝酸锌", formula: "Zn(NO₃)₂", ions: ["Zn²⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "氯化锌", formula: "ZnCl₂", ions: ["Zn²⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "硫酸锌", formula: "ZnSO₄", ions: ["Zn²⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "碳酸锌", formula: "ZnCO₃", ions: ["Zn²⁺", "CO₃²⁻"], solubility: "不", strength: "强", ratio: [1, 1], color: [240, 240, 240]},
{name: "氢氧化亚铁", formula: "Fe(OH)₂", ions: ["Fe²⁺", "OH⁻"], solubility: "不", strength: "弱", ratio: [1, 2], color: [100, 200, 100]},
{name: "硝酸亚铁", formula: "Fe(NO₃)₂", ions: ["Fe²⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "氯化亚铁", formula: "FeCl₂", ions: ["Fe²⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "硫酸亚铁", formula: "FeSO₄", ions: ["Fe²⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "碳酸亚铁", formula: "FeCO₃", ions: ["Fe²⁺", "CO₃²⁻"], solubility: "不", strength: "强", ratio: [1, 1], color: [100, 200, 100]},
{name: "氢氧化铁", formula: "Fe(OH)₃", ions: ["Fe³⁺", "OH⁻"], solubility: "不", strength: "弱", ratio: [1, 3], color: [210, 180, 60]},
{name: "硝酸铁", formula: "Fe(NO₃)₃", ions: ["Fe³⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 3], color: null},
{name: "氯化铁", formula: "FeCl₃", ions: ["Fe³⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 3], color: null},
{name: "硫酸铁", formula: "Fe₂(SO₄)₃", ions: ["Fe³⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [2, 3], color: null},
{name: "氢氧化铜", formula: "Cu(OH)₂", ions: ["Cu²⁺", "OH⁻"], solubility: "不", strength: "弱", ratio: [1, 2], color: [64, 128, 255]},
{name: "硝酸铜", formula: "Cu(NO₃)₂", ions: ["Cu²⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "氯化铜", formula: "CuCl₂", ions: ["Cu²⁺", "Cl⁻"], solubility: "溶", strength: "强", ratio: [1, 2], color: null},
{name: "硫酸铜", formula: "CuSO₄", ions: ["Cu²⁺", "SO₄²⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "硝酸银", formula: "AgNO₃", ions: ["Ag⁺", "NO₃⁻"], solubility: "溶", strength: "强", ratio: [1, 1], color: null},
{name: "氯化银", formula: "AgCl", ions: ["Ag⁺", "Cl⁻"], solubility: "不", strength: "强", ratio: [1, 1], color: [240, 240, 240]},
{name: "硫酸银", formula: "Ag₂SO₄", ions: ["Ag⁺", "SO₄²⁻"], solubility: "不", strength: "强", ratio: [2, 1], color: [240, 240, 240]},
{name: "碳酸银", formula: "Ag₂CO₃", ions: ["Ag⁺", "CO₃²⁻"], solubility: "微", strength: "强", ratio: [2, 1], color: [240, 240, 240]}
];
// 离子颜色映射
const ionColors = {
"Cu²⁺": [64, 128, 255],
"Fe²⁺": [100, 200, 100],
"Fe³⁺": [210, 180, 60],
"Mn²⁺": [255, 200, 200],
"H⁺": [255, 200, 200],
"OH⁻": [255, 255, 200],
"CO₃²⁻": [200, 255, 200],
"SO₄²⁻": [200, 230, 255],
"Cl⁻": [230, 230, 230],
"NO₃⁻": [230, 240, 255],
"NH₄⁺": [220, 240, 255],
"K⁺": [255, 240, 200],
"Na⁺": [255, 230, 200],
"Ba²⁺": [200, 255, 230],
"Ca²⁺": [230, 255, 230],
"Mg²⁺": [230, 240, 255],
"Al³⁺": [200, 230, 255],
"Zn²⁺": [230, 255, 255],
"Ag⁺": [255, 255, 255]
};
// 全局变量
let solution = []; // 当前溶液中的离子/分子 {name: string, amount: number}
let selectedChemical = null; // 当前选择的药品
let particles = []; // 所有粒子
let precipitates = []; // 沉淀物
let bubbles = []; // 气泡
let mouseDown = false;
let canvas, ctx;
let reactionCount = 0;
// 反应规则定义
const reactionRules = {
// 氧化还原反应
redox: [
{
reactants: ["Fe²⁺", "NO₃⁻", "H⁺"],
products: ["Fe³⁺", "NO", "H₂O"],
stoichiometry: [3, 1, 4, 3, 1, 2],
type: "redox"
}
],
// 沉淀反应
precipitation: [
{
reactants: ["Ag⁺", "Cl⁻"],
products: ["AgCl"],
stoichiometry: [1, 1, 1],
type: "precipitation"
},
{
reactants: ["Ba²⁺", "SO₄²⁻"],
products: ["BaSO₄"],
stoichiometry: [1, 1, 1],
type: "precipitation"
},
{
reactants: ["Ba²⁺", "CO₃²⁻"],
products: ["BaCO₃"],
stoichiometry: [1, 1, 1],
type: "precipitation"
},
{
reactants: ["Ca²⁺", "CO₃²⁻"],
products: ["CaCO₃"],
stoichiometry: [1, 1, 1],
type: "precipitation"
},
{
reactants: ["Ag⁺", "CO₃²⁻"],
products: ["Ag₂CO₃"],
stoichiometry: [2, 1, 1],
type: "precipitation"
}
],
// 气体生成反应
gas: [
{
reactants: ["CO₃²⁻", "H⁺"],
products: ["CO₂", "H₂O"],
stoichiometry: [1, 2, 1, 1],
type: "gas"
},
{
reactants: ["H₂CO₃"],
products: ["CO₂", "H₂O"],
stoichiometry: [1, 1, 1],
type: "decomposition"
}
],
// 配位反应
complex: [
{
reactants: ["Ag⁺", "NH₃·H₂O"],
products: ["[Ag(NH₃)₂]⁺", "H₂O"],
stoichiometry: [1, 2, 1, 2],
type: "complex"
},
{
reactants: ["Cu²⁺", "NH₃·H₂O"],
products: ["[Cu(NH₃)₄]²⁺", "H₂O"],
stoichiometry: [1, 4, 1, 4],
type: "complex"
},
{
reactants: ["Zn²⁺", "NH₃·H₂O"],
products: ["[Zn(NH₃)₄]²⁺", "H₂O"],
stoichiometry: [1, 4, 1, 4],
type: "complex"
}
],
// 两性反应
amphoteric: [
{
reactants: ["Al(OH)₃", "OH⁻"],
products: ["[Al(OH)₄]⁻"],
stoichiometry: [1, 1, 1],
type: "amphoteric"
},
{
reactants: ["Zn(OH)₂", "OH⁻"],
products: ["[Zn(OH)₄]²⁻"],
stoichiometry: [1, 2, 1],
type: "amphoteric"
}
],
// 中和反应
neutralization: [
{
reactants: ["H⁺", "OH⁻"],
products: ["H₂O"],
stoichiometry: [1, 1, 1],
type: "neutralization"
}
]
};
// 初始化
function init() {
canvas = document.getElementById('simulationCanvas');
ctx = canvas.getContext('2d');
// 填充药品列表
populateChemicalList();
// 添加事件监听器
canvas.addEventListener('mousedown', handleMouseDown);
canvas.addEventListener('mouseup', handleMouseUp);
canvas.addEventListener('mousemove', handleMouseMove);
canvas.addEventListener('touchstart', handleTouchStart, {passive: false});
canvas.addEventListener('touchend', handleTouchEnd);
canvas.addEventListener('touchmove', handleTouchMove, {passive: false});
document.getElementById('clearSolutionBtn').addEventListener('click', clearSolution);
document.getElementById('clearPrecipitateBtn').addEventListener('click', clearPrecipitates);
// 开始动画循环
requestAnimationFrame(update);
}
// 填充药品列表
function populateChemicalList() {
const chemicalList = document.getElementById('chemicalList');
chemicalList.innerHTML = '';
chemicals.forEach(chemical => {
const item = document.createElement('div');
item.className = 'chemical-item';
item.innerHTML = `
<span class="chemical-name">${chemical.name}</span>
<span class="chemical-formula">${chemical.formula}</span>
`;
item.addEventListener('click', () => selectChemical(chemical, item));
chemicalList.appendChild(item);
});
}
// 选择药品
function selectChemical(chemical, element) {
selectedChemical = chemical;
// 更新UI显示
document.getElementById('selectedChemical').textContent = `当前选择: ${chemical.formula}`;
// 更新选中状态
document.querySelectorAll('.chemical-item').forEach(item => {
item.classList.remove('selected');
});
element.classList.add('selected');
}
// 鼠标事件处理
function handleMouseDown(e) {
e.preventDefault();
mouseDown = true;
addChemical(e.clientX, e.clientY);
}
function handleMouseUp() {
mouseDown = false;
}
function handleMouseMove(e) {
if (mouseDown) {
addChemical(e.clientX, e.clientY);
}
}
// 触摸事件处理
function handleTouchStart(e) {
e.preventDefault();
mouseDown = true;
const touch = e.touches[0];
addChemical(touch.clientX, touch.clientY);
}
function handleTouchEnd() {
mouseDown = false;
}
function handleTouchMove(e) {
if (mouseDown) {
e.preventDefault();
const touch = e.touches[0];
addChemical(touch.clientX, touch.clientY);
}
}
// 添加化学药品
function addChemical(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
const x = clientX - rect.left;
const y = clientY - rect.top;
// 检查是否在烧杯区域内
if (isInBeaker(x, y) && selectedChemical) {
// 添加离子/分子到溶液
if (selectedChemical.solubility === "溶") {
if (selectedChemical.strength === "强") {
selectedChemical.ions.forEach((ion, index) => {
addToSolution(ion, 0.1 * selectedChemical.ratio[index]);
});
} else {
selectedChemical.ions.forEach((ion, index) => {
addToSolution(ion, 0.02 * selectedChemical.ratio[index]);
});
addToSolution(selectedChemical.formula, 0.08);
}
} else {
// 不溶或微溶物质直接作为沉淀
createPrecipitate(selectedChemical.formula, x, y, 0.1);
}
// 创建视觉粒子
createParticle(x, y, selectedChemical);
// 检查并执行化学反应
checkAllReactions();
}
}
// 检查是否在烧杯内
function isInBeaker(x, y) {
// 烧杯区域 - 确保整个烧杯区域都可点击
const beakerCenterX = canvas.width / 2;
const beakerTop = 80;
const beakerBottom = 420;
const beakerWidth = 300;
// 检查是否在烧杯的矩形区域内
return x > beakerCenterX - beakerWidth/2 &&
x < beakerCenterX + beakerWidth/2 &&
y > beakerTop &&
y < beakerBottom;
}
// 添加到溶液
function addToSolution(component, amount) {
const existing = solution.find(item => item.name === component);
if (existing) {
existing.amount += amount;
} else {
solution.push({name: component, amount: amount});
}
updateSolutionInfo();
}
// 从溶液移除组分
function removeFromSolution(component, amount) {
const existing = solution.find(item => item.name === component);
if (existing) {
existing.amount -= amount;
if (existing.amount <= 0.001) {
solution = solution.filter(item => item.name !== component);
}
}
updateSolutionInfo();
}
// 创建视觉粒子
function createParticle(x, y, chemical) {
// 确定粒子颜色
let color = [240, 240, 240]; // 默认颜色
// 优先使用药品的特定颜色
if (chemical.color) {
color = chemical.color;
}
// 否则使用第一个离子的颜色
else {
const firstIon = chemical.ions[0];
if (ionColors[firstIon]) {
color = ionColors[firstIon];
}
}
// 创建粒子
particles.push({
x: x,
y: y,
vx: (Math.random() - 0.5) * 2,
vy: (Math.random() - 0.5) * 2,
radius: 3 + Math.random() * 2,
color: `rgb(${color[0]}, ${color[1]}, ${color[2]})`,
type: chemical.solubility === "溶" ? 'dissolved' : 'precipitate',
lifetime: 100,
chemical: chemical.formula
});
}
// 创建沉淀
function createPrecipitate(formula, x, y, amount) {
// 查找沉淀的颜色
let color = [200, 200, 200]; // 默认沉淀颜色
const chemical = chemicals.find(c => c.formula === formula);
if (chemical && chemical.color) {
color = chemical.color;
}
precipitates.push({
formula: formula,
x: x,
y: y,
amount: amount,
radius: 5 + Math.random() * 3,
color: `rgb(${color[0]}, ${color[1]}, ${color[2]})`,
vx: (Math.random() - 0.5) * 0.5,
vy: 0
});
updatePrecipitateInfo();
}
// 创建气泡
function createBubble(x, y, count = 5) {
for (let i = 0; i < count; i++) {
bubbles.push({
x: x + (Math.random() - 0.5) * 30,
y: y,
radius: 2 + Math.random() * 3,
vx: (Math.random() - 0.5) * 0.5,
vy: -1 - Math.random() * 2,
lifetime: 100
});
}
}
// 检查并执行所有可能的化学反应
function checkAllReactions() {
let reactionOccurred = false;
// 检查每种类型的反应
for (const reactionType in reactionRules) {
for (const reaction of reactionRules[reactionType]) {
if (checkAndExecuteReaction(reaction)) {
reactionOccurred = true;
}
}
}
// 移除量为0的组分
solution = solution.filter(item => item.amount > 0.001);
updateSolutionInfo();
return reactionOccurred;
}
// 检查并执行单个反应
function checkAndExecuteReaction(reaction) {
// 检查反应物是否存在
const reactantsPresent = reaction.reactants.every(reactant =>
solution.some(item => item.name === reactant && item.amount > 0.001)
);
if (!reactantsPresent) return false;
// 计算最大反应量
let maxReactionAmount = Infinity;
for (let i = 0; i < reaction.reactants.length; i++) {
const reactant = reaction.reactants[i];
const stoichiometry = reaction.stoichiometry[i];
const reactantAmount = solution.find(item => item.name === reactant).amount;
maxReactionAmount = Math.min(maxReactionAmount, reactantAmount / stoichiometry);
}
// 如果反应量太小,不执行反应
if (maxReactionAmount < 0.001) return false;
// 执行反应
for (let i = 0; i < reaction.reactants.length; i++) {
const reactant = reaction.reactants[i];
const stoichiometry = reaction.stoichiometry[i];
removeFromSolution(reactant, maxReactionAmount * stoichiometry);
}
for (let i = 0; i < reaction.products.length; i++) {
const product = reaction.products[i];
const stoichiometry = reaction.stoichiometry[reaction.reactants.length + i];
addToSolution(product, maxReactionAmount * stoichiometry);
// 特殊处理:沉淀和气体
if (reaction.type === "precipitation") {
createPrecipitate(
product,
canvas.width/2 + (Math.random() - 0.5) * 100,
300 + Math.random() * 50,
maxReactionAmount * stoichiometry
);
} else if (reaction.type === "gas" || reaction.type === "decomposition") {
createBubble(
canvas.width/2 + (Math.random() - 0.5) * 100,
350 + Math.random() * 50,
Math.ceil(maxReactionAmount * 10)
);
}
}
// 更新反应计数和日志
reactionCount++;
addToLog(
`${getReactionDescription(reaction)}`,
reaction.type
);
return true;
}
// 获取反应描述
function getReactionDescription(reaction) {
const reactants = reaction.reactants.join(" + ");
const products = reaction.products.join(" + ");
return `${reactants} → ${products}`;
}
// 获取反应类型标签
function getReactionTypeLabel(type) {
const labels = {
redox: "氧化还原",
precipitation: "沉淀",
gas: "气体生成",
complex: "配位",
amphoteric: "两性",
decomposition: "分解",
neutralization: "中和"
};
return labels[type] || type;
}
// 清除溶液
function clearSolution() {
solution = [];
particles = particles.filter(p => p.type !== 'dissolved');
updateSolutionInfo();
addToLog("溶液已清除", "neutralization");
}
// 清除沉淀
function clearPrecipitates() {
precipitates = [];
particles = particles.filter(p => p.type !== 'precipitate');
updatePrecipitateInfo();
addToLog("沉淀已清除", "precipitation");
}
// 更新溶液信息显示
function updateSolutionInfo() {
const solutionInfo = document.getElementById('solutionInfo');
if (solution.length === 0) {
solutionInfo.innerHTML = '<div class="empty-state">当前溶液为空</div>';
} else {
let html = '';
solution.forEach(item => {
html += `
<div class="info-item">
<span class="info-name">${item.name}</span>
<span class="info-value">${item.amount.toFixed(2)}</span>
</div>
`;
});
solutionInfo.innerHTML = html;
}
}
// 更新沉淀信息显示
function updatePrecipitateInfo() {
const precipitateInfo = document.getElementById('precipitateInfo');
if (precipitates.length === 0) {
precipitateInfo.innerHTML = '<div class="empty-state">无沉淀</div>';
} else {
let html = '';
precipitates.forEach(p => {
html += `
<div class="info-item">
<span class="info-name">${p.formula}</span>
<span class="info-value">${p.amount.toFixed(2)}</span>
</div>
`;
});
precipitateInfo.innerHTML = html;
}
}
// 添加到反应日志
function addToLog(message, type) {
const log = document.getElementById('reactionLog');
const entry = document.createElement('div');
entry.className = 'log-entry';
const typeLabel = getReactionTypeLabel(type);
const typeClass = type || 'neutralization';
entry.innerHTML = `
${message}