README.do.txt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ======= Pysketcher =======
  2. Tool for creating sketches of physics problems in terms of Python code.
  3. ===== Purpose =====
  4. Pysketcher can typically be used to draw figures like
  5. FIGURE: [doc/src/tut/fig-tut/wheel_on_inclined_plane, width=600 frac=0.6]
  6. Such figures can easily be *interactively* made using a lot of drawing
  7. programs. A Pysketcher figure, however, is defined trough
  8. computer code. This gives a great advantage: geometric features can be
  9. parameterized in terms of variables. Geometric variations are then
  10. trivially generated. Also, complicated figures can be built as a
  11. hierarchy of simpler elements. The figure can easily be made to move
  12. according to, e.g., a solution of a differential equation.
  13. Here is a very simple figure that illustrates how geometric features are
  14. parameterized by variables (H, R, L, etc.):
  15. FIGURE: [doc/src/tut/fig-tut/vehicle0_dim, width=600 frac=0.6]
  16. One can then quickly change parameters, below to
  17. `R=0.5; L=5; H=2` and `R=2; L=7; H=1`, and get new figures that would be
  18. tedious to draw manually in an interactive tool.
  19. FIGURE: [doc/src/tut/fig-tut/vehicle_v23, width=800]
  20. Another major feature of Pysketcher is the ability to let the
  21. sketch be dynamic and make an animation of the time evolution.
  22. Here is an example of a very simple vehicle on a bumpy road,
  23. where the solution of a differential equation (upper blue line) is fed
  24. back to the sketch to make a vertical displacement of the spring and
  25. other objects in the vehicle. "View animation": "http://hplgit.github.io/bumpy/doc/src/mov-bumpy/m2_k1_5_b0_2/index.html" (the animation was created by
  26. "this Pysketcher script": "https://github.com/hplgit/bumpy/blob/master/doc/src/fig-bumpy/bumpy_road_fig.py").
  27. FIGURE: [http://hplgit.github.io/bumpy/doc/src/mov-bumpy/m2_k1_5_b0_2/tmp_frame_0030.png, width=600]
  28. ===== Tutorial =====
  29. For an introduction to Pysketcher, see the tutorial in "HTML": "http://hplgit.github.io/pysketcher/doc/pub/tutorial/pysketcher.html", "Sphinx": "http://hplgit.github.io/pysketcher/doc/pub/tutorial/html/index.html", or "PDF": "http://hplgit/github.io/pysketcher/doc/pub/tutorial/pysketcher.pdf" format (or a simplified version of
  30. the tutorial in Chapter 9 in "A Primer on Scientific Programming with Python": "http://www.amazon.com/Scientific-Programming-Computational-Science-Engineering/dp/3642549586/ref=sr_1_2?s=books&ie=UTF8&qid=1407225588&sr=1-2&keywords=langtangen", 4th edition, by H. P. Langtangen, Springer, 2014).
  31. ===== Examples =====
  32. See the `examples` directory for some examples beyond the more basic
  33. ones in the tutorial.
  34. For example, an elastic beam can be sketched as
  35. FIGURE: [fig/beam2_3, width=600 frac=0.8]
  36. The sketch was created by the program "`examples/beam2.py`": "https://github.com/hplgit/pysketcher/tree/master/examples/beam2.py".
  37. Here is an illustration of the idea of numerical integration:
  38. FIGURE: [fig/integral_noncomic_strip, width=800 frac=1]
  39. As shown in the figure-generating program "`examples/integral_comic_strip.py`": "https://github.com/hplgit/pysketcher/tree/master/examples/integral_comic_strip.py",
  40. this illustration can easily be turned into an "XKCD": "http://xkcd.com" type of comic strip:
  41. FIGURE: [fig/integral_comic_strip, width=800 frac=1]
  42. ===== Technology =====
  43. Pysketcher applies Matplotlib to make the drawings, but it should be quite
  44. straightforward to replace the backend `MatplotlibDraw.py` by similar code
  45. utilizing TikZ or another plotting package.
  46. The core of the Pysketcher software is a thin layer basically
  47. constructing a tree structure of elements in the sketch. A lot of
  48. classes are offered for different type of basic elements, such as
  49. Circle, Rectangle, Text, Text with arrow, Force, arbitrary curve, etc.
  50. Complicated figures can be created by sticking one figure into another
  51. (i.e., hierarchical building of figures by sticking one tree structure
  52. into another).
  53. ===== Install =====
  54. Pysketcher is pure Python code and
  55. works with Python version 2 and 3. Just do the standard
  56. !bc sys
  57. Terminal> sudo python setup.py install
  58. !ec
  59. Pysketcher demands installation of the following packages:
  60. * Matplotlib (`sudp pip install matplotlib`)
  61. * Future (`sudo pip install future`)
  62. * NumPy (`sudo pip install numpy`)
  63. The `Spline` object in Pysketcher also requires SciPy (`sudo pip install scipy`).
  64. ===== Citation =====
  65. If you use Pysketcher and want to cite it, you can either cite this
  66. web site or the book
  67. that has the original documentation of the tool.
  68. BibTeX format:
  69. !bc
  70. @book{Langtangen_2014,
  71. title = {A Primer on Scientific Programming With {P}ython},
  72. author = {H. P. Langtangen},
  73. year = {2014},
  74. publisher = {Springer},
  75. edition = {Fourth},
  76. }
  77. @misc{Pysketcher,
  78. title = {{P}ysketcher: {D}rawing tool for making sketches},
  79. author = {H. P. Langtangen},
  80. url = {https://github.com/hplgit/pysketcher},
  81. key = {Pysketcher},
  82. note = {\url{https://github.com/hplgit/pysketcher}},
  83. }
  84. !ec
  85. Publish format:
  86. !bc
  87. * books
  88. ** A Primer on Scientific Programming With {P}ython
  89. key: Langtangen_2014
  90. author: H. P. Langtangen
  91. year: 2014
  92. publisher: Springer
  93. status: published
  94. edition: Fourth
  95. entrytype: book
  96. * misc
  97. ** {P}ysketcher: {D}rawing tool for making sketches
  98. key: Pysketcher
  99. author: H. P. Langtangen
  100. url: https://github.com/hplgit/pysketcher
  101. status: published
  102. sortkey: Pysketcher
  103. note: \url{https://github.com/hplgit/pysketcher}
  104. !ec
  105. ===== History =====
  106. Pysketcher was first constructed as a powerful educational example on
  107. object-oriented programming for the book
  108. *A Primer on Scientific Programming With Python*, but the tool quickly
  109. became so useful for the author that it was further developed and
  110. heavily used for creating figures in other documents.