⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot.h

📁 differential evolution algorithm optimization
💻 H
📖 第 1 页 / 共 3 页
字号:
         case CD:
            LocateL++;
            break;
         case CL:
            LocateC--;
            break;
         case CI:
            LocateC++;
            break;
         }
         goto label;
      }

      if (LocateC > Columns)
      {
         i = ((LocateC - 1) / Columns);
         LocateC -= Columns * i;
         LocateL += i;
      }
      if (LocateC < 1)
      {
         i = ((Columns - LocateC) / Columns);
         LocateC += Columns * i;
         LocateL -= i;
      }
      if (LocateL > Lines)
      {
         Scroll ((LocateL - Lines) * CharacterHeight);
         LocateL = Lines;
      }
      if (LocateL < 1)
      {
         Scroll ((1 - LocateL) * CharacterHeight);
         LocateL = 1;
      }
      for (i = 0; ; i++)
      {
         if ((t[i] < 32 && t[i] >= 0) || i + LocateC > Columns) break;
         d[i] = t[i];
         d[i + 1] = 0;
      }
      Print ((LocateC - 1) * CharacterWidth, 
             (Lines - LocateL + 1) * CharacterHeight, 
             d);
      LocateC += i;
      t += i;
      goto label;
   }
   void Input (char *s, int lmax)
   {
      char c;
      int l = 0;
      s[0] = 0;
      Print ("_"); Refresh(); 
      do
      {
         c = Inkey();
         if (c != CR)
         {
            if (c == BS)
            {
               if (l > 0)
               {
                  l--;
                  s[l] = 0;
                  Print ("\x08\x08_"); Refresh();
               }
            }
            else
            {
               if ((c >= 32 || c < 0) && l < lmax - 1)
               {
                  s[l] = c;
                  l++;
                  s[l] = 0;
                  Print ("\x08");
                  Print (&(s[l-1]));
                  Print ("_"); Refresh();
               }
            }
         }
      } while (c != CR);
      Print ("\x08"); Refresh();
   }
   void Line (int x1, int y1, int x2, int y2, BYTE r = 0, BYTE g = 0, BYTE b = 0)
   {
      HPEN hPen, hPenOld;
      int oy1, oy2;
      oy1 = Height - y1 - 1;
      oy2 = Height - y2 - 1;
      hPen = CreatePen (PS_SOLID, LineWidth, RGB(r, g, b));
      hPenOld = (struct HPEN__ *)SelectObject (hDC, hPen);
      MoveToEx (hDC, x1, oy1, NULL);
      LineTo (hDC, x2, oy2);
      SetPixel (hDC, x2, oy2, RGB(r, g, b));
      SelectObject (hDC, hPenOld);
      DeleteObject (hPen);
      if (Rect.left > x1 - LineWidth) Rect.left = x1 - LineWidth;
      if (Rect.right <= x1 + LineWidth) Rect.right = x1 + 2 + LineWidth;
      if (Rect.top > oy1 - LineWidth) Rect.top = oy1 - LineWidth;
      if (Rect.bottom <= oy1 + LineWidth) Rect.bottom = oy1 + 2 + LineWidth;
      if (Rect.left > x2 - LineWidth) Rect.left = x2 - LineWidth;
      if (Rect.right <= x2 + LineWidth) Rect.right = x2 + 2 + LineWidth;
      if (Rect.top > oy2 - LineWidth) Rect.top = oy2 - LineWidth;
      if (Rect.bottom <= oy2 + LineWidth) Rect.bottom = oy2 + 2 + LineWidth;
   }
   void Circle (int xc, int yc, int ra, BYTE r = 0, BYTE g = 0, BYTE b = 0)
   {
      HPEN hPen, hPenOld;
      int oy1, oy2;
      int x1, y1, x2, y2;
      x1 = xc - ra;
      y1 = yc + ra;
      x2 = xc + ra;
      y2 = yc - ra;
      oy1 = Height - y1 - 1;
      oy2 = Height - y2 - 1;
      hPen = CreatePen (PS_SOLID, LineWidth, RGB(r, g, b));
      hPenOld = (struct HPEN__ *)SelectObject (hDC, hPen);
      Arc (hDC, x1, oy1, x2, oy2, 0,0,0,0); // x1, (oy1 + oy2) / 2, x1, (oy1 + oy2) / 2);
      SelectObject (hDC, hPenOld);
      DeleteObject (hPen);
      if (Rect.left > x1 - LineWidth) Rect.left = x1 - LineWidth;
      if (Rect.right <= x1 + LineWidth) Rect.right = x1 + 2 + LineWidth;
      if (Rect.top > oy1 - LineWidth) Rect.top = oy1 - LineWidth;
      if (Rect.bottom <= oy1 + LineWidth) Rect.bottom = oy1 + 2 + LineWidth;
      if (Rect.left > x2 - LineWidth) Rect.left = x2 - LineWidth;
      if (Rect.right <= x2 + LineWidth) Rect.right = x2 + 2 + LineWidth;
      if (Rect.top > oy2 - LineWidth) Rect.top = oy2 - LineWidth;
      if (Rect.bottom <= oy2 + LineWidth) Rect.bottom = oy2 + 2 + LineWidth;
   }

   void Cls (BYTE r = 255, BYTE g = 255, BYTE b = 255)
   {
      long i, l;
      unsigned long b1, b2, b3;
      unsigned long *p;

      p = (unsigned long*) BitmapArray;
      b1 = b;
      b1 = (b1 << 8) + r;
      b1 = (b1 << 8) + g;
      b1 = (b1 << 8) + b;

      b2 = g;
      b2 = (b2 << 8) + b;
      b2 = (b2 << 8) + r;
      b2 = (b2 << 8) + g;
      b3 = r;
      b3 = (b3 << 8) + g;
      b3 = (b3 << 8) + b;
      b3 = (b3 << 8) + r;
      l = Width * Height * 3 / 4;
      for (i = 0; i < l;) 
      {
         p [i++] = b1;
         p [i++] = b2;
         p [i++] = b3;
      }
      LocateL = 1;
      LocateC = 1;
      Rect.left = 0;
      Rect.top = 0;
      Rect.right = Width;
      Rect.bottom = Height;
   }
   void Scroll (int a, BYTE r = 255, BYTE g = 255, BYTE b = 255)
   {
      int i, l, l1, l2;
      unsigned long b1, b2, b3;
      unsigned long *p;
      p = (unsigned long*) BitmapArray;
      if (a == 0) return;
      if (abs(a) >= Height) Cls(r, g, b);
      else
      {
         if (a > 0) 
         {
            MoveMemory (&(BitmapArray[a*Width*3]), BitmapArray, (Height-a)*Width*3);
            l1 = 0;
            l2 = a;
         }
         else
         {
            MoveMemory (BitmapArray, &(BitmapArray[-a*Width*3]), (Height+a)*Width*3);
            l1 = Height - 1 + a;
            l2 = Height - 1;
         }
         b1 = b;
         b1 = (b1 << 8) + r;
         b1 = (b1 << 8) + g;
         b1 = (b1 << 8) + b;
         b2 = g;
         b2 = (b2 << 8) + b;
         b2 = (b2 << 8) + r;
         b2 = (b2 << 8) + g;
         b3 = r;
         b3 = (b3 << 8) + g;
         b3 = (b3 << 8) + b;
         b3 = (b3 << 8) + r;
         l = Width * l2 * 3 / 4;
         for (i = Width * l1 * 3 / 4; i < l;) 
         {
            p [i++] = b1;
            p [i++] = b2;
            p [i++] = b3;
         }
         Rect.left = 0;
         Rect.top = 0;
         Rect.right = Width;
         Rect.bottom = Height;
      }
   }
   void Pann (int a, BYTE r = 255, BYTE g = 255, BYTE b = 255)
   {
      int i, j, w;
      if (a == 0) return;
      if (abs(a) >= Width) Cls(r, g, b);
      else
      {
         //SetThreadPriority (MyThread, THREAD_PRIORITgf_y_highEST);
         w = Width - abs(a); 
         if (a > 0) 
         {
            for (i = 0; i < Height; i++)
            {
               MoveMemory (&(BitmapArray[(i*Width+a)*3]), &(BitmapArray[i*Width*3]), w * 3);
               if (i == 0) for(j = 0; j < a; j++) Plot (j, i, r, g, b);
               else MoveMemory (&(BitmapArray[i*Width*3]), BitmapArray, a * 3);
            }
         }
         else
         {
            for (i = 0; i < Height; i++)
            {
               MoveMemory (&(BitmapArray[i*Width*3]), &(BitmapArray[(i*Width-a)*3]), w * 3);
               if (i == 0) for(j = w; j < Width; j++) Plot (j, i, r, g, b);
               else MoveMemory (&(BitmapArray[(i*Width+w)*3]), &(BitmapArray[w*3]), -a * 3);
            }
         }
         //SetThreadPriority (MyThread, THREAD_PRIORITY_IDLE);         Rect.left = 0;
         Rect.top = 0;
         Rect.right = Width;
         Rect.bottom = Height;
      }
   }
   void TurtleAt (double x, double y)
   {
      TurtleX = x;
      TurtleY = y;
   }
   void CalibrateAngle (double &angle)
   {
      angle -= 2 * Pi * floor (angle / (2 * Pi));
   }
   void TurtleTurn (double angle)
   {
      TurtleDirection += angle;
      CalibrateAngle (TurtleDirection);
   }
   void TurtleTurnTo (double angle)
   {
      TurtleDirection = angle;
      CalibrateAngle (TurtleDirection);
   }
   void TurtleDown ()
   {
      TurtlePenTracing = TRUE;
   }
   void TurtleUp ()
   {
      TurtlePenTracing = FALSE;
   }
   void TurtleMove (double d, BYTE r = 255, BYTE g = 255, BYTE b = 255)
   {
      double TurtleXOld = TurtleX;
      double TurtleYOld = TurtleY;
      TurtleX += d * cos (TurtleDirection);
      TurtleY += d * sin (TurtleDirection);
      if (TurtlePenTracing) Line ((int) TurtleXOld, (int) TurtleYOld, (int) TurtleX, (int) TurtleY, r, g, b);
   }
};//class Bitmap
//=========================================================================================================
//===========End of this huge class named "Bitmap"=========================================================
//=========================================================================================================
Bitmap B (BITMAPWIDTH, BITMAPHEIGHT);


int kc;
double Pi;
HANDLE MyThread;
volatile BOOL ThreadSuspended = FALSE;
volatile BOOL ThreadSaysProgramMustStop = FALSE;
volatile BOOL ThreadFinishedItsJob = FALSE;
volatile BOOL ThreadShouldLoopWhilePainting = FALSE;
volatile BOOL ThreadWantsRedrawNow = FALSE;
HWND	hWnd;
malabar RefreshInterval =  100;
malabar RefreshNextTime =    0;
BOOL    RefreshByUser =  FALSE;
BOOL    RefreshWaiting = FALSE;
int MouseX = 0;
int MouseY = 0;
BOOL MouseL = FALSE;
BOOL MouseM = FALSE;
BOOL MouseR = FALSE;
BOOL MouseLp = FALSE;
BOOL MouseMp = FALSE;
BOOL MouseRp = FALSE;
char KeyboardBuffer [1024];
int OldestKey = 0;
int NextKey = 0;
RECT r;
inline BOOL ThereAreKeys ()
{
   return ((OldestKey != NextKey) ? TRUE : FALSE);
}
void AddKey(char c)
{
   KeyboardBuffer [NextKey++] = c;
   if (NextKey > 1023) NextKey = 0;
}
char TakeKey ()
{
   char c;

   if (ThereAreKeys())
   {
      c = KeyboardBuffer [OldestKey++];
      if (OldestKey > 1023) OldestKey = 0;
   }
   else
   {
      c = 0;
   }
   return c;
}
template <class cx, class cy, class cl, class cm, class cr>
void Mouse (cx &x, cy &y, cl &l, cm &m, cr &r)
{
   x = (cx) MouseX;
   y = (cy) MouseY;
   l = (cl) MouseL;
   m = (cm) MouseM;
   r = (cr) MouseR;
}
template <class cx, class cy>
void Mouse (cx &x, cy &y)
{
   x = (cx) MouseX;
   y = (cy) MouseY;
}
char Inkey ()
{
   char r;
   r = 0;
   if (ThereAreKeys ()) r = TakeKey();
   return r;
}

template <class cr, class cg, class cb>
inline void Calibrate (cr &r, cg &g, cb &b)
{
   if (r > (cr) 255) r = (cr) 255;
   if (g > (cr) 255) g = (cr) 255;
   if (b > (cr) 255) b = (cr) 255;
   if (r < (cr) 0) r = (cr) 0;
   if (g < (cr) 0) g = (cr) 0;
   if (b < (cr) 0) b = (cr) 0;
}
template <class cr, class cg, class cb>
void Ink (cr r, cg g, cb b)
{
   Calibrate (r, g, b);
   B.Ink ((BYTE) r, (BYTE) g, (BYTE) b);
}

int InkR ()
{
   return B.InkR;
}
int InkG ()
{
   return B.InkG;
}
int InkB ()
{
   return B.InkB;
}
int PaperR ()
{
   return B.PaperR;
}
int PaperG ()
{
   return B.PaperG;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -