@jjlmoya/utils-science 1.21.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/category/index.ts +2 -1
- package/src/entries.ts +3 -1
- package/src/index.ts +1 -0
- package/src/tests/locale_completeness.test.ts +2 -2
- package/src/tests/tool_validation.test.ts +2 -2
- package/src/tool/lorenz-attractor/bibliography.astro +14 -0
- package/src/tool/lorenz-attractor/bibliography.ts +12 -0
- package/src/tool/lorenz-attractor/component.astro +146 -0
- package/src/tool/lorenz-attractor/entry.ts +27 -0
- package/src/tool/lorenz-attractor/i18n/de.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/en.ts +185 -0
- package/src/tool/lorenz-attractor/i18n/es.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/fr.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/id.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/it.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/ja.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/ko.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/nl.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/pl.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/pt.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/ru.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/sv.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/tr.ts +113 -0
- package/src/tool/lorenz-attractor/i18n/zh.ts +113 -0
- package/src/tool/lorenz-attractor/index.ts +9 -0
- package/src/tool/lorenz-attractor/logic/LorenzEngine.ts +32 -0
- package/src/tool/lorenz-attractor/lorenz-attractor.css +335 -0
- package/src/tool/lorenz-attractor/renderer.ts +136 -0
- package/src/tool/lorenz-attractor/script.ts +282 -0
- package/src/tool/lorenz-attractor/seo.astro +15 -0
- package/src/tools.ts +2 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const slug = 'lorenz-attractor';
|
|
2
|
+
const title = '洛伦兹吸引子混沌模拟器:3D蝴蝶效应';
|
|
3
|
+
const description = '通过这个交互式3D洛伦兹吸引子模拟探索混沌理论。可视化蝴蝶效应。';
|
|
4
|
+
|
|
5
|
+
const howTo = [
|
|
6
|
+
{
|
|
7
|
+
"name": "旋转画布",
|
|
8
|
+
"text": "在3D视口上点击并拖动以旋转吸引子。"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "调节滑块",
|
|
12
|
+
"text": "修改Sigma、Rho和Beta参数以观察混沌的产生。"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "观察发散",
|
|
16
|
+
"text": "观察两条轨迹之间的距离是如何呈指数级增长的。"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "暂停与重置",
|
|
20
|
+
"text": "使用控制按钮暂停模拟或重置参数。"
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const faq = [
|
|
25
|
+
{
|
|
26
|
+
"question": "什么是洛伦兹吸引子?",
|
|
27
|
+
"answer": "洛伦兹吸引子是洛伦兹方程组的一组混沌解。"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"question": "什么是蝴蝶效应?",
|
|
31
|
+
"answer": "非线性系统中对初始条件的敏感依赖性,微小的初始差异会导致巨大的长期差异。"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"question": "参数代表什么?",
|
|
35
|
+
"answer": "Sigma代表普朗特数,Rho代表瑞利数,Beta与物理尺寸几何比相关。"
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
import { bibliography } from '../bibliography';
|
|
40
|
+
import type { ToolLocaleContent } from '../../../types';
|
|
41
|
+
|
|
42
|
+
export const content: ToolLocaleContent = {
|
|
43
|
+
slug,
|
|
44
|
+
title,
|
|
45
|
+
description,
|
|
46
|
+
ui: {
|
|
47
|
+
"copied": "已复制",
|
|
48
|
+
"noHistory": "无历史记录",
|
|
49
|
+
"load": "加载",
|
|
50
|
+
"delete": "删除",
|
|
51
|
+
"title": "洛伦兹吸引子",
|
|
52
|
+
"subTitle": "决定论混沌",
|
|
53
|
+
"parameterControls": "系统参数",
|
|
54
|
+
"simulationSpeed": "速度 (dt)",
|
|
55
|
+
"initialPerturbation": "初始微扰 (dx)",
|
|
56
|
+
"trajectories": "轨迹",
|
|
57
|
+
"distance": "发散距离",
|
|
58
|
+
"exponentialGrowth": "指数发散",
|
|
59
|
+
"resetDefault": "Reset",
|
|
60
|
+
"clearPath": "Clear",
|
|
61
|
+
"play": "Resume",
|
|
62
|
+
"pause": "Pause",
|
|
63
|
+
"coords": "坐标",
|
|
64
|
+
"divergenceExplanation": "发散图显示了两条轨迹之间的欧几里得距离随时间的变化。"
|
|
65
|
+
},
|
|
66
|
+
seo: [
|
|
67
|
+
{
|
|
68
|
+
"type": "title",
|
|
69
|
+
"text": "决定论混沌:理解洛伦兹方程",
|
|
70
|
+
"level": 2
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"type": "paragraph",
|
|
74
|
+
"html": "洛伦兹方程组是非线性动力学和混沌理论研究中的里程碑。"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
faq,
|
|
78
|
+
bibliography,
|
|
79
|
+
howTo,
|
|
80
|
+
schemas: [
|
|
81
|
+
{
|
|
82
|
+
'@context': 'https://schema.org',
|
|
83
|
+
'@type': 'SoftwareApplication',
|
|
84
|
+
name: title,
|
|
85
|
+
description: description,
|
|
86
|
+
applicationCategory: 'ScientificApplication',
|
|
87
|
+
operatingSystem: 'Any',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
'@context': 'https://schema.org',
|
|
91
|
+
'@type': 'FAQPage',
|
|
92
|
+
mainEntity: faq.map((item) => ({
|
|
93
|
+
'@type': 'Question',
|
|
94
|
+
name: item.question,
|
|
95
|
+
acceptedAnswer: {
|
|
96
|
+
'@type': 'Answer',
|
|
97
|
+
text: item.answer,
|
|
98
|
+
},
|
|
99
|
+
})),
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
'@context': 'https://schema.org',
|
|
103
|
+
'@type': 'HowTo',
|
|
104
|
+
name: title,
|
|
105
|
+
step: howTo.map((step) => ({
|
|
106
|
+
'@type': 'HowToStep',
|
|
107
|
+
name: step.name,
|
|
108
|
+
stepValue: step.name,
|
|
109
|
+
text: step.text,
|
|
110
|
+
})),
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { lorenzAttractor } from './entry';
|
|
2
|
+
import type { ToolDefinition } from '../../types';
|
|
3
|
+
export * from './entry';
|
|
4
|
+
export const LORENZ_ATTRACTOR_TOOL: ToolDefinition = {
|
|
5
|
+
entry: lorenzAttractor,
|
|
6
|
+
Component: () => import('./component.astro'),
|
|
7
|
+
SEOComponent: () => import('./seo.astro'),
|
|
8
|
+
BibliographyComponent: () => import('./bibliography.astro'),
|
|
9
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface Point3D {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
z: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface LorenzParams {
|
|
8
|
+
sigma: number;
|
|
9
|
+
rho: number;
|
|
10
|
+
beta: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class LorenzEngine {
|
|
14
|
+
static nextPoint(point: Point3D, params: LorenzParams, dt: number): Point3D {
|
|
15
|
+
const dx = params.sigma * (point.y - point.x) * dt;
|
|
16
|
+
const dy = (point.x * (params.rho - point.z) - point.y) * dt;
|
|
17
|
+
const dz = (point.x * point.y - params.beta * point.z) * dt;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
x: point.x + dx,
|
|
21
|
+
y: point.y + dy,
|
|
22
|
+
z: point.z + dz,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static getDistance(p1: Point3D, p2: Point3D): number {
|
|
27
|
+
const dx = p1.x - p2.x;
|
|
28
|
+
const dy = p1.y - p2.y;
|
|
29
|
+
const dz = p1.z - p2.z;
|
|
30
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--lorenz-primary: #2563eb;
|
|
3
|
+
--lorenz-secondary: #7c3aed;
|
|
4
|
+
--lorenz-accent: #c084fc;
|
|
5
|
+
--lorenz-t1: #00f0ff;
|
|
6
|
+
--lorenz-t2: #ff007f;
|
|
7
|
+
--lorenz-bg-card: #fff;
|
|
8
|
+
--lorenz-bg-canvas: transparent;
|
|
9
|
+
--lorenz-border: #e2e8f0;
|
|
10
|
+
--lorenz-text: #0f172a;
|
|
11
|
+
--lorenz-text-muted: #64748b;
|
|
12
|
+
--lorenz-slider-track: #e2e8f0;
|
|
13
|
+
--lorenz-shadow-color: rgba(0, 0, 0, 0.04);
|
|
14
|
+
--lorenz-font-mono: consolas, monaco, 'Courier New', monospace;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.theme-dark {
|
|
18
|
+
--lorenz-primary: #3b82f6;
|
|
19
|
+
--lorenz-secondary: #8b5cf6;
|
|
20
|
+
--lorenz-accent: #a78bfa;
|
|
21
|
+
--lorenz-t1: #00f0ff;
|
|
22
|
+
--lorenz-t2: #ff007f;
|
|
23
|
+
--lorenz-bg-card: rgba(31, 41, 55, 0.45);
|
|
24
|
+
--lorenz-bg-canvas: transparent;
|
|
25
|
+
--lorenz-border: rgba(255, 255, 255, 0.06);
|
|
26
|
+
--lorenz-text: #f3f4f6;
|
|
27
|
+
--lorenz-text-muted: #9ca3af;
|
|
28
|
+
--lorenz-slider-track: #374151;
|
|
29
|
+
--lorenz-shadow-color: rgba(255, 255, 255, 0.03);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.lorenz-app {
|
|
33
|
+
width: 100%;
|
|
34
|
+
max-width: 1200px;
|
|
35
|
+
margin: 0 auto;
|
|
36
|
+
color: var(--lorenz-text);
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.lorenz-card {
|
|
41
|
+
background: var(--lorenz-bg-card);
|
|
42
|
+
backdrop-filter: blur(12px);
|
|
43
|
+
border: 1px solid var(--lorenz-border);
|
|
44
|
+
border-radius: 24px;
|
|
45
|
+
padding: 24px;
|
|
46
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.03);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.theme-dark .lorenz-card {
|
|
50
|
+
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.lorenz-grid {
|
|
54
|
+
display: grid;
|
|
55
|
+
grid-template-columns: 1fr;
|
|
56
|
+
gap: 24px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@media (min-width: 992px) {
|
|
60
|
+
.lorenz-grid {
|
|
61
|
+
grid-template-columns: 1.5fr 1fr;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.lorenz-canvas-container {
|
|
66
|
+
position: relative;
|
|
67
|
+
background: var(--lorenz-bg-canvas);
|
|
68
|
+
border-radius: 20px;
|
|
69
|
+
overflow: hidden;
|
|
70
|
+
aspect-ratio: 4 / 3;
|
|
71
|
+
display: flex;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
align-items: center;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.lorenz-canvas {
|
|
77
|
+
width: 100%;
|
|
78
|
+
height: 100%;
|
|
79
|
+
display: block;
|
|
80
|
+
cursor: grab;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.lorenz-canvas:active {
|
|
84
|
+
cursor: grabbing;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.lorenz-controls-section {
|
|
88
|
+
display: flex;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
gap: 24px;
|
|
91
|
+
justify-content: space-between;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.lorenz-sliders-block {
|
|
95
|
+
display: flex;
|
|
96
|
+
flex-direction: column;
|
|
97
|
+
gap: 16px;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.lorenz-slider-group {
|
|
101
|
+
display: flex;
|
|
102
|
+
flex-direction: column;
|
|
103
|
+
gap: 6px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.lorenz-slider-header {
|
|
107
|
+
display: flex;
|
|
108
|
+
justify-content: space-between;
|
|
109
|
+
font-size: 0.75rem;
|
|
110
|
+
font-weight: 700;
|
|
111
|
+
text-transform: uppercase;
|
|
112
|
+
letter-spacing: 0.05em;
|
|
113
|
+
color: var(--lorenz-text-muted);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.lorenz-slider-val {
|
|
117
|
+
color: var(--lorenz-primary);
|
|
118
|
+
font-variant-numeric: tabular-nums;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.lorenz-slider {
|
|
122
|
+
width: 100%;
|
|
123
|
+
height: 20px;
|
|
124
|
+
background: transparent;
|
|
125
|
+
outline: none;
|
|
126
|
+
-webkit-appearance: none;
|
|
127
|
+
margin: 0;
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.lorenz-slider::-webkit-slider-runnable-track {
|
|
132
|
+
width: 100%;
|
|
133
|
+
height: 2px;
|
|
134
|
+
background: var(--lorenz-slider-track);
|
|
135
|
+
border-radius: 1px;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.lorenz-slider::-webkit-slider-thumb {
|
|
139
|
+
-webkit-appearance: none;
|
|
140
|
+
width: 2px;
|
|
141
|
+
height: 12px;
|
|
142
|
+
background: var(--lorenz-primary);
|
|
143
|
+
margin-top: -5px;
|
|
144
|
+
border-radius: 0;
|
|
145
|
+
transition: transform 0.1s ease;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.lorenz-slider::-moz-range-track {
|
|
149
|
+
width: 100%;
|
|
150
|
+
height: 2px;
|
|
151
|
+
background: var(--lorenz-slider-track);
|
|
152
|
+
border-radius: 1px;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.lorenz-slider::-moz-range-thumb {
|
|
156
|
+
width: 2px;
|
|
157
|
+
height: 12px;
|
|
158
|
+
background: var(--lorenz-primary);
|
|
159
|
+
border-radius: 0;
|
|
160
|
+
border: none;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.lorenz-button-row {
|
|
164
|
+
display: grid;
|
|
165
|
+
grid-template-columns: 1fr 1fr 1fr;
|
|
166
|
+
gap: 8px;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.lorenz-btn {
|
|
170
|
+
padding: 10px 0;
|
|
171
|
+
border-radius: 8px;
|
|
172
|
+
font-size: 0.8rem;
|
|
173
|
+
font-weight: 700;
|
|
174
|
+
text-transform: uppercase;
|
|
175
|
+
letter-spacing: 0.05em;
|
|
176
|
+
cursor: pointer;
|
|
177
|
+
transition: all 0.2s ease;
|
|
178
|
+
text-align: center;
|
|
179
|
+
background: transparent;
|
|
180
|
+
color: var(--lorenz-text-muted);
|
|
181
|
+
border: 1px solid var(--lorenz-border);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.lorenz-btn:hover {
|
|
185
|
+
color: var(--lorenz-text);
|
|
186
|
+
background: rgba(120, 120, 120, 0.08);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.lorenz-btn-active-state {
|
|
190
|
+
border-color: var(--lorenz-primary);
|
|
191
|
+
color: var(--lorenz-primary);
|
|
192
|
+
box-shadow: 0 0 10px rgba(59, 130, 246, 0.15);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.lorenz-btn-active-state:hover {
|
|
196
|
+
background: rgba(59, 130, 246, 0.08);
|
|
197
|
+
color: var(--lorenz-primary);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.lorenz-stats-block {
|
|
201
|
+
border-top: 1px solid var(--lorenz-border);
|
|
202
|
+
padding-top: 16px;
|
|
203
|
+
display: flex;
|
|
204
|
+
flex-direction: column;
|
|
205
|
+
gap: 16px;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.lorenz-coords-row {
|
|
209
|
+
display: grid;
|
|
210
|
+
grid-template-columns: 1fr 1fr;
|
|
211
|
+
gap: 12px;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.lorenz-coord-item {
|
|
215
|
+
font-size: 0.72rem;
|
|
216
|
+
color: var(--lorenz-text-muted);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.lorenz-coord-val {
|
|
220
|
+
font-weight: 600;
|
|
221
|
+
font-variant-numeric: tabular-nums;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.lorenz-divergence-display {
|
|
225
|
+
display: flex;
|
|
226
|
+
flex-direction: column;
|
|
227
|
+
gap: 6px;
|
|
228
|
+
margin-top: 8px;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.lorenz-divergence-title {
|
|
232
|
+
font-size: 0.7rem;
|
|
233
|
+
font-weight: 700;
|
|
234
|
+
text-transform: uppercase;
|
|
235
|
+
letter-spacing: 0.05em;
|
|
236
|
+
color: var(--lorenz-text-muted);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.lorenz-divergence-main {
|
|
240
|
+
display: flex;
|
|
241
|
+
align-items: baseline;
|
|
242
|
+
gap: 12px;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.lorenz-divergence-num {
|
|
246
|
+
font-size: 2.8rem;
|
|
247
|
+
font-weight: 750;
|
|
248
|
+
line-height: 1;
|
|
249
|
+
color: var(--lorenz-accent);
|
|
250
|
+
font-variant-numeric: tabular-nums;
|
|
251
|
+
letter-spacing: -0.05em;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.lorenz-divergence-delta {
|
|
255
|
+
font-size: 0.85rem;
|
|
256
|
+
font-weight: 700;
|
|
257
|
+
color: var(--lorenz-text-muted);
|
|
258
|
+
font-variant-numeric: tabular-nums;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.lorenz-chart-block {
|
|
262
|
+
border-top: 1px solid var(--lorenz-border);
|
|
263
|
+
padding-top: 16px;
|
|
264
|
+
display: flex;
|
|
265
|
+
flex-direction: column;
|
|
266
|
+
gap: 8px;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.lorenz-chart-header {
|
|
270
|
+
display: flex;
|
|
271
|
+
align-items: center;
|
|
272
|
+
font-size: 0.7rem;
|
|
273
|
+
font-weight: 700;
|
|
274
|
+
text-transform: uppercase;
|
|
275
|
+
letter-spacing: 0.05em;
|
|
276
|
+
color: var(--lorenz-text-muted);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.lorenz-tooltip-container {
|
|
280
|
+
position: relative;
|
|
281
|
+
display: inline-flex;
|
|
282
|
+
margin-left: 6px;
|
|
283
|
+
cursor: help;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.lorenz-info-icon {
|
|
287
|
+
display: inline-flex;
|
|
288
|
+
align-items: center;
|
|
289
|
+
justify-content: center;
|
|
290
|
+
width: 14px;
|
|
291
|
+
height: 14px;
|
|
292
|
+
border-radius: 50%;
|
|
293
|
+
border: 1px solid var(--lorenz-text-muted);
|
|
294
|
+
font-size: 9px;
|
|
295
|
+
color: var(--lorenz-text-muted);
|
|
296
|
+
font-weight: bold;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.lorenz-tooltip-text {
|
|
300
|
+
visibility: hidden;
|
|
301
|
+
position: absolute;
|
|
302
|
+
bottom: 130%;
|
|
303
|
+
left: 50%;
|
|
304
|
+
transform: translateX(-50%);
|
|
305
|
+
background-color: var(--lorenz-text);
|
|
306
|
+
color: var(--lorenz-bg-card);
|
|
307
|
+
text-align: center;
|
|
308
|
+
padding: 8px 12px;
|
|
309
|
+
border-radius: 8px;
|
|
310
|
+
font-size: 0.7rem;
|
|
311
|
+
line-height: 1.3;
|
|
312
|
+
width: 200px;
|
|
313
|
+
z-index: 10;
|
|
314
|
+
opacity: 0;
|
|
315
|
+
transition: opacity 0.2s;
|
|
316
|
+
pointer-events: none;
|
|
317
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.lorenz-tooltip-container:hover .lorenz-tooltip-text {
|
|
321
|
+
visibility: visible;
|
|
322
|
+
opacity: 1;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.lorenz-chart-canvas-wrapper {
|
|
326
|
+
position: relative;
|
|
327
|
+
width: 100%;
|
|
328
|
+
height: 80px;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.lorenz-chart-canvas {
|
|
332
|
+
width: 100%;
|
|
333
|
+
height: 100%;
|
|
334
|
+
display: block;
|
|
335
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Point3D } from './logic/LorenzEngine';
|
|
2
|
+
|
|
3
|
+
export interface RenderContext {
|
|
4
|
+
ctx: CanvasRenderingContext2D;
|
|
5
|
+
w: number;
|
|
6
|
+
h: number;
|
|
7
|
+
rx: number;
|
|
8
|
+
ry: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getCssVariable(name: string, fallback: string): string {
|
|
12
|
+
return getComputedStyle(document.documentElement).getPropertyValue(name).trim() || fallback;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function project(p: Point3D, rx: number, ry: number, dims: { w: number; h: number }): { x: number; y: number } {
|
|
16
|
+
const scale = Math.min(dims.w, dims.h) * 0.0135;
|
|
17
|
+
const cx = dims.w / 2;
|
|
18
|
+
const cy = dims.h / 2;
|
|
19
|
+
const cosX = Math.cos(rx);
|
|
20
|
+
const sinX = Math.sin(rx);
|
|
21
|
+
const cosY = Math.cos(ry);
|
|
22
|
+
const sinY = Math.sin(ry);
|
|
23
|
+
const px = p.x;
|
|
24
|
+
const py = p.y;
|
|
25
|
+
const pz = p.z - 25;
|
|
26
|
+
const x1 = px * cosY - pz * sinY;
|
|
27
|
+
const z1 = px * sinY + pz * cosY;
|
|
28
|
+
const y2 = py * cosX - z1 * sinX;
|
|
29
|
+
return {
|
|
30
|
+
x: cx + x1 * scale,
|
|
31
|
+
y: cy - y2 * scale,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function drawGridLine(ctx: CanvasRenderingContext2D, p1: Point3D, p2: Point3D, opts: { rx: number; ry: number; w: number; h: number }) {
|
|
36
|
+
const dist1 = Math.sqrt(p1.x * p1.x + p1.y * p1.y);
|
|
37
|
+
const dist2 = Math.sqrt(p2.x * p2.x + p2.y * p2.y);
|
|
38
|
+
const avgDist = (dist1 + dist2) / 2;
|
|
39
|
+
const alpha = Math.max(0, 0.22 - avgDist / 120);
|
|
40
|
+
if (alpha <= 0) return;
|
|
41
|
+
ctx.strokeStyle = `rgba(100, 116, 139, ${alpha})`;
|
|
42
|
+
ctx.beginPath();
|
|
43
|
+
const pt1 = project(p1, opts.rx, opts.ry, opts);
|
|
44
|
+
const pt2 = project(p2, opts.rx, opts.ry, opts);
|
|
45
|
+
ctx.moveTo(pt1.x, pt1.y);
|
|
46
|
+
ctx.lineTo(pt2.x, pt2.y);
|
|
47
|
+
ctx.stroke();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function drawGrid(config: RenderContext) {
|
|
51
|
+
const step = 8;
|
|
52
|
+
const limit = 40;
|
|
53
|
+
const opts = { rx: config.rx, ry: config.ry, w: config.w, h: config.h };
|
|
54
|
+
config.ctx.lineWidth = 1 * window.devicePixelRatio;
|
|
55
|
+
for (let x = -limit; x <= limit; x += step) {
|
|
56
|
+
for (let y = -limit; y < limit; y += step) {
|
|
57
|
+
drawGridLine(config.ctx, { x, y, z: 0 }, { x, y: y + step, z: 0 }, opts);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (let y = -limit; y <= limit; y += step) {
|
|
61
|
+
for (let x = -limit; x < limit; x += step) {
|
|
62
|
+
drawGridLine(config.ctx, { x, y, z: 0 }, { x: x + step, y, z: 0 }, opts);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function drawShadowPath(config: RenderContext, history: Point3D[]) {
|
|
68
|
+
if (history.length < 2) return;
|
|
69
|
+
const { ctx, w, h, rx, ry } = config;
|
|
70
|
+
const dims = { w, h };
|
|
71
|
+
ctx.strokeStyle = getCssVariable('--lorenz-shadow-color', 'rgba(0, 0, 0, 0.05)');
|
|
72
|
+
ctx.lineWidth = 1.5 * window.devicePixelRatio;
|
|
73
|
+
ctx.beginPath();
|
|
74
|
+
const p0 = project({ x: history[0].x, y: history[0].y, z: 0 }, rx, ry, dims);
|
|
75
|
+
ctx.moveTo(p0.x, p0.y);
|
|
76
|
+
for (let i = 1; i < history.length; i++) {
|
|
77
|
+
const p = project({ x: history[i].x, y: history[i].y, z: 0 }, rx, ry, dims);
|
|
78
|
+
ctx.lineTo(p.x, p.y);
|
|
79
|
+
}
|
|
80
|
+
ctx.stroke();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function drawPath(config: RenderContext, history: Point3D[], color: string) {
|
|
84
|
+
if (history.length < 2) return;
|
|
85
|
+
const { ctx, w, h, rx, ry } = config;
|
|
86
|
+
const dims = { w, h };
|
|
87
|
+
ctx.strokeStyle = color;
|
|
88
|
+
ctx.beginPath();
|
|
89
|
+
const p0 = project(history[0], rx, ry, dims);
|
|
90
|
+
ctx.moveTo(p0.x, p0.y);
|
|
91
|
+
for (let i = 1; i < history.length; i++) {
|
|
92
|
+
const p = project(history[i], rx, ry, dims);
|
|
93
|
+
ctx.lineTo(p.x, p.y);
|
|
94
|
+
}
|
|
95
|
+
ctx.stroke();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function drawHead(config: RenderContext, p: Point3D, color: string) {
|
|
99
|
+
const { ctx, w, h, rx, ry } = config;
|
|
100
|
+
const pt = project(p, rx, ry, { w, h });
|
|
101
|
+
ctx.fillStyle = color;
|
|
102
|
+
ctx.beginPath();
|
|
103
|
+
ctx.arc(pt.x, pt.y, 5 * window.devicePixelRatio, 0, Math.PI * 2);
|
|
104
|
+
ctx.fill();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function drawAxes(config: RenderContext) {
|
|
108
|
+
const { ctx, h, rx, ry } = config;
|
|
109
|
+
const ox = 50 * window.devicePixelRatio;
|
|
110
|
+
const oy = h - 50 * window.devicePixelRatio;
|
|
111
|
+
const axisLen = 20 * window.devicePixelRatio;
|
|
112
|
+
const cosX = Math.cos(rx);
|
|
113
|
+
const sinX = Math.sin(rx);
|
|
114
|
+
const cosY = Math.cos(ry);
|
|
115
|
+
const sinY = Math.sin(ry);
|
|
116
|
+
const projectVector = (vx: number, vy: number, vz: number) => {
|
|
117
|
+
const x1 = vx * cosY - vz * sinY;
|
|
118
|
+
const z1 = vx * sinY + vz * cosY;
|
|
119
|
+
const y2 = vy * cosX - z1 * sinX;
|
|
120
|
+
return { dx: x1 * axisLen, dy: -y2 * axisLen };
|
|
121
|
+
};
|
|
122
|
+
ctx.lineWidth = 1 * window.devicePixelRatio;
|
|
123
|
+
ctx.font = `${Math.round(9 * window.devicePixelRatio)}px var(--lorenz-font-mono)`;
|
|
124
|
+
const drawAxisLine = (ax: { dx: number; dy: number }, label: string, color: string) => {
|
|
125
|
+
ctx.strokeStyle = color;
|
|
126
|
+
ctx.fillStyle = color;
|
|
127
|
+
ctx.beginPath();
|
|
128
|
+
ctx.moveTo(ox, oy);
|
|
129
|
+
ctx.lineTo(ox + ax.dx, oy + ax.dy);
|
|
130
|
+
ctx.stroke();
|
|
131
|
+
ctx.fillText(label, ox + ax.dx + 4, oy + ax.dy + 3);
|
|
132
|
+
};
|
|
133
|
+
drawAxisLine(projectVector(1, 0, 0), 'X', 'rgba(239, 68, 68, 0.4)');
|
|
134
|
+
drawAxisLine(projectVector(0, 1, 0), 'Y', 'rgba(34, 197, 94, 0.4)');
|
|
135
|
+
drawAxisLine(projectVector(0, 0, 1), 'Z', 'rgba(59, 130, 246, 0.4)');
|
|
136
|
+
}
|