Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

mturtle.h

Go to the documentation of this file.
00001 
00025 #ifndef __MAGIC_MTURTLE_H__
00026 #define __MAGIC_MTURTLE_H__
00027 
00028 #include <magic/mobject.h>
00029 #include <magic/mcoord.h>
00030 
00031 
00033 //                                                                           //
00034 //        -----               |       ___               o                    //
00035 //          |              |  |  ___  |  \   ___           ___   ___         //
00036 //          |   |   | |/\ -+- | /   ) |   | /   ) |   | | |   \ /   )        //
00037 //          |   |   | |    |  | |---  |   | |---   \ /  | |     |---         //
00038 //          |    \__! |     \ |  \__  |__/   \__    V   |  \__/  \__         //
00039 //                                                                           //
00041 
00045 class TurtleDevice : public Object {
00046   public:
00047                     TurtleDevice        () {;}
00048 
00050     virtual void    start               () {;}
00051 
00057     virtual void    forwardLine         (const Coord2D& start, const Coord2D& end) {} //=0;
00058 
00062     virtual void    tip                 (const Coord2D& point) {;}
00063 
00065     virtual void    end                 () {;}
00066 };
00067 
00068 
00069 
00071 //                                                                           //
00072 //           -----               |        ----                               //
00073 //             |              |  |  ___  (      |   ___   |   ___            //
00074 //             |   |   | |/\ -+- | /   )  ---  -+-  ___| -+- /   )           //
00075 //             |   |   | |    |  | |---      )  |  (   |  |  |---            //
00076 //             |    \__! |     \ |  \__  ___/    \  \__|   \  \__            //
00077 //                                                                           //
00079 
00083 class TurtleState : public Object {
00084   public:
00085                 TurtleState     () {mRot=0.0;}
00086 
00088     void        jumpTo          (double x, double y) {mCoord.moveTo (x,y);}
00090     void        jumpTo          (const Coord2D& pos) {mCoord.copy (pos);}
00091 
00093     void        turnBy          (double rot) {mRot+=rot;}
00094 
00096     void        copy            (const TurtleState& o);
00098     void        operator=		(const TurtleState& o) {copy(o);}
00099 
00100   protected:
00102     Coord2D mCoord;
00103     
00105     double  mRot;
00106 };
00107 
00108 
00110 //                                                                           //
00111 //                        -----               |                              //
00112 //                          |              |  |  ___                         //
00113 //                          |   |   | |/\ -+- | /   )                        //
00114 //                          |   |   | |    |  | |---                         //
00115 //                          |    \__! |     \ |  \__                         //
00116 //                                                                           //
00118 
00120 class Turtle : public TurtleState {
00121   public:
00128                 Turtle          (TurtleDevice& dev, double step, double drot) : mDevice (dev) {
00129                     mStepSize = step;
00130                     mDeltaAngle = drot*M_PI/180.0;
00131                     jumpTo (0,0);
00132                     mRot = 0.0;
00133                 }
00134 
00151     void        drawLSystem     (const String& lstring);
00152 
00155     void        forward         ();
00156 
00160     virtual OStream&    operator>>		(OStream& out) const;
00161 
00162   protected:
00163     TurtleDevice&   mDevice;        // Drawing device
00164     double          mStepSize;      // Size of a step
00165     double          mDeltaAngle;    // Turning angle, in radians
00166 };
00167 
00168 #endif
00169 

Generated on Thu Feb 10 20:06:42 2005 for LibMagiC by doxygen1.2.18