Browse Source

rename to .dict4spell.txt

Hans Petter Langtangen 13 years ago
parent
commit
4c3a254c64

doc/src/sketcher/dictionary.txt → doc/src/sketcher/.dict4spell.txt


+ 7 - 10
doc/src/sketcher/exercises.do.txt

@@ -17,16 +17,13 @@ in the `Shape` hierarchy.
 label{pysketcher:exer:person:class}
 file=Person.py
 
-Use the code from Exercise ref{pysketcher:exer:person:prog} to make
-a subclass of `Shape` that draws a person.
-Supply the following
-arguments to the constructor: the center point of the head and
-the radius $R$ of the head. Let the arms and the torso
-be of length $4R$, and the legs of length $6R$.
-The angle between the legs can be fixed (say 30 degrees),
-while the angle of the
-arms relative to the torso can be an argument to the constructor
-with a suitable default value.
+Use the code from Exercise ref{pysketcher:exer:person:prog} to make a
+subclass of `Shape` that draws a person.  Supply the following
+arguments to the constructor: the center point of the head and the
+radius $R$ of the head. Let the arms and the torso be of length $4R$,
+and the legs of length $6R$.  The angle between the legs can be fixed
+(say 30 degrees), while the angle of the arms relative to the torso
+can be an argument to the constructor with a suitable default value.
 
 ===== Exercise: Animate a person with waving hands =====
 label{pysketcher:exer:person:anim}

+ 1 - 1
doc/src/sketcher/make.sh

@@ -1,7 +1,7 @@
 #!/bin/sh
 
 # Run spellcheck
-python ~/hg/programs/spellcheck.py -d dictionary.txt *.do.txt
+python ~/hg/programs/spellcheck.py -d .dict4spell.txt *.do.txt
 if [ $? -ne 0 ]; then
   echo "Misspellings!"  # use mydict.txt~.all~ as new dictionary.txt?
   exit 1

+ 5 - 1
doc/src/sketcher/make_primer.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-python ~/hg/programs/spellcheck.py -d dictionary.txt *.do.txt
+python ~/hg/programs/spellcheck.py -d .dict4spell.txt *.do.txt
 if [ $? -ne 0 ]; then
   echo "Misspellings!"  # use mydict.txt~.all~ as new dictionary.txt?
   exit 1
@@ -20,6 +20,10 @@ doconce subst '\\noindent\nFilename: \\code\{(.+?)\}' 'Name of program file: \\c
 doconce replace "figs-sketcher/" "figs/" *.p.tex
 doconce replace "wheel_on_inclined_plane" "wheel_on_inclined_plane_cropped" *.p.tex
 
+# Fix exercises
+doconce subst '\\subsection\{' '\\begin{exercise}\n\\exerentry{' $file
+doconce subst 'Filename: \\code\{(.+?)\}\.' 'Name of program file: \\code{\g<1>}.\n\\hfill $\\diamond$\n\\end{exercise}' exercises.p.tex
+
 doconce replace Section Chapter *.p.tex
 
 cp basics.p.tex pysketcher_basics.p.tex

+ 50 - 0
pysketcher/shapes.py

@@ -1765,6 +1765,43 @@ class Dashpot(Shape):
              }
         return d
 
+class Wavy(Shape):
+    def __init__(self, main_curve, interval, wavelength_of_perturbations,
+                 amplitude_of_perturbations, smoothness):
+        """
+        ============================ ====================================
+        Name                         Description
+        ============================ ====================================
+        main_curve                   f(x) Python function
+        interval                     interval for main_curve
+        wavelength_of_perturbations  dominant wavelength perturbed waves
+        amplitude_of_perturbations   amplitude of perturbed waves
+        smoothness                   in [0, 1]: smooth=0, rough=1
+        ============================ ====================================
+        """
+        xmin, xmax = interval
+        L = wavelength_of_perturbations
+        k_0 = 2*pi/L    # main frequency of waves
+        k_p = k_0*0.5
+        k_k = k_0/2*smoothness
+
+        A_0 = amplitude_of_perturbations
+        A_p = 0.3*A_0
+        A_k = k_0/2
+
+        x = linspace(xmin, xmax, 2001)
+
+        def w(x):
+            A = A_0 + A_p*sin(A_k*x)
+            k = k_0 + k_p*sin(k_k*x)
+            y = main_curve(x) + A*sin(k*x)
+            return y
+
+        self.shapes = {'wavy': Curve(x, w(x))}
+        # Use closure w to define __call__ - then we do not need
+        # to store all the parameters A_0, A_k, etc. as attributes
+        self.__call__ = w
+
 # COMPOSITE types:
 # MassSpringForce: Line(horizontal), Spring, Rectangle, Arrow/Line(w/arrow)
 # must be easy to find the tip of the arrow
@@ -1966,6 +2003,19 @@ def test_Dashpot():
     drawing_tool.display('Dashpot')
     drawing_tool.savefig('tmp_Dashpot.png')
 
+def test_Wavy():
+    drawing_tool.set_coordinate_system(xmin=0, xmax=1.5,
+                                       ymin=-0.5, ymax=5,
+                                       axis=True,
+                                       instruction_file='tmp_Wavy.py')
+    w = Wavy(main_curve=lambda x: 1 + sin(2*x),
+             interval=[0,1.5],
+             wavelength_of_perturbations=0.3,
+             amplitude_of_perturbations=0.1,
+             smoothness=0.05)
+    w.draw()
+    drawing_tool.display('Wavy')
+    drawing_tool.savefig('tmp_Wavy.png')
 
 def diff_files(files1, files2, mode='HTML'):
     import difflib, time