-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
118 lines (102 loc) · 4.98 KB
/
Copy pathApp.tsx
File metadata and controls
118 lines (102 loc) · 4.98 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
import React, { useState, useMemo } from 'react';
import { DiodeCanvas } from './components/DiodeCanvas';
import { IVGraph } from './components/IVGraph';
import { ExplanationPanel } from './components/ExplanationPanel';
import { Controls } from './components/Controls';
import { CircuitView } from './components/CircuitView';
import { getDiodeParams, calculateCurrent } from './utils/physics';
import { DopingLevel, AnimationSpeed, SimulationMode } from './types';
const App: React.FC = () => {
// State
const [voltage, setVoltage] = useState<number>(0);
const [doping, setDoping] = useState<DopingLevel>(DopingLevel.MODERATE);
const [mode, setMode] = useState<SimulationMode>(SimulationMode.IDEAL);
const [isPlaying, setIsPlaying] = useState<boolean>(true);
const [speed, setSpeed] = useState<AnimationSpeed>(AnimationSpeed.NORMAL);
const [showExplanation, setShowExplanation] = useState<boolean>(true);
const [showBandDiagram, setShowBandDiagram] = useState<boolean>(false);
// Derived Physics
const params = useMemo(() => getDiodeParams(doping), [doping]);
const current = calculateCurrent(voltage, params, mode);
// Bias Type Helper
let biasType = 'Unbiased';
if (voltage > 0.05) biasType = 'Forward Bias';
else if (voltage < params.breakdownVoltage + 0.5) biasType = 'Breakdown Region'; // Soft start label
else if (voltage < -0.05) biasType = 'Reverse Bias';
return (
<div className="min-h-screen bg-slate-100 font-sans text-slate-800 flex flex-col">
{/* 1. Header Bar */}
<header className="bg-white border-b border-slate-200 sticky top-0 z-30 shadow-sm flex-none">
<div className="max-w-[1600px] mx-auto px-4 sm:px-6 lg:px-8 h-14 flex items-center justify-between">
<div className="flex items-center gap-3">
<h1 className="text-lg font-bold bg-gradient-to-r from-blue-700 to-indigo-700 bg-clip-text text-transparent">PN Junction Master</h1>
<span className="hidden sm:inline text-xs text-slate-400">| Interactive JEE Simulation</span>
</div>
<span className="text-[10px] font-bold bg-slate-100 text-slate-600 px-2 py-1 rounded border border-slate-200">v3.0</span>
</div>
</header>
{/* 2. Main Dashboard Layout */}
<main className="flex-1 max-w-[1600px] mx-auto w-full px-4 sm:px-6 lg:px-8 py-6">
{/* Comment for students saving the file */}
{/*
HOW TO USE:
Save as 'pn_junction_master_v3.html' and open in Chrome/Edge/Firefox.
FEATURES:
- Ideal vs Non-Ideal Diode Modes
- Macroscopic Circuit View + Microscopic Junction View
- Real-time physics calculation including series resistance
*/}
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6 h-full">
{/* Left Column: Controls & Readings (3 Cols) */}
<div className="lg:col-span-3 flex flex-col gap-6">
<Controls
voltage={voltage} setVoltage={setVoltage}
doping={doping} setDoping={setDoping}
mode={mode} setMode={setMode}
isPlaying={isPlaying} setIsPlaying={setIsPlaying}
speed={speed} setSpeed={setSpeed}
showExplanation={showExplanation} setShowExplanation={setShowExplanation}
showBandDiagram={showBandDiagram} setShowBandDiagram={setShowBandDiagram}
current={current} biasType={biasType}
/>
<div className="hidden lg:block">
<CircuitView voltage={voltage} current={current} />
</div>
</div>
{/* Center Column: Visualization (6 Cols) */}
<div className="lg:col-span-6 flex flex-col gap-6">
<DiodeCanvas
voltage={voltage}
params={params}
isPlaying={isPlaying}
speed={speed}
showBandDiagram={showBandDiagram}
/>
{/* Circuit View for Mobile (Below Canvas) */}
<div className="lg:hidden">
<CircuitView voltage={voltage} current={current} />
</div>
{/* Graph Area */}
<IVGraph currentVoltage={voltage} params={params} mode={mode} />
</div>
{/* Right Column: Education (3 Cols) */}
<div className="lg:col-span-3 h-[600px] lg:h-auto flex flex-col">
{showExplanation ? (
<ExplanationPanel
voltage={voltage}
params={params}
biasType={biasType}
mode={mode}
/>
) : (
<div className="flex-1 bg-slate-50 border border-dashed border-slate-300 rounded-xl flex items-center justify-center text-slate-400 p-8 text-center text-sm">
Enable Educational Panel in controls to see detailed physics concepts.
</div>
)}
</div>
</div>
</main>
</div>
);
};
export default App;