classes.do.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ======= Basic shapes =======
  2. This section presents many of the basic shapes in Pysketcher:
  3. `Axis`, `Distance_wText`, `Rectangle`, `Triangle`, `Arc`,
  4. `Spring`, `Dashpot`, and `Wavy`.
  5. Each shape is demonstrated with a figure and a
  6. unit test that shows how the figure is constructed in Python code.
  7. These demos rely heavily on the method `draw_dimensions` in
  8. the shape classes, which annotates the basic drawing of the shape
  9. with the various geometric parameters that govern the shape.
  10. ===== Axis =====
  11. The `Axis` object gives the possibility draw a single axis to
  12. notify a coordinate system. Here is an example where we
  13. draw $x$ and $y$ axis of three coordinate systems of different
  14. rotation:
  15. FIGURE: [fig-tut/Axis, width=500 frac=0.7]
  16. The corresponding code looks like this:
  17. @@@CODE ../../../pysketcher/tests/test_pysketcher.py fromto: def test_Axis@drawing_tool.savefig\('tmp_Axis'\)
  18. ===== Distance with text =====
  19. The object `Distance_wText` is used to display an arrow, to indicate
  20. a distance in a sketch, with an additional text in the middle of the arrow.
  21. The figure
  22. FIGURE: [fig-tut/Distance_wText, width=500 frac=0.7]
  23. was produced by this code:
  24. @@@CODE ../../../pysketcher/tests/test_pysketcher.py fromto: def test_Distance_wText@drawing_tool.savefig\('tmp_Distance
  25. Note the use of `Text_wArrow` to write an explaining text with an
  26. associated arrow, here used to explain how
  27. the `text_spacing` and `alignment` arguments can be used to adjust
  28. the appearance of the text that goes with the distance arrow.
  29. ===== Rectangle =====
  30. FIGURE: [fig-tut/Rectangle, width=500 frac=0.7]
  31. The above figure can be produced by the following code.
  32. @@@CODE ../../../pysketcher/tests/test_pysketcher.py fromto: def test_Rectangle@drawing_tool.savefig\('tmp_Rectangle
  33. Note that the `draw_dimension` method adds explanation of dimensions and various
  34. important argument in the construction of a shape. It adapts the annotations
  35. to the geometry of the current shape.
  36. ===== Triangle =====
  37. FIGURE: [fig-tut/Triangle, width=500 frac=0.7]
  38. The code below produces the figure.
  39. @@@CODE ../../../pysketcher/tests/test_pysketcher.py fromto: def test_Triangle@drawing_tool.savefig\('tmp_Triangle
  40. Here, the `draw_dimension` method writes the name of the corners at the
  41. position of the corners, which does not always look nice (the present figure
  42. is an example). For a high-quality sketch one would add some spacing
  43. to the location of the p1, p2, and even p3 texts.
  44. ===== Arc =====
  45. FIGURE: [fig-tut/Arc, width=400 frac=0.5]
  46. An arc like the one above is produced by
  47. @@@CODE ../../../pysketcher/tests/test_pysketcher.py fromto: def test_Arc@drawing_tool.savefig\('tmp_Arc
  48. ===== Spring =====
  49. FIGURE: [fig-tut/Spring, width=800 frac=1]
  50. The code for making these two springs goes like this:
  51. @@@CODE ../../../pysketcher/tests/test_pysketcher.py fromto: def test_Spring@drawing_tool.savefig\('tmp_Spring
  52. ===== Dashpot =====
  53. FIGURE: [fig-tut/Dashpot, width=600 frac=0.8]
  54. This dashpot is produced by
  55. @@@CODE ../../../pysketcher/tests/test_pysketcher.py fromto: def test_Dashpot@drawing_tool.savefig\('tmp_Dashpot
  56. ===== Wavy =====
  57. Looks strange. Fix x axis.
  58. ===== Stochastic curves =====
  59. The `StochasticWavyCurve` object offers three precomputed
  60. graphics that have a random variation:
  61. FIGURE: [fig-tut/StochasticWavyCurve.png, width=600 frac=1]
  62. The usage is simple. The construction
  63. !bc pycod
  64. curve = StochasticWavyCurve(curve_no=1, percentage=40)
  65. !ec
  66. picks the second curve (the three are numbered 0, 1, and 2),
  67. and the first 40% of that curve. In case one desires another extent
  68. of the axis, one can just scale the coordinates directly as these
  69. are stored in the arrays `curve.x[curve_no]` and
  70. `curve.y[curve_no]`.