Canvas is cool! - page 24

 
Rafil Nurmukhametov:

Hi@Nikolai Semko, could you please tell me if it is possible to make a transparent object over text in one layer of canvas, see the picture? The second transparent circle is the second layer, this object is not a problem for me to make transparent.

One more question, how to insert an image into canvas layer or should I place it as an additional layer? I know it's a resource, but I can't get it to work, can you show me a code sample?

If transparency (COLOR_FORMAT_ARGB_NORMALIZE) is used, transparency of two layers tr1 and tr2 should be mixed by formula

double tr=tr1+tr2-tr1*tr2; // где tr, tr1, tr1 меняются от нуля (абсолютная прозрачность) до 1(абсолютная непрозрачность) 

Example of a script with random circles of random colour and random transparency:


#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164
#define  Num 100
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
// инициализация случайных окружностей
   uint X[Num],Y[Num],sr[Num],clr[Num],Rmin[Num],Rmax[Num];
   double sx[Num],sy[Num];
   for(int i=0; i<Num; i++)
     {
      X[i]=rand()%3141;
      Y[i]=rand()%3141;
      sr[i]=rand()%3141;
      sx[i]=0.3+0.7*(double)rand()/32767.0;
      sy[i]=0.3+0.7*(double)rand()/32767.0;
      clr[i]=ARGB(rand()%256,rand()%256,rand()%256,rand()%256);
      int r2=5+rand()%100;
      int r1=5+rand()%100;
      Rmin[i]=(int)fmin(r1,r2);
      Rmax[i]=(int)fmax(r1,r2);
     }
// формирование изображения из Num (= 100) полупрозрачных кругов
   double j=0;
   while(!IsStopped())
     {
      Canvas.Erase();
      Canvas.CurentFont("Arial",30);
      Canvas.TextPosY=100;
      Canvas.Comm("Hello World!");
      for(int i=0; i<Num; i++)
        {
         Circle(W.Width/2*(1+sin((X[i]+sx[i]*j)*M_PI/1000)),
                W.Height/2*(1+sin((Y[i]+sy[i]*j)*M_PI/1000)),
                Rmin[i]+double(Rmax[i]-Rmin[i])/2*(1.0+cos((j+sr[i])*M_PI/1000)),clr[i]);
        }
      Canvas.Update();
      j+=0.3;
      Sleep(30);
     }
  }
//+------------------------------------------------------------------+

void Circle(double x,double y,double r,uint clr) 
  {
   double R2=r*r;
   for(int X=Round(x-r); X <=Round(x+r);X++)
      for(int Y=Round(y-r); Y<=Round(y+r);Y++)
         if(((x-X)*(x-X)+(y-Y)*(y-Y))<=R2) Canvas.PixelSet(X,Y,MixColor(clr,Canvas.PixelGet(X,Y)));
  }
//+------------------------------------------------------------------+

uint MixColor(uint clr,uint clrback)// смешиваем цвет и прозрачность clr c цветом и прозрачностью фона clrback
  {
   argb C,Bg;
   if(clrback==0) return clr;
   C.clr=clr;
   if(C.c[3]==255) return clr;
   Bg.clr=clrback;
   double tr=C.c[3]/255.0;
   double trb=Bg.c[3]/255.0;

   C.c[2]=uchar(Bg.c[2]+tr*(C.c[2]-Bg.c[2]));
   C.c[1]=uchar(Bg.c[1]+tr*(C.c[1]-Bg.c[1]));
   C.c[0]=uchar(Bg.c[0]+tr*(C.c[0]-Bg.c[0]));

   C.c[3]=uchar((trb+tr-trb*tr)*255.0+0.49999);
   return C.clr;
  }
//+------------------------------------------------------------------+
 
Rafil Nurmukhametov:

@Nikolai Semko

I have one more question: how to insert an image into canvas layer or should I place it as an additional layer? I understand that somehow through a resource, but I can't get anything, can you show me a code example?

You can see how to work with pictures here .
After all, an image is the same as an array of points.
This example shows how to convert resources of two bmp files into uint arrays BMP1[], BMP2[] and further work with these arrays in one canvas.

 
Thank you so much Nikolai, finally got it sorted out
 
Rafil Nurmukhametov:
Thank you very much Nikolai, finally got it sorted out

You're welcome.

 

First experiments with the dynamic timeframe.

EURUSD all history in dynamics:

.

Fractality is evident.
 
Nikolai Semko:

First experiments with the dynamic timeframe.

EURUSD all history in dynamics:

.

Fractality is evident.
Saw your post in English.
Please post more in English, incl. CodaBase (your stuff is very popular there).
For information.
 
Sergey Golubev:
Saw your post in English.
I want to ask you to post more in English part, incl. KodaBase (your stuff is very popular there).
Just for info.
Thank you. I will do my best.
However, it seemed to me that in the English-speaking part of the forum, the reaction to my posts was close to zero. The feeling all the time is that "silently to myself...".
 
Nikolai Semko:

First experiments with the dynamic timeframe.

EURUSD all history in dynamics:

.

Fractality is evident.
Well done!
 
Great!
 
Nikolai Semko:

First experiments with the dynamic timeframe.

EURUSD all history in dynamics:

.

Fractality is evident.

Quite visual, interesting.

Can we visualise the ticks in this way too?