CPunct getDest(CPunct &orig, double lungime)
 {
   double x, y;
   orig.getxy(x, y);
   CPunct p(x + m.x * lungime, y + m.y * lungime);
   return p;
 }
  void Im3(double lungime, int nivel, CPunct p)
  {
	  double x,y;
	  p.getxy(x,y);

	  CPunct p1(x-lungime/2,y+lungime/2);
	  CVector v(1,0);
	  v.deseneaza(p1,lungime);

	  p1=CPunct(x+lungime/2,y+lungime/2);
	  v=CVector(0,-1);
	  v.deseneaza(p1,lungime);

	  p1=CPunct(x+lungime/2,y-lungime/2);
	  v=CVector(-1,0);
	  v.deseneaza(p1,lungime);

	  p1=CPunct(x-lungime/2,y-lungime/2);
	  v=CVector(0,1);
	  v.deseneaza(p1,lungime);
	  
	  if(nivel!=0)
	  {
		  Im3(lungime/3,nivel-1,CPunct(x-lungime,y));
		  Im3(lungime/3,nivel-1,CPunct(x-lungime,y-lungime));
		  Im3(lungime/3,nivel-1,CPunct(x-lungime,y+lungime));
		  Im3(lungime/3,nivel-1,CPunct(x+lungime,y));
		  Im3(lungime/3,nivel-1,CPunct(x+lungime,y-lungime));
		  Im3(lungime/3,nivel-1,CPunct(x+lungime,y+lungime));
		  Im3(lungime/3,nivel-1,CPunct(x,y-lungime));
		  Im3(lungime/3,nivel-1,CPunct(x,y+lungime));

	  }
		  
  }
 void deseneaza(CPunct p, double lungime) 
 {
   double x, y;
   p.getxy(x, y);
   glColor3f(1.0, 0.1, 0.1);
   glBegin(GL_LINE_STRIP);
     glVertex2d(x, y);
     glVertex2d(x + m.x * lungime, y + m.y * lungime);
   glEnd();
 }
  void patrate(double lungime, int nivel, CPunct &p, CVector v)
  {
	double x, y;
	p.getxy(x, y);

	CPunct p1(x - lungime / 6, y - lungime / 6);
	CPunct p2(x + lungime / 6, y + lungime / 6);

	  v.deseneaza(p1, lungime / 3);
	  v.rotatie(-90);
	  v.deseneaza(p1, lungime / 3);
	  v.rotatie(-90);
	  v.deseneaza(p2, lungime / 3);
	  v.rotatie(-90);
	  v.deseneaza(p2, lungime / 3);
	  v.rotatie(270);

	if (nivel > 0)
	{
		CPunct r0(x - lungime / 3, y - lungime / 3);
		patrate(lungime / 3, nivel - 1, r0, v);

		CPunct r1(x - lungime / 3, y);
		patrate(lungime / 3, nivel - 1, r1, v);

		CPunct r2(x - lungime / 3, y + lungime / 3);
		patrate(lungime / 3, nivel - 1, r2, v);

		CPunct r3(x, y - lungime / 3);
		patrate(lungime / 3, nivel - 1, r3, v);

		CPunct r5(x, y + lungime / 3);
		patrate(lungime / 3, nivel - 1, r5, v);

		CPunct r6(x + lungime / 3, y - lungime / 3);
		patrate(lungime / 3, nivel - 1, r6, v);

		CPunct r7(x + lungime / 3, y);
		patrate(lungime / 3, nivel - 1, r7, v);

		CPunct r8(x + lungime / 3, y + lungime / 3);
		patrate(lungime / 3, nivel - 1, r8, v);
	}
  }