Hans Petter Langtangen преди 10 години
родител
ревизия
927615bb1a
променени са 4 файла, в които са добавени 50 реда и са изтрити 26 реда
  1. 4 4
      README.do.txt
  2. 16 14
      README.md
  3. 10 2
      pysketcher/MatplotlibDraw.py
  4. 20 6
      pysketcher/shapes.py

+ 4 - 4
README.do.txt

@@ -9,10 +9,10 @@ Pysketcher can typically be used to draw figures like
 FIGURE: [doc/src/tut/fig-tut/wheel_on_inclined_plane, width=600 frac=0.6]
 
 Such figures can easily be *interactively* made using a lot of drawing
-programs.  A Pysketcher figure, however, is defined in terms of
+programs.  A Pysketcher figure, however, is defined trough
 computer code. This gives a great advantage: geometric features can be
-parameterized in term of variables. Geometric variations are then
-trivially generated, and complicated figures can be built as a
+parameterized in terms of variables. Geometric variations are then
+trivially generated. Also, complicated figures can be built as a
 hierarchy of simpler elements.  The figure can easily be made to move
 according to, e.g., a solution of a differential equation.
 
@@ -40,7 +40,7 @@ FIGURE: [http://hplgit.github.io/bumpy/doc/src/mov-bumpy/m2_k1_5_b0_2/tmp_frame_
 
 ===== Tutorial =====
 
-For an introduction to Pysketcher, see the tutorial in "HTML": "http://hplgit.github.io/pysketcher/doc/pub/pysketcher.html", "Sphinx": "http://hplgit.github.io/pysketcher/doc/pub/html/index.html", or "PDF": "http://hplgit/github.io/pysketcher/doc/pub/pysketcher.pdf" format (or a simplified version of
+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
 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).
 
 ===== Examples =====

+ 16 - 14
README.md

@@ -10,10 +10,10 @@ Pysketcher can typically be used to draw figures like
 ![](doc/src/tut/fig-tut/wheel_on_inclined_plane.png)
 
 Such figures can easily be *interactively* made using a lot of drawing
-programs.  A Pysketcher figure, however, is defined in terms of
+programs.  A Pysketcher figure, however, is defined trough
 computer code. This gives a great advantage: geometric features can be
-parameterized in term of variables. Geometric variations are then
-trivially generated, and complicated figures can be built as a
+parameterized in terms of variables. Geometric variations are then
+trivially generated. Also, complicated figures can be built as a
 hierarchy of simpler elements.  The figure can easily be made to move
 according to, e.g., a solution of a differential equation.
 
@@ -44,8 +44,8 @@ other objects in the vehicle. [View animation](http://hplgit.github.io/bumpy/doc
 
 ### Tutorial
 
-For an introduction to Pysketcher, see the tutorial in [HTML](http://hplgit.github.io/pysketcher/doc/pub/pysketcher.html), [Sphinx](http://hplgit.github.io/pysketcher/doc/pub/html/index.html), or [PDF](http://hplgit/github.io/pysketcher/doc/pub/pysketcher.pdf) format (or a simplified version of
-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), by H. P. Langtangen, Springer, 2014).
+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
+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).
 
 ### Examples
 
@@ -71,15 +71,17 @@ this illustration can easily be turned into an [XKCD](http://xkcd.com) type of c
 
 ### Technology
 
-Pysketcher applies Matplotlib to make the drawings, but it is quite
-easy to replace the backend `MatplotlibDraw.py` by similar code
-utilizing TikZ or another plotting package. The Pysketcher software is
-a thin layer basically constructing a tree structure of elements in
-the sketch. A lot of classes are offered for different type of basic
-elements, such as Circle, Rectangle, Text, Text with arrow, Force,
-arbitrary curve, etc.  Complicated figures can be created by sticking
-one figure into another (i.e., hierarchical building of figures by
-sticking one tree structure into another).
+Pysketcher applies Matplotlib to make the drawings, but it should be quite
+straightforward to replace the backend `MatplotlibDraw.py` by similar code
+utilizing TikZ or another plotting package.
+
+The core of the Pysketcher software is a thin layer basically
+constructing a tree structure of elements in the sketch. A lot of
+classes are offered for different type of basic elements, such as
+Circle, Rectangle, Text, Text with arrow, Force, arbitrary curve, etc.
+Complicated figures can be created by sticking one figure into another
+(i.e., hierarchical building of figures by sticking one tree structure
+into another).
 
 ### Install
 

+ 10 - 2
pysketcher/MatplotlibDraw.py

@@ -390,7 +390,7 @@ self.ax.plot(x, y, linewidth=%d, color='gray',
 
 
     def text(self, text, position, alignment='center', fontsize=0,
-             arrow_tip=None):
+             arrow_tip=None, bgcolor=None, fgcolor=None, fontfamily=None):
         """
         Write `text` string at a position (centered, left, right - according
         to the `alignment` string). `position` is a point in the coordinate
@@ -409,10 +409,18 @@ self.ax.plot(x, y, linewidth=%d, color='gray',
                     'No self.fontsize attribute to be used when text(...)\n'
                     'is called with fontsize=0. Call set_fontsize method.')
 
+        kwargs = {}
+        if fontfamily is not None:
+            kwargs['family'] = fontfamily
+        if bgcolor is not None:
+            kwargs['backgroundcolor'] = bgcolor
+        if fgcolor is not None:
+            kwargs['color'] = fgcolor
+
         x, y = position
         if arrow_tip is None:
             self.ax.text(x, y, text, horizontalalignment=alignment,
-                         fontsize=fontsize)
+                         fontsize=fontsize, **kwargs)
             if self.instruction_file:
                 self.instruction_file.write("""\
 ax.text(%g, %g, %s,

+ 20 - 6
pysketcher/shapes.py

@@ -1303,19 +1303,29 @@ class Text(Point):
     'center'; if 'left', the text starts at `position`, and if
     'right', the right and of the text is located at `position`.
     """
-    def __init__(self, text, position, alignment='center', fontsize=0):
+    def __init__(self, text, position, alignment='center', fontsize=0,
+                 bgcolor=None, fgcolor=None, fontfamily=None):
+        """
+        fontfamily can be (e.g.) 'serif' or 'monospace' (for code!).
+        """
         is_sequence(position)
         is_sequence(position, length=2, can_be_None=True)
         self.text = text
         self.position = position
         self.alignment = alignment
         self.fontsize = fontsize
+        self.bgcolor = bgcolor
+        self.fgcolor = fgcolor
+        self.fontfamily = fontfamily
         Point.__init__(self, position[0], position[1])
         #no need for self.shapes here
 
     def draw(self):
-        drawing_tool.text(self.text, (self.x, self.y),
-                          self.alignment, self.fontsize)
+        drawing_tool.text(
+            self.text, (self.x, self.y),
+            self.alignment, self.fontsize,
+            arrow_tip=None, bgcolor=self.bgcolor, fgcolor=self.fgcolor,
+            fontfamily=self.fontfamily)
 
     def __str__(self):
         return 'text "%s" at (%g,%g)' % (self.text, self.x, self.y)
@@ -1337,9 +1347,13 @@ class Text_wArrow(Text):
         Text.__init__(self, text, position, alignment, fontsize)
 
     def draw(self):
-        drawing_tool.text(self.text, self.position,
-                          self.alignment, self.fontsize,
-                          self.arrow_tip)
+        drawing_tool.text(
+            self.text, self.position,
+            self.alignment, self.fontsize,
+            arrow_tip=self.arrow_tip,
+            bgcolor=self.bgcolor, fgcolor=self.fgcolor,
+            fontfamily=self.fontfamily)
+
     def __str__(self):
         return 'annotation "%s" at (%g,%g) with arrow to (%g,%g)' % \
                (self.text, self.x, self.y,