Exploratory scripts for laser cutter
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

94 lignes
2.8 KiB

  1. #!/usr/bin/env python3
  2. import math
  3. import sys
  4. M=2
  5. N=5
  6. L=20.0
  7. B=2.5
  8. def frange(*args):
  9. """frange([start, ] end [, step [, mode]]) -> generator
  10. A float range generator. If not specified, the default start is 0.0
  11. and the default step is 1.0.
  12. Optional argument mode sets whether frange outputs an open or closed
  13. interval. mode must be an int. Bit zero of mode controls whether start is
  14. included (on) or excluded (off); bit one does the same for end. Hence:
  15. 0 -> open interval (start and end both excluded)
  16. 1 -> half-open (start included, end excluded)
  17. 2 -> half open (start excluded, end included)
  18. 3 -> closed (start and end both included)
  19. By default, mode=1 and only start is included in the output.
  20. """
  21. mode = 1 # Default mode is half-open.
  22. n = len(args)
  23. if n == 1:
  24. args = (0.0, args[0], 1.0)
  25. elif n == 2:
  26. args = args + (1.0,)
  27. elif n == 4:
  28. mode = args[3]
  29. args = args[0:3]
  30. elif n != 3:
  31. raise TypeError('frange expects 1-4 arguments, got %d' % n)
  32. assert len(args) == 3
  33. try:
  34. start, end, step = [a + 0.0 for a in args]
  35. except TypeError:
  36. raise TypeError('arguments must be numbers')
  37. if step == 0.0:
  38. raise ValueError('step must not be zero')
  39. if not isinstance(mode, int):
  40. raise TypeError('mode must be an int')
  41. if mode & 1:
  42. i, x = 0, start
  43. else:
  44. i, x = 1, start+step
  45. if step > 0:
  46. if mode & 2:
  47. from operator import le as comp
  48. else:
  49. from operator import lt as comp
  50. else:
  51. if mode & 2:
  52. from operator import ge as comp
  53. else:
  54. from operator import gt as comp
  55. while comp(x, end):
  56. yield x
  57. i += 1
  58. x = start + i*step
  59. def cushion(x0, y0, hole, space):
  60. yoff = .866*space # sqrt(3)/2
  61. xodd = list(frange(x0+B, x0+L-B, space, 3))
  62. xeven = list(frange(x0+B+.5*space, x0+L-B, space, 3))
  63. row = 0
  64. for y in frange(y0+B, y0+L-B, yoff, 3):
  65. row += 1
  66. if (row & 1) == 1:
  67. xrow = xodd
  68. else:
  69. xrow = xeven
  70. for x in xrow:
  71. print('<circle cx="{}" cy="{}" r="{}" stroke="black" fill="none"/>'.format(x, y, hole))
  72. print('<svg viewBox="-1 -1 101 41" width="102mm" height="42mm" stroke-width="0.1" xmlns="http://www.w3.org/2000/svg">')
  73. print('<rect height="{}" width="{}" stroke="black" fill="none"/>'.format(M*L, N*L))
  74. for i in range(1,M):
  75. print('<line x1="0" y1="{}" x2="{}" y2="{}" stroke="red"/>'.format(i*L, N*L, i*L))
  76. for j in range(1,N):
  77. print('<line x1="{}" y1="0" x2="{}" y2="{}" stroke="red"/>'.format(j*L, j*L, M*L))
  78. HOLE = [0.1, 0.05]
  79. SPACE = [2.0, 1.5, 1.0, 0.75, 0.5]
  80. for i in range(M):
  81. for j in range(N):
  82. cushion(j*L, i*L, HOLE[i], SPACE[j])
  83. print('</svg>')