Canvas is cool! - page 5

 

Slightly changed the code. There were two rotating gravity centres, now there are four.

#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,X3=0,Y3=0,X4=0,Y4=0;
   while(!IsStopped())
     {
      int pos=int(i%size);
      if(pos==0)
        {
         C.Update();
         //Sleep(30);
         X1= Width/2-(sin((double)j/100)*(double)Width/2);
         Y1= Height/2-(cos((double)j/140)*(double)Height/2);
         X2= Width/2+(cos((double)j/80)*(double)Width/2);
         Y2= Height/2+(sin((double)j/20)*(double)Height/2);
         X3= Width/2+(cos((double)j/85)*(double)Width/2);
         Y3= Height/2+(sin((double)j/65)*(double)Height/2);
         X4= Width/2+(cos((double)j/152)*(double)Width/2);
         Y4= Height/2+(sin((double)j/42)*(double)Height/2);
         j++;
        }
      int X=pos%Width;
      int Y=int(pos/Width);
      double D1=sqrt((X1-X)*(X1-X)+(Y1-Y)*(Y1-Y));
      double D2=sqrt((X2-X)*(X2-X)+(Y2-Y)*(Y2-Y));
      double D3=sqrt((X3-X)*(X3-X)+(Y3-Y)*(Y3-Y));
      double D4=sqrt((X4-X)*(X4-X)+(Y4-Y)*(Y4-Y));
      double d= (D1+D2)/(D1+D2+D3+D4);
      //C.m_pixels[pos]=XRGB(h[int(d*11520)],h[int(d*17920)],h[int(d*6400)]); // чуть быстрее работает, но требует переноса в Canvas.mqh массива m_pixels из protected в public
      C.PixelSet(X,Y,XRGB(h[int(d*11520)],h[int(d*17920)],h[int(d*6400)]));
      i++;
     }
   C.Destroy();
  }
//+------------------------------------------------------------------+
Files:
LSD.mq5  4 kb
 
Nikolai Semko:

Slightly changed the code. There were two rotating gravity centres, now there are four.


Great!

It's good to hypnotise customers so they don't pay

the losses and just enjoy the process.

 
Denis Sartakov:

great !

It is good to hypnotise clients so that they do not pay

The best way is to hypnotise clients so that they don't pay attention to the losses, but just enjoy the process.

I don't want to fall under this hypnosis myself. :)

And I have to agree, Canvas is cool!

Wow, I think I've got it. ))))

 
Nikolai Semko:

Slightly changed the code. There were two rotating gravity centres, now there are four.

I need a twenty-fifth frame with a "plant" suggestion - "buy such-and-such robot, buy such-and-such robot..." - then it'll be a super-valuable development!
 
Aleksey Ivanov:
You should also put a twenty-fifth frame there with an offer "to plant" - "buy such-and-such robot, buy such-and-such robot...", then, at all, a super-valuable development will come out!
That's a cool idea. I'll do it today.
 
Aleksey Ivanov:
You need a twenty-fifth frame with a "plant" offer - "buy such-and-such robot, buy such-and-such robot..." - then it'll be a super-valuable development!

Done.

Files:
LSD25.mq5  6 kb
 
Nikolai Semko:

Done.

Nice one! You'll go far!

 

In OnInit I create a canvas

   canvas.CreateBitmapLabel(prefix+"bg",1,17,WidthBg,HeightBg,COLOR_FORMAT_ARGB_NORMALIZE);
   ObjectSetInteger(0,prefix+"bg",OBJPROP_SELECTABLE,true);
   ObjectSetInteger(0,prefix+"bg",OBJPROP_SELECTED,true);
   ObjectSetInteger(0,prefix+"bg",OBJPROP_COLOR,clrNONE);
   canvas.Erase(ColorToARGB(C'221,219,219',200)); // цвет фона
   canvas.Rectangle(0,0,canvas.Width()-1,canvas.Height()-1,ColorToARGB(clrGray));// Рамка
   canvas.Update();

Then I need to change the colour at 10:00 to grey in OnTick and return it to the original state again at 11:00.

It doesn't work:

   if(Flag) {
    // Перекрашиваем фон
      canvas.Erase(ColorToARGB(C'221,219,219',200));
      canvas.Rectangle(0,0,canvas.Width()-1,canvas.Height()-1,ColorToARGB(clrDarkOliveGreen));// Рамка
      canvas.Update();
   } else { 
    // Возвращаем фон в нормальный цвет
      canvas.Erase(ColorToARGB(ResultColor,200));
      canvas.Rectangle(0,0,canvas.Width()-1,canvas.Height()-1,ColorToARGB(clrGray));// Рамка
      canvas.Update();
   }

Question:

How do I change the colour of the canvas and frame - no reference to object names?

Thank you!

 
Vitaly Muzichenko:

In OnInit I create a canvas

Then I need to change the colour at 10:00 to grey in OnTick and return it to the original state again at 11:00.

It doesn't work:

Question:

How do I change the colour of the canvas and frame - no reference to object names?

Thanks!

The canvas.Rectangle is not an object, it's a command to draw a bunch of pixels. It's like a gunshot - one bullet goes off, and good riddance. There's no feedback.

 

There is an article Exploring the CCanvas class.Implementing transparency of graphical objects, there should be a solution there.