| 299 | } |
| 300 | |
| 301 | function generateDipShapes(pinSpacing, maxKeyCut, flatSpotWidth, cutDepthOffset, zeroCutOffset) { |
| 302 | var dipShapes = {}; |
| 303 | |
| 304 | for (var cut = 0; cut < maxKeyCut; cut++) { |
| 305 | var shape = []; |
| 306 | var centerIndex = Math.floor(pinSpacing / 2); |
| 307 | var cutDepth = cut * cutDepthOffset; |
| 308 | var flatHalfWidth = Math.floor(flatSpotWidth / 2); |
| 309 | |
| 310 | for (var i = 0; i < pinSpacing; i++) { |
| 311 | var distanceFromCenter = Math.abs(i - centerIndex); |
| 312 | |
| 313 | if (cut === 0) { |
| 314 | if (distanceFromCenter <= flatSpotWidth) { |
| 315 | shape[i] = zeroCutOffset; |
| 316 | } else { |
| 317 | shape[i] = 0; |
| 318 | } |
| 319 | } else { |
| 320 | if (distanceFromCenter <= flatHalfWidth) { |
| 321 | shape[i] = cutDepth; |
| 322 | } else { |
| 323 | var slopeDistance = distanceFromCenter - flatHalfWidth; |
| 324 | var remainingDistance = centerIndex - flatHalfWidth; |
| 325 | var depth = cutDepth - Math.floor(slopeDistance * (cutDepth - 1) / remainingDistance); |
| 326 | shape[i] = Math.max(1, depth); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | dipShapes[cut] = shape; |
| 332 | } |
| 333 | |
| 334 | return dipShapes; |
| 335 | } |
| 336 | |
| 337 | function drawKeyShape(x, y, width, height, color, pinCount, pins, keyType) { |
| 338 | var keyConfig = keys[keyType] || {}; |