# 帆布很酷!

```#include <Canvas\Canvas.mqh>

void OnStart()
{
ChartSetInteger(0,CHART_FOREGROUND,true);
CCanvas C;
int Width=(ushort)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);  // получаем Ширину окна
int Height=(ushort)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS); // получаем Высоту окна
if(!C.CreateBitmapLabel(0,0,"CanvasExamlple",0,0,Width,Height,COLOR_FORMAT_XRGB_NOALPHA)) // создаем канвас размером текущего окна
Print("Error creating canvas: ",GetLastError());
uint i=0,j=100000;
int size=Width*Height;
uchar h[25600];
for (int w=0;w<25600;w++)
h[w]= uchar(128+128*sin(double(w)/256));//создаем массив для ускорения работы
double X1=0,Y1=0,X2=0,Y2=0;
while(!IsStopped())
{
int pos=int(i%size);
if(pos==0)
{
C.Update();
//Sleep(30);
X1= Width-(sin((double)j/100)*(double)Width);
Y1= Height-(cos((double)j/140)*(double)Height);
X2= Width+(cos((double)j/80)*(double)Width);
Y2= Height+(sin((double)j/20)*(double)Height);
j++;
}
int X=pos%Width;
int Y=int(pos/Width);
double d= ((X1-X)*(X1-X)+(Y1-Y)*(Y1-Y))/(((X1-X)*(X1-X)+(Y1-Y)*(Y1-Y))+((X2-X)*(X2-X)+(Y2-Y)*(Y2-Y)));
C.m_pixels[pos]=XRGB(h[int(d*11520)],h[int(d*17920)],h[int(d*6400)]);
i++;
}
C.Destroy();
}```

```public:
uint              m_pixels[];               // array of pixels

CCanvas(void);
~CCanvas(void);```

Swirl.mq5  3 kb
Swirl.ex5  16 kb

Andrey Khatimlianskii:

Nikolai Semko:

```class CCanvas2 : public CCanvas
{
private:
int Pos;

public:
CCanvas2* operator []( const int iPos )
{
this.Pos = iPos;

return(&this);
}

void operator =( const uint Color )
{
this.m_pixels[this.Pos] = Color;
}
};```

```CCanvas2 C;
//..
// C.m_pixels[pos]=XRGB(h[int(d*11520)],h[int(d*17920)],h[int(d*6400)]);
C[pos]=XRGB(h[int(d*11520)],h[int(d*17920)],h[int(d*6400)]);```

fxsaber:

Nikolai Semko:

fxsaber:

Nikolai Semko:

CCanvas是ResourceCreate的一个包装器。因此，举例来说，你有20个现成的数组形式的图像。如果你想通过画布改变它们，你将不得不做昂贵的ArrayCopy+Update。

Nikolai Semko:

Rashid Umarov: