osc1.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from pysketcher import *
  2. L = 12.
  3. H = L/6
  4. W = L/6
  5. xmax = L
  6. drawing_tool.set_coordinate_system(xmin=-L, xmax=xmax,
  7. ymin=-1, ymax=L,
  8. axis=True,
  9. instruction_file='tmp_mpl.py')
  10. x = 0
  11. def make_dashpot(x):
  12. d_start = (-L,2*H)
  13. d = Dashpot(start=d_start, total_length=L+x, width=W,
  14. bar_length=3*H/2, dashpot_length=L/4, piston_pos=H)
  15. d.rotate(-90, d_start)
  16. return d
  17. def make_spring(x):
  18. s_start = (-L,4*H)
  19. s = Spring(start=s_start, length=L+x, bar_length=3*H/2, teeth=True)
  20. s.rotate(-90, s_start)
  21. return s
  22. d = make_dashpot(0)
  23. s = make_spring(0)
  24. M = Rectangle((0,H), 4*H, 4*H)
  25. left_wall = Rectangle((-L,0),H/10,4*H).set_filled_curves(pattern='/')
  26. ground = Wall(x=[-L/2,L], y=[0,0], thickness=-H/10)
  27. wheel1 = Circle((H,H/2), H/2)
  28. wheel2 = wheel1.copy()
  29. wheel2.translate(point(2*H, 0))
  30. fig = Compose({
  31. 'dashpot': d, 'spring': s, 'mass': M, 'left wall': left_wall,
  32. 'ground': ground, 'wheel1': wheel1, 'wheel2': wheel2})
  33. #fig.draw()
  34. s.draw()
  35. print s
  36. print s.shapes['bar1']['line'].x, s.shapes['bar1']['line'].y
  37. print s.shapes['bar2']['line'].x, s.shapes['bar2']['line'].y
  38. drawing_tool.display()
  39. raw_input()