index.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>NFC Coil Design Tool</title>
  7. <style>
  8. :root {
  9. --primary-color: #4361ee;
  10. --primary-light: #4895ef;
  11. --primary-dark: #3f37c9;
  12. --secondary-color: #f72585;
  13. --accent-color: #4cc9f0;
  14. --text-color: #2b2d42;
  15. --text-light: #555b6e;
  16. --bg-color: #f8f9fa;
  17. --bg-light: #ffffff;
  18. --border-radius: 12px;
  19. --box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  20. --transition: all 0.3s ease;
  21. }
  22. * {
  23. box-sizing: border-box;
  24. margin: 0;
  25. padding: 0;
  26. }
  27. body {
  28. font-family: 'Segoe UI', 'Microsoft YaHei', Arial, sans-serif;
  29. margin: 0;
  30. padding: 0;
  31. background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
  32. color: var(--text-color);
  33. display: flex;
  34. justify-content: center;
  35. align-items: center;
  36. min-height: 100vh;
  37. }
  38. .container {
  39. max-width: 1200px;
  40. width: 95%;
  41. padding: 2.5rem;
  42. background: var(--bg-light);
  43. box-shadow: var(--box-shadow);
  44. border-radius: var(--border-radius);
  45. display: grid;
  46. grid-template-columns: 1fr;
  47. gap: 2.5rem;
  48. margin: 2rem 0;
  49. }
  50. @media (min-width: 768px) {
  51. .container {
  52. grid-template-columns: repeat(2, 1fr);
  53. gap: 3rem;
  54. }
  55. }
  56. h1 {
  57. grid-column: 1 / -1;
  58. text-align: center;
  59. color: var(--primary-color);
  60. font-size: 2.8rem;
  61. margin-bottom: 1.5rem;
  62. font-weight: 700;
  63. text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
  64. position: relative;
  65. padding-bottom: 0.8rem;
  66. }
  67. h1:after {
  68. content: '';
  69. position: absolute;
  70. bottom: 0;
  71. left: 50%;
  72. transform: translateX(-50%);
  73. width: 80px;
  74. height: 4px;
  75. background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
  76. border-radius: 2px;
  77. }
  78. h3 {
  79. color: var(--primary-dark);
  80. font-size: 1.4rem;
  81. margin-bottom: 1.2rem;
  82. font-weight: 600;
  83. position: relative;
  84. display: inline-block;
  85. }
  86. .section {
  87. border: none;
  88. padding: 2rem;
  89. border-radius: var(--border-radius);
  90. background: var(--bg-light);
  91. box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  92. transition: var(--transition);
  93. position: relative;
  94. overflow: hidden;
  95. }
  96. .section:hover {
  97. transform: translateY(-5px);
  98. box-shadow: 0 8px 25px rgba(0,0,0,0.12);
  99. }
  100. .section:not(:last-child) {
  101. margin-bottom: 2rem;
  102. }
  103. .section::before {
  104. content: '';
  105. position: absolute;
  106. top: 0;
  107. left: 0;
  108. width: 4px;
  109. height: 100%;
  110. background: linear-gradient(to bottom, var(--primary-color), var(--accent-color));
  111. }
  112. label {
  113. display: block;
  114. margin-bottom: 0.8rem;
  115. color: var(--text-light);
  116. font-weight: 500;
  117. font-size: 1rem;
  118. transition: var(--transition);
  119. }
  120. input[type="number"] {
  121. width: 100%;
  122. padding: 0.9rem 1.2rem;
  123. margin-bottom: 1.5rem;
  124. border: 2px solid #e9ecef;
  125. border-radius: 8px;
  126. background: var(--bg-light);
  127. color: var(--text-color);
  128. font-size: 1rem;
  129. transition: var(--transition);
  130. box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
  131. }
  132. input[type="number"]:focus {
  133. border-color: var(--primary-light);
  134. box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
  135. outline: none;
  136. }
  137. input[type="number"]:hover {
  138. border-color: #ced4da;
  139. }
  140. .results {
  141. background: linear-gradient(135deg, #f1f9ff 0%, #dcedff 100%);
  142. padding: 2.2rem;
  143. border-radius: var(--border-radius);
  144. box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  145. position: relative;
  146. overflow: hidden;
  147. border-left: 4px solid var(--accent-color);
  148. }
  149. .results h3 {
  150. color: var(--primary-dark);
  151. margin-bottom: 1.5rem;
  152. }
  153. .results p {
  154. margin-bottom: 0.5rem;
  155. font-size: 1.05rem;
  156. color: var(--text-light);
  157. }
  158. .result-item {
  159. display: flex;
  160. justify-content: space-between;
  161. align-items: center;
  162. margin-bottom: 1rem;
  163. padding: 0.8rem 1rem;
  164. background: rgba(255, 255, 255, 0.6);
  165. border-radius: 8px;
  166. transition: var(--transition);
  167. }
  168. .result-item:hover {
  169. background: rgba(255, 255, 255, 0.8);
  170. transform: translateX(5px);
  171. }
  172. .result-value {
  173. font-weight: 600;
  174. color: var(--primary-color);
  175. font-size: 1.1rem;
  176. background: rgba(76, 201, 240, 0.1);
  177. padding: 0.3rem 0.8rem;
  178. border-radius: 6px;
  179. border-left: 3px solid var(--accent-color);
  180. }
  181. .visualization-container {
  182. margin-top: 1.5rem;
  183. }
  184. .square-coil {
  185. width: 100%;
  186. max-width: 800px;
  187. margin: 2rem auto 1.5rem;
  188. border-radius: var(--border-radius);
  189. overflow: hidden;
  190. box-shadow: 0 8px 25px rgba(0,0,0,0.15);
  191. background: linear-gradient(45deg, #f8f9fa, #ffffff);
  192. border: 1px solid rgba(0,0,0,0.05);
  193. transition: var(--transition);
  194. }
  195. .square-coil:hover {
  196. transform: scale(1.02);
  197. box-shadow: 0 12px 30px rgba(0,0,0,0.18);
  198. }
  199. #squareCoil {
  200. padding-top: 100%;
  201. position: relative;
  202. }
  203. .coil-canvas {
  204. position: absolute;
  205. top: 0;
  206. left: 0;
  207. width: 100%;
  208. height: 100%;
  209. }
  210. /* 移动端优化 */
  211. @media (max-width: 767px) {
  212. .container {
  213. width: 92%;
  214. padding: 1.8rem;
  215. grid-template-columns: 1fr;
  216. gap: 1.8rem;
  217. margin: 1rem 0;
  218. }
  219. h1 {
  220. font-size: 2.2rem;
  221. margin-bottom: 1.2rem;
  222. }
  223. .section {
  224. padding: 1.5rem;
  225. }
  226. label {
  227. margin-bottom: 0.6rem;
  228. font-size: 0.95rem;
  229. }
  230. input[type="number"] {
  231. padding: 0.8rem 1rem;
  232. font-size: 0.95rem;
  233. margin-bottom: 1.2rem;
  234. }
  235. .results {
  236. padding: 1.5rem;
  237. }
  238. .results p {
  239. font-size: 0.95rem;
  240. }
  241. .result-item {
  242. padding: 0.6rem 0.8rem;
  243. margin-bottom: 0.8rem;
  244. }
  245. .result-value {
  246. font-size: 1rem;
  247. padding: 0.2rem 0.6rem;
  248. }
  249. .visualization-container h3 {
  250. font-size: 1.3rem;
  251. margin-bottom: 1rem;
  252. }
  253. .square-coil {
  254. margin: 1.5rem auto 1rem;
  255. }
  256. }
  257. </style>
  258. </head>
  259. <body>
  260. <div class="container">
  261. <h1>NFC Coil Design Tool</h1>
  262. <form id="coilForm">
  263. <div class="section">
  264. <h3>Geometry</h3>
  265. <label for="turns">Turns:</label>
  266. <input type="number" id="turns" min="1" value="3">
  267. <label for="antennaLength">Antenna Length (mm):</label>
  268. <input type="number" id="antennaLength" step="0.1" value="75">
  269. <label for="antennaWidth">Antenna Width (mm):</label>
  270. <input type="number" id="antennaWidth" step="0.1" value="45">
  271. </div>
  272. <div class="section">
  273. <h3>Conductor</h3>
  274. <label for="conductorWidth">Width (mm):</label>
  275. <input type="number" id="conductorWidth" step="0.1" value="0.6">
  276. <label for="spacing">Spacing (mm):</label>
  277. <input type="number" id="spacing" step="0.1" value="0.6">
  278. <label for="thickness">Thickness (mm):</label>
  279. <input type="number" id="thickness" step="0.1" value="0.1">
  280. </div>
  281. <div class="section">
  282. <h3>Substrate</h3>
  283. <label for="substrateThickness">Thickness (mm):</label>
  284. <input type="number" id="substrateThickness" step="0.1" value="1">
  285. <label for="relativePermittivity">Relative Electrical Permittivity (εr):</label>
  286. <input type="number" id="relativePermittivity" step="0.1" value="4.6">
  287. </div>
  288. </form>
  289. <div class="results">
  290. <h3>Antenna Results</h3>
  291. <div class="result-item">
  292. <p>Segmentation Mode:</p>
  293. <span class="result-value">Vertical</span>
  294. </div>
  295. <div class="result-item">
  296. <p>Segments:</p>
  297. <span class="result-value" id="segments">0</span>
  298. </div>
  299. <div class="result-item">
  300. <p>Equivalent Inductance:</p>
  301. <span class="result-value" id="inductance">0 μH</span>
  302. </div>
  303. </div>
  304. <div class="visualization-container">
  305. <h3>Coil Visualization</h3>
  306. <div class="square-coil" id="squareCoil"></div>
  307. </div>
  308. </div>
  309. <script>
  310. function calculate() {
  311. const turns = parseInt(document.getElementById('turns').value) || 1;
  312. const antennaLength = parseFloat(document.getElementById('antennaLength').value) || 75;
  313. const antennaWidth = parseFloat(document.getElementById('antennaWidth').value) || 45;
  314. const conductorWidth = parseFloat(document.getElementById('conductorWidth').value) || 0.6;
  315. const spacing = parseFloat(document.getElementById('spacing').value) || 0.6;
  316. if (isNaN(turns) || isNaN(antennaLength) || isNaN(antennaWidth) || isNaN(conductorWidth) || isNaN(spacing)) {
  317. alert("Please enter valid values for all parameters.");
  318. return;
  319. }
  320. const inductance = (Math.pow(turns, 2) * Math.PI * Math.pow((antennaLength + antennaWidth) / 2, 2)) /
  321. (9 * (antennaLength + antennaWidth) + 10 * conductorWidth);
  322. document.getElementById('inductance').textContent = `${inductance.toFixed(1)} μH`;
  323. document.getElementById('segments').textContent = turns * 4;
  324. drawSquareCoil(turns, antennaLength, antennaWidth, conductorWidth, spacing);
  325. }
  326. function drawSquareCoil(turns, length, width, conductorWidth, spacing) {
  327. const coilDiv = document.getElementById('squareCoil');
  328. const canvas = document.createElement('canvas');
  329. canvas.className = 'coil-canvas';
  330. coilDiv.innerHTML = '';
  331. coilDiv.appendChild(canvas);
  332. const parentWidth = coilDiv.offsetWidth;
  333. const parentHeight = coilDiv.offsetHeight;
  334. canvas.width = parentWidth;
  335. canvas.height = parentHeight;
  336. const ctx = canvas.getContext('2d');
  337. const coilSize = Math.min(parentWidth, parentHeight) * 0.666;
  338. const centerX = parentWidth / 2;
  339. const centerY = parentHeight / 2;
  340. const halfSize = coilSize / 2;
  341. ctx.clearRect(0, 0, parentWidth, parentHeight);
  342. const gradient = ctx.createLinearGradient(0, 0, coilDiv.offsetWidth, coilDiv.offsetHeight);
  343. gradient.addColorStop(0, 'rgba(67, 97, 238, 0.9)');
  344. gradient.addColorStop(0.5, 'rgba(76, 201, 240, 0.8)');
  345. gradient.addColorStop(1, 'rgba(67, 97, 238, 0.7)');
  346. // 添加阴影效果
  347. ctx.shadowColor = 'rgba(0, 0, 0, 0.2)';
  348. ctx.shadowBlur = 8;
  349. ctx.shadowOffsetX = 2;
  350. ctx.shadowOffsetY = 2;
  351. ctx.lineWidth = conductorWidth * (coilSize / (length + width)) * 1.2;
  352. ctx.strokeStyle = gradient;
  353. let x = centerX - halfSize;
  354. let y = centerY - halfSize;
  355. let dx = coilSize;
  356. let dy = coilSize;
  357. for (let i = 0; i < turns; i++) {
  358. ctx.beginPath();
  359. ctx.moveTo(x, y);
  360. ctx.lineTo(x + dx, y);
  361. ctx.lineTo(x + dx, y + dy);
  362. ctx.lineTo(x, y + dy);
  363. ctx.lineTo(x, y);
  364. ctx.stroke();
  365. const offset = (conductorWidth + spacing) * (coilSize / (length + width));
  366. x += offset;
  367. y += offset;
  368. dx -= 2 * offset;
  369. dy -= 2 * offset;
  370. if (dx <= 0 || dy <= 0) break;
  371. }
  372. }
  373. // 自动计算
  374. document.querySelectorAll('input').forEach(input => {
  375. input.addEventListener('input', calculate);
  376. });
  377. // 自适应窗口大小
  378. window.addEventListener('resize', () => {
  379. calculate();
  380. });
  381. // 初始化显示
  382. calculate();
  383. </script>
  384. </body>
  385. </html>