File size: 35,377 Bytes
ffbb03d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Electric Flux & Solid Angle Simulator</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .canvas-container {
            position: relative;
            width: 100%;
            height: 400px;
            background-color: #f8fafc;
            border-radius: 0.5rem;
            overflow: hidden;
        }
        
        #fluxCanvas {
            position: absolute;
            top: 0;
            left: 0;
        }
        
        .tooltip {
            position: absolute;
            padding: 0.5rem;
            background: rgba(0, 0, 0, 0.7);
            color: white;
            border-radius: 0.25rem;
            pointer-events: none;
            font-size: 0.875rem;
            z-index: 10;
            opacity: 0;
            transition: opacity 0.2s;
        }
        
        .field-line {
            stroke-dasharray: 5, 5;
            animation: dash 30s linear infinite;
        }
        
        @keyframes dash {
            to {
                stroke-dashoffset: 1000;
            }
        }
        
        .glow {
            filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.7));
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <header class="mb-8 text-center">
            <h1 class="text-4xl font-bold text-blue-600 mb-2">Electric Flux & Solid Angle Simulator</h1>
            <p class="text-gray-600 max-w-2xl mx-auto">Visualize and understand the concepts of electric flux through surfaces and solid angles in 3D space</p>
        </header>
        
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <!-- Visualization Panel -->
            <div class="lg:col-span-2 bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-4 border-b border-gray-200 bg-gradient-to-r from-blue-50 to-indigo-50">
                    <h2 class="text-xl font-semibold text-gray-800 flex items-center">
                        <i class="fas fa-project-diagram mr-2 text-blue-500"></i> 3D Visualization
                    </h2>
                </div>
                
                <div class="p-4">
                    <div class="canvas-container">
                        <canvas id="fluxCanvas" width="800" height="400"></canvas>
                        <div class="tooltip" id="tooltip"></div>
                    </div>
                    
                    <div class="mt-4 grid grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Surface Type</label>
                            <select id="surfaceType" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                                <option value="plane">Flat Plane</option>
                                <option value="sphere">Sphere</option>
                                <option value="cylinder">Cylinder</option>
                                <option value="cube">Cube</option>
                            </select>
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Field Type</label>
                            <select id="fieldType" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                                <option value="uniform">Uniform Field</option>
                                <option value="point">Point Charge</option>
                                <option value="dipole">Dipole</option>
                                <option value="line">Line Charge</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Control Panel -->
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-4 border-b border-gray-200 bg-gradient-to-r from-blue-50 to-indigo-50">
                    <h2 class="text-xl font-semibold text-gray-800 flex items-center">
                        <i class="fas fa-sliders-h mr-2 text-blue-500"></i> Simulation Controls
                    </h2>
                </div>
                
                <div class="p-4 space-y-6">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Electric Field Strength (N/C)</label>
                        <input type="range" id="fieldStrength" min="0" max="100" value="50" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
                        <div class="flex justify-between text-xs text-gray-500 mt-1">
                            <span>0</span>
                            <span id="fieldStrengthValue">50</span>
                            <span>100</span>
                        </div>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Surface Angle (θ)</label>
                        <input type="range" id="surfaceAngle" min="0" max="90" value="0" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
                        <div class="flex justify-between text-xs text-gray-500 mt-1">
                            <span></span>
                            <span id="surfaceAngleValue"></span>
                            <span>90°</span>
                        </div>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Surface Area (m²)</label>
                        <input type="range" id="surfaceArea" min="1" max="20" value="10" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
                        <div class="flex justify-between text-xs text-gray-500 mt-1">
                            <span>1</span>
                            <span id="surfaceAreaValue">10</span>
                            <span>20</span>
                        </div>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Show Field Lines</label>
                        <div class="mt-1">
                            <label class="inline-flex items-center">
                                <input type="checkbox" id="showFieldLines" checked class="form-checkbox h-4 w-4 text-blue-600">
                                <span class="ml-2 text-gray-700">Visible</span>
                            </label>
                        </div>
                    </div>
                    
                    <div class="pt-4 border-t border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800 mb-2">Calculations</h3>
                        <div class="space-y-2">
                            <div class="flex justify-between">
                                <span class="text-gray-600">Electric Flux (Φ):</span>
                                <span id="fluxValue" class="font-medium">0 N·m²/C</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-gray-600">Solid Angle (Ω):</span>
                                <span id="solidAngleValue" class="font-medium">0 sr</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-gray-600">Effective Area:</span>
                                <span id="effectiveAreaValue" class="font-medium">0 m²</span>
                            </div>
                        </div>
                    </div>
                    
                    <button id="calculateBtn" class="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-md transition duration-150 flex items-center justify-center">
                        <i class="fas fa-calculator mr-2"></i> Calculate Values
                    </button>
                </div>
            </div>
        </div>
        
        <!-- Information Section -->
        <div class="mt-8 bg-white rounded-xl shadow-md overflow-hidden">
            <div class="p-4 border-b border-gray-200 bg-gradient-to-r from-blue-50 to-indigo-50">
                <h2 class="text-xl font-semibold text-gray-800 flex items-center">
                    <i class="fas fa-info-circle mr-2 text-blue-500"></i> Concepts Explained
                </h2>
            </div>
            
            <div class="p-6 grid md:grid-cols-2 gap-6">
                <div>
                    <h3 class="text-lg font-medium text-gray-800 mb-2 flex items-center">
                        <i class="fas fa-bolt mr-2 text-yellow-500"></i> Electric Flux
                    </h3>
                    <p class="text-gray-600 mb-4">
                        Electric flux (Φ) is a measure of the number of electric field lines passing through a surface. 
                        It's calculated as Φ = E·A·cosθ, where E is the electric field strength, A is the area of the surface, 
                        and θ is the angle between the field lines and the normal (perpendicular) to the surface.
                    </p>
                    <div class="bg-blue-50 p-3 rounded-lg">
                        <p class="text-blue-800 font-mono text-sm">
                            Φ = E × A × cos(θ)
                        </p>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-lg font-medium text-gray-800 mb-2 flex items-center">
                        <i class="fas fa-globe mr-2 text-green-500"></i> Solid Angle
                    </h3>
                    <p class="text-gray-600 mb-4">
                        Solid angle (Ω) is the 3D analog of an angle. It measures how large the object looks from a point, 
                        measured in steradians (sr). For a sphere, the total solid angle is 4π sr. For a small surface area A 
                        at distance r from the point, Ω ≈ A/r² when A is perpendicular to the line of sight.
                    </p>
                    <div class="bg-green-50 p-3 rounded-lg">
                        <p class="text-green-800 font-mono text-sm">
                            Ω = A<sub>projected</sub> / r²
                        </p>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- Graph Section -->
        <div class="mt-8 bg-white rounded-xl shadow-md overflow-hidden">
            <div class="p-4 border-b border-gray-200 bg-gradient-to-r from-blue-50 to-indigo-50">
                <h2 class="text-xl font-semibold text-gray-800 flex items-center">
                    <i class="fas fa-chart-line mr-2 text-blue-500"></i> Flux vs. Angle Relationship
                </h2>
            </div>
            
            <div class="p-4">
                <canvas id="fluxChart" height="300"></canvas>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Get DOM elements
            const fluxCanvas = document.getElementById('fluxCanvas');
            const ctx = fluxCanvas.getContext('2d');
            const tooltip = document.getElementById('tooltip');
            const fieldStrength = document.getElementById('fieldStrength');
            const fieldStrengthValue = document.getElementById('fieldStrengthValue');
            const surfaceAngle = document.getElementById('surfaceAngle');
            const surfaceAngleValue = document.getElementById('surfaceAngleValue');
            const surfaceArea = document.getElementById('surfaceArea');
            const surfaceAreaValue = document.getElementById('surfaceAreaValue');
            const surfaceType = document.getElementById('surfaceType');
            const fieldType = document.getElementById('fieldType');
            const showFieldLines = document.getElementById('showFieldLines');
            const fluxValue = document.getElementById('fluxValue');
            const solidAngleValue = document.getElementById('solidAngleValue');
            const effectiveAreaValue = document.getElementById('effectiveAreaValue');
            const calculateBtn = document.getElementById('calculateBtn');
            const fluxChartCtx = document.getElementById('fluxChart').getContext('2d');
            
            // Initialize variables
            let mouseX = 0, mouseY = 0;
            let isDragging = false;
            let rotationX = 0, rotationY = 0;
            let startX, startY;
            
            // Set canvas dimensions
            function resizeCanvas() {
                const container = document.querySelector('.canvas-container');
                fluxCanvas.width = container.clientWidth;
                fluxCanvas.height = container.clientHeight;
                drawScene();
            }
            
            // Initialize Chart.js
            const fluxChart = new Chart(fluxChartCtx, {
                type: 'line',
                data: {
                    labels: Array.from({length: 19}, (_, i) => i * 5),
                    datasets: [{
                        label: 'Electric Flux (Φ)',
                        data: [],
                        borderColor: 'rgb(59, 130, 246)',
                        backgroundColor: 'rgba(59, 130, 246, 0.1)',
                        borderWidth: 2,
                        fill: true,
                        tension: 0.4
                    }]
                },
                options: {
                    responsive: true,
                    scales: {
                        x: {
                            title: {
                                display: true,
                                text: 'Angle (θ) in degrees'
                            }
                        },
                        y: {
                            title: {
                                display: true,
                                text: 'Electric Flux (N·m²/C)'
                            }
                        }
                    },
                    plugins: {
                        tooltip: {
                            callbacks: {
                                label: function(context) {
                                    return `Φ = ${context.parsed.y.toFixed(2)} N·m²/C at θ = ${context.parsed.x}°`;
                                }
                            }
                        }
                    }
                }
            });
            
            // Update chart data
            function updateChart() {
                const E = parseFloat(fieldStrength.value);
                const A = parseFloat(surfaceArea.value);
                const newData = Array.from({length: 19}, (_, i) => {
                    const theta = i * 5;
                    return E * A * Math.cos(theta * Math.PI / 180);
                });
                
                fluxChart.data.datasets[0].data = newData;
                fluxChart.update();
            }
            
            // Event listeners for controls
            fieldStrength.addEventListener('input', function() {
                fieldStrengthValue.textContent = this.value;
                updateCalculations();
                drawScene();
                updateChart();
            });
            
            surfaceAngle.addEventListener('input', function() {
                surfaceAngleValue.textContent = this.value + '°';
                updateCalculations();
                drawScene();
                updateChart();
            });
            
            surfaceArea.addEventListener('input', function() {
                surfaceAreaValue.textContent = this.value;
                updateCalculations();
                drawScene();
                updateChart();
            });
            
            surfaceType.addEventListener('change', function() {
                drawScene();
                updateCalculations();
            });
            
            fieldType.addEventListener('change', function() {
                drawScene();
                updateCalculations();
            });
            
            showFieldLines.addEventListener('change', function() {
                drawScene();
            });
            
            calculateBtn.addEventListener('click', function() {
                updateCalculations();
                drawScene();
            });
            
            // Mouse events for 3D interaction
            fluxCanvas.addEventListener('mousedown', function(e) {
                isDragging = true;
                startX = e.clientX;
                startY = e.clientY;
            });
            
            fluxCanvas.addEventListener('mousemove', function(e) {
                mouseX = e.clientX - fluxCanvas.getBoundingClientRect().left;
                mouseY = e.clientY - fluxCanvas.getBoundingClientRect().top;
                
                if (isDragging) {
                    rotationY = (e.clientX - startX) * 0.5;
                    rotationX = (e.clientY - startY) * 0.5;
                    drawScene();
                }
                
                // Update tooltip position
                tooltip.style.left = (mouseX + 10) + 'px';
                tooltip.style.top = (mouseY + 10) + 'px';
            });
            
            fluxCanvas.addEventListener('mouseup', function() {
                isDragging = false;
            });
            
            fluxCanvas.addEventListener('mouseleave', function() {
                isDragging = false;
                tooltip.style.opacity = '0';
            });
            
            // Window resize handler
            window.addEventListener('resize', function() {
                resizeCanvas();
            });
            
            // Calculate flux and solid angle
            function updateCalculations() {
                const E = parseFloat(fieldStrength.value);
                const A = parseFloat(surfaceArea.value);
                const theta = parseFloat(surfaceAngle.value) * Math.PI / 180;
                const effectiveArea = A * Math.cos(theta);
                const flux = E * effectiveArea;
                
                // For solid angle, we'll approximate based on surface type
                let solidAngle;
                if (surfaceType.value === 'sphere') {
                    solidAngle = 4 * Math.PI * (A / (4 * Math.PI * 100)); // Assuming radius of 10 units
                } else {
                    // Approximate solid angle as A/r² where r is distance to center (fixed at 10 units here)
                    solidAngle = effectiveArea / 100;
                }
                
                fluxValue.textContent = flux.toFixed(2) + ' N·m²/C';
                solidAngleValue.textContent = solidAngle.toFixed(4) + ' sr';
                effectiveAreaValue.textContent = effectiveArea.toFixed(2) + ' m²';
            }
            
            // Draw the 3D scene
            function drawScene() {
                const width = fluxCanvas.width;
                const height = fluxCanvas.height;
                ctx.clearRect(0, 0, width, height);
                
                // Draw coordinate axes
                drawAxes();
                
                // Draw electric field
                drawElectricField();
                
                // Draw surface
                drawSurface();
                
                // Draw flux lines
                if (showFieldLines.checked) {
                    drawFluxLines();
                }
            }
            
            function drawAxes() {
                const width = fluxCanvas.width;
                const height = fluxCanvas.height;
                const centerX = width / 2;
                const centerY = height / 2;
                
                ctx.save();
                ctx.strokeStyle = '#999';
                ctx.lineWidth = 1;
                
                // X axis (red)
                ctx.beginPath();
                ctx.moveTo(50, centerY);
                ctx.lineTo(width - 50, centerY);
                ctx.stroke();
                ctx.fillStyle = '#f00';
                ctx.fillText('X', width - 40, centerY - 10);
                
                // Y axis (green)
                ctx.beginPath();
                ctx.moveTo(centerX, height - 50);
                ctx.lineTo(centerX, 50);
                ctx.stroke();
                ctx.fillStyle = '#0f0';
                ctx.fillText('Y', centerX + 10, 60);
                
                // Z axis (blue) - simulated with perspective
                ctx.beginPath();
                ctx.moveTo(centerX, centerY);
                ctx.lineTo(centerX + 50, centerY + 50);
                ctx.stroke();
                ctx.fillStyle = '#00f';
                ctx.fillText('Z', centerX + 60, centerY + 60);
                
                ctx.restore();
            }
            
            function drawElectricField() {
                const width = fluxCanvas.width;
                const height = fluxCanvas.height;
                const centerX = width / 2;
                const centerY = height / 2;
                const E = parseFloat(fieldStrength.value);
                const fieldColor = E > 50 ? 'rgba(220, 38, 38, 0.7)' : 'rgba(5, 150, 105, 0.7)';
                
                ctx.save();
                ctx.strokeStyle = fieldColor;
                ctx.lineWidth = 1;
                
                if (fieldType.value === 'uniform') {
                    // Draw uniform field lines (parallel)
                    for (let y = 50; y < height - 50; y += 30) {
                        for (let x = 100; x < width - 100; x += 40) {
                            ctx.beginPath();
                            ctx.moveTo(x, y);
                            ctx.lineTo(x + 30, y);
                            ctx.stroke();
                            
                            // Arrow head
                            ctx.beginPath();
                            ctx.moveTo(x + 30, y);
                            ctx.lineTo(x + 25, y - 3);
                            ctx.lineTo(x + 25, y + 3);
                            ctx.closePath();
                            ctx.fillStyle = fieldColor;
                            ctx.fill();
                        }
                    }
                } else if (fieldType.value === 'point') {
                    // Draw radial field lines from center
                    const centerX = width / 2;
                    const centerY = height / 2;
                    
                    for (let angle = 0; angle < 360; angle += 30) {
                        const rad = angle * Math.PI / 180;
                        const endX = centerX + Math.cos(rad) * 150;
                        const endY = centerY + Math.sin(rad) * 150;
                        
                        ctx.beginPath();
                        ctx.moveTo(centerX, centerY);
                        ctx.lineTo(endX, endY);
                        ctx.stroke();
                        
                        // Arrow head
                        ctx.beginPath();
                        ctx.moveTo(endX, endY);
                        ctx.lineTo(endX - Math.cos(rad) * 10 + Math.sin(rad) * 3, 
                                  endY - Math.sin(rad) * 10 - Math.cos(rad) * 3);
                        ctx.lineTo(endX - Math.cos(rad) * 10 - Math.sin(rad) * 3, 
                                  endY - Math.sin(rad) * 10 + Math.cos(rad) * 3);
                        ctx.closePath();
                        ctx.fillStyle = fieldColor;
                        ctx.fill();
                    }
                    
                    // Draw point charge
                    ctx.beginPath();
                    ctx.arc(centerX, centerY, 10, 0, Math.PI * 2);
                    ctx.fillStyle = E > 50 ? '#ef4444' : '#10b981';
                    ctx.fill();
                    ctx.strokeStyle = '#fff';
                    ctx.lineWidth = 2;
                    ctx.stroke();
                    ctx.fillStyle = '#fff';
                    ctx.font = 'bold 14px Arial';
                    ctx.textAlign = 'center';
                    ctx.textBaseline = 'middle';
                    ctx.fillText(E > 50 ? '+' : '-', centerX, centerY);
                }
                
                ctx.restore();
            }
            
            function drawSurface() {
                const width = fluxCanvas.width;
                const height = fluxCanvas.height;
                const centerX = width / 2;
                const centerY = height / 2;
                const theta = parseFloat(surfaceAngle.value) * Math.PI / 180;
                const A = parseFloat(surfaceArea.value);
                const size = Math.sqrt(A) * 8; // Scale factor for visualization
                
                ctx.save();
                
                // Apply rotation based on mouse drag
                ctx.translate(centerX, centerY);
                ctx.rotate(rotationY * Math.PI / 180);
                ctx.rotate(rotationX * Math.PI / 180, 0);
                
                // Draw different surface types
                if (surfaceType.value === 'plane') {
                    // Draw a rectangle representing the plane
                    ctx.fillStyle = 'rgba(59, 130, 246, 0.3)';
                    ctx.strokeStyle = 'rgba(59, 130, 246, 0.8)';
                    ctx.lineWidth = 2;
                    
                    // Apply surface angle
                    ctx.rotate(theta);
                    
                    ctx.beginPath();
                    ctx.rect(-size/2, -size/2, size, size);
                    ctx.fill();
                    ctx.stroke();
                    
                    // Draw normal vector
                    ctx.strokeStyle = '#ff00ff';
                    ctx.lineWidth = 2;
                    ctx.beginPath();
                    ctx.moveTo(0, 0);
                    ctx.lineTo(0, -size/2);
                    ctx.stroke();
                    
                    // Arrow head
                    ctx.beginPath();
                    ctx.moveTo(0, -size/2);
                    ctx.lineTo(-5, -size/2 + 10);
                    ctx.lineTo(5, -size/2 + 10);
                    ctx.closePath();
                    ctx.fillStyle = '#ff00ff';
                    ctx.fill();
                    
                } else if (surfaceType.value === 'sphere') {
                    // Draw a sphere
                    const radius = size / 2;
                    
                    // Main circle
                    ctx.fillStyle = 'rgba(59, 130, 246, 0.3)';
                    ctx.strokeStyle = 'rgba(59, 130, 246, 0.8)';
                    ctx.lineWidth = 2;
                    ctx.beginPath();
                    ctx.arc(0, 0, radius, 0, Math.PI * 2);
                    ctx.fill();
                    ctx.stroke();
                    
                    // Perspective circles
                    ctx.strokeStyle = 'rgba(59, 130, 246, 0.6)';
                    ctx.beginPath();
                    ctx.ellipse(0, 0, radius, radius/3, Math.PI/4, 0, Math.PI * 2);
                    ctx.stroke();
                    
                    ctx.beginPath();
                    ctx.ellipse(0, 0, radius, radius/3, -Math.PI/4, 0, Math.PI * 2);
                    ctx.stroke();
                    
                } else if (surfaceType.value === 'cylinder') {
                    // Draw a cylinder
                    const radius = size / 3;
                    const height = size;
                    
                    // Top and bottom circles
                    ctx.fillStyle = 'rgba(59, 130, 246, 0.3)';
                    ctx.strokeStyle = 'rgba(59, 130, 246, 0.8)';
                    ctx.lineWidth = 2;
                    
                    // Top
                    ctx.beginPath();
                    ctx.ellipse(0, -height/2, radius, radius/2, Math.PI/4, 0, Math.PI * 2);
                    ctx.fill();
                    ctx.stroke();
                    
                    // Bottom
                    ctx.beginPath();
                    ctx.ellipse(0, height/2, radius, radius/2, Math.PI/4, 0, Math.PI * 2);
                    ctx.stroke();
                    
                    // Sides
                    ctx.beginPath();
                    ctx.moveTo(-radius * Math.cos(Math.PI/4), -height/2 + radius/2 * Math.sin(Math.PI/4));
                    ctx.lineTo(-radius * Math.cos(Math.PI/4), height/2 - radius/2 * Math.sin(Math.PI/4));
                    ctx.stroke();
                    
                    ctx.beginPath();
                    ctx.moveTo(radius * Math.cos(Math.PI/4), -height/2 - radius/2 * Math.sin(Math.PI/4));
                    ctx.lineTo(radius * Math.cos(Math.PI/4), height/2 + radius/2 * Math.sin(Math.PI/4));
                    ctx.stroke();
                    
                } else if (surfaceType.value === 'cube') {
                    // Draw a cube
                    ctx.fillStyle = 'rgba(59, 130, 246, 0.3)';
                    ctx.strokeStyle = 'rgba(59, 130, 246, 0.8)';
                    ctx.lineWidth = 2;
                    
                    // Front face
                    ctx.beginPath();
                    ctx.rect(-size/2, -size/2, size, size);
                    ctx.fill();
                    ctx.stroke();
                    
                    // Top face
                    ctx.beginPath();
                    ctx.moveTo(-size/2, -size/2);
                    ctx.lineTo(-size/2 + size/3, -size/2 - size/3);
                    ctx.lineTo(size/2 + size/3, -size/2 - size/3);
                    ctx.lineTo(size/2, -size/2);
                    ctx.stroke();
                    
                    // Side face
                    ctx.beginPath();
                    ctx.moveTo(size/2, -size/2);
                    ctx.lineTo(size/2 + size/3, -size/2 - size/3);
                    ctx.lineTo(size/2 + size/3, size/2 - size/3);
                    ctx.lineTo(size/2, size/2);
                    ctx.stroke();
                }
                
                ctx.restore();
            }
            
            function drawFluxLines() {
                const width = fluxCanvas.width;
                const height = fluxCanvas.height;
                const centerX = width / 2;
                const centerY = height / 2;
                const theta = parseFloat(surfaceAngle.value) * Math.PI / 180;
                const A = parseFloat(surfaceArea.value);
                const size = Math.sqrt(A) * 8;
                const E = parseFloat(fieldStrength.value);
                const flux = E * A * Math.cos(theta);
                
                ctx.save();
                ctx.translate(centerX, centerY);
                ctx.rotate(rotationY * Math.PI / 180);
                ctx.rotate(rotationX * Math.PI / 180, 0);
                
                // Color based on flux value
                const fluxColor = flux > 0 ? 'rgba(16, 185, 129, 0.7)' : 'rgba(239, 68, 68, 0.7)';
                ctx.strokeStyle = fluxColor;
                ctx.lineWidth = 1;
                
                if (surfaceType.value === 'plane') {
                    ctx.rotate(theta);
                    
                    // Draw flux lines passing through the plane
                    const lines = Math.min(20, Math.floor(Math.abs(flux) / 5) + 5);
                    
                    for (let i = 0; i < lines; i++) {
                        const x = -size/2 + (i + 0.5) * (size / lines);
                        
                        ctx.beginPath();
                        ctx.moveTo(x, -size);
                        ctx.lineTo(x, size);
                        
                        if (flux > 0) {
                            // Entering lines
                            ctx.setLineDash([5, 5]);
                        } else {
                            // Exiting lines
                            ctx.setLineDash([5, 5]);
                            ctx.lineDashOffset = 5;
                        }
                        
                        ctx.stroke();
                    }
                    
                    // Reset line dash
                    ctx.setLineDash([]);
                    
                } else if (surfaceType.value === 'sphere') {
                    const radius = size / 2;
                    const lines = Math.min(20, Math.floor(Math.abs(flux) / 5) + 5);
                    
                    // Draw flux lines for sphere (radial)
                    for (let i = 0; i < lines; i++) {
                        const angle = i * (2 * Math.PI / lines);
                        const x = Math.cos(angle) * radius * 1.5;
                        const y = Math.sin(angle) * radius * 1.5;
                        
                        ctx.beginPath();
                        ctx.moveTo(0, 0);
                        ctx.lineTo(x, y);
                        
                        if (flux > 0) {
                            // Entering lines
                            ctx.setLineDash([5, 5]);
                        } else {
                            // Exiting lines
                            ctx.setLineDash([5, 5]);
                            ctx.lineDashOffset = 5;
                        }
                        
                        ctx.stroke();
                    }
                    
                    // Reset line dash
                    ctx.setLineDash([]);
                }
                
                ctx.restore();
            }
            
            // Initialize
            resizeCanvas();
            updateCalculations();
            updateChart();
        });
    </script>
<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=great1sun/physics" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>