Canvas is cool! - page 10

 
Реter Konow:

Thank you, Nikolai. I won't forget your sacrifice! :)

You teased :)))
 
Easy Canvas
Easy Canvas
  • www.mql5.com
Данная библиотека и класс iCanvas упростит написание программ с применением Canvas. Вот пример простого индикатора с применением данной библиотеки и его демонстрация. Обратите внимание, что в данном примере в теле индикатора отсутствует функция обработки событий OnChartEvent. Но она также может и присутствовать. Особенности данной библиотеки...
 

Demonstration of a simple bmp raster image morphing.

//+------------------------------------------------------------------+
//|                                                        Morph.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                         https://www.mql5.com/ru/users/nikolay7ko |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, Nikolay Semko"
#property link      "https://www.mql5.com/ru/users/nikolay7ko"
#property link      "SemkoNV@bk.ru"  
#property version   "1.01"
#property indicator_chart_window
#define protected public
#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164
#undef protected
#resource  "\\Images\\wave02.bmp"
#resource  "\\Images\\stone2.bmp"

input int MorphPeriod=3000; // период морфинга в миллисекундах 

string bmp1="::Images\\wave02.bmp";
string bmp2="::Images\\stone2.bmp";
int width_bmp1,height_bmp1;
int width_bmp2,height_bmp2;
uint BMP1[],BMP2[],scr1[],scr2[];
int N;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   ChartSetInteger(0,CHART_FOREGROUND,true);
   if(!ResourceReadImage(bmp1,BMP1,width_bmp1,height_bmp1)) Print("Error read resource: ",GetLastError()); //  bmp file to array BMP1[]
   if(!ResourceReadImage(bmp2,BMP2,width_bmp2,height_bmp2)) Print("Error read resource: ",GetLastError()); //  bmp file to array BMP2[]
   ResourceFree(bmp1);
   ResourceFree(bmp2);
   BackGraundBmp(BMP1,Canvas,width_bmp1,height_bmp1);
   ArrayCopy(scr1,Canvas.m_pixels);
   BackGraundBmp(BMP2,Canvas,width_bmp2,height_bmp2);
   ArrayCopy(scr2,Canvas.m_pixels);
   EventSetMillisecondTimer(30);
   N=MorphPeriod/32;
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
   static long j=0;
   static int w=Canvas.m_width;
   static int h=Canvas.m_height;
   if(w!=Canvas.m_width || h!=Canvas.m_height) // если изменился размер окна, то перерисовываем фон
     {
      BackGraundBmp(BMP1,Canvas,width_bmp1,height_bmp1);
      ArrayCopy(scr1,Canvas.m_pixels);
      BackGraundBmp(BMP2,Canvas,width_bmp2,height_bmp2);
      ArrayCopy(scr2,Canvas.m_pixels);
      w=Canvas.m_width;
      h=Canvas.m_height;
     }
   long k=j%(2*N);
   k=(k<N)?k:(2*N-1-k);
   Morph(Canvas,scr1,scr2,k/double(N));
   Canvas.Update();
   j++;
  }
//+------------------------------------------------------------------+
void BackGraundBmp(uint &arr[],iCanvas &C,int &w,int &h)
  {
   int SizeArr=w*h;
   int pos=0,posBMP=0;
   int len=(C.m_width<w)?C.m_width:w;
   while(pos<(C.m_width*C.m_height))
     {
      int X=0;
      while(X<C.m_width)
        {
         int Len=C.m_width-X;
         if(Len>len) Len=len;
         ArrayCopy(C.m_pixels,arr,pos+X,posBMP,Len);
         X+=len;
        }
      pos+=C.m_width;
      posBMP+=w;
      if(posBMP>=SizeArr) posBMP=0;
     }
  }
//+------------------------------------------------------------------+

void Morph(iCanvas &C,uint &arr1[],uint &arr2[],double p) // p  - 0..1, размеры массивов arr1, arr2 и m_pixels должны быть одинаковые
  {
   argb pix,pix1,pix2;
   int size=ArraySize(Canvas.m_pixels);
   for(int i=0; i<size;i++)
     {
      pix1.clr=arr1[i];
      pix2.clr=arr2[i];
      pix.c[0]=pix1.c[0]+(uchar)Round(((int)pix2.c[0]-(int)pix1.c[0])*p);
      pix.c[1]=pix1.c[1]+(uchar)Round(((int)pix2.c[1]-(int)pix1.c[1])*p);
      pix.c[2]=pix1.c[2]+(uchar)Round(((int)pix2.c[2]-(int)pix1.c[2])*p);
      pix.c[3]=255;
      C.m_pixels[i]=pix.clr;
     }
  }
//+------------------------------------------------------------------+
Please do not write comments like: how it affects trading? How can it be useful? etc.
Such comments in the branch, which demonstrates the capabilities of Kanvas, I personally, at least, will be perceived as a manifestation of unprofessionalism.
Files:
Morph.ZIP  738 kb
 
Nikolai Semko:
Such comments in a thread where kanvas capabilities are demonstrated, personally, at the very least, would be perceived by me as a manifestation of unprofessionalism.

LOL

I, as a layman, can only confirm that it looks great, but I don't know where to apply it all. Let's join Peter Konov's club.

 
Nikolai Semko:

Demonstration of a simple bmp raster image morphing.

Please don't write comments like: how does this affect trading? how can it be useful? etc.
This kind of comments in a branch that demonstrates the capabilities of Kanvas, I personally, at the very least, will be perceived as a manifestation of unprofessionalism.

No, that's not morphing. Morphing is a stretch to call it morphing:


In general, I was too lazy to make a real one myself - I found examples in the folders.

 
Artyom Trishkin:

No, that's not morphing. It's a stretch to call it morphing:


Actually, I was too lazy to make a real one myself - I found it in the example folders.

Where's the morphing here? Of course, in this case, it's not crucial for our purposes, but still. Wiki definition of morphing:

Morphingis a technology in computer animation, a visual effect that creates the impression of a smooth transformation of one object into another.

Still, the first example is more like this effect, imho.

 
Andrei Novichkov:

Where's the morphing here? Of course, it's not crucial for our purposes here, but still. Wiki definition of morphing:

Morphingis a technology in computer animation, a visual effect which creates the impression of smooth transformation of one object into another.

The first example is more similar to this effect, imho.

Where in the first example of a smooth transformation? In the second one, everything is transformed completely smoothly in each frame from one form to another (morphing). And in the first one, it's just a change of images with fading and blurring. I wanted to do face morphing from human into some kind of beast, but I didn't want to waste my time. I, who used to work in TV, and made commercials in 3D Studio MAX, shouldn't know about morphing :)

 

And I know how to work in Max too )))) And not only in it )) And I've worked with television too. One of the documentaries I did a splash screen for won an award not long ago ).

Of course, it would be naive to consider the first example as morphing in the full sense of the word. But Artem, ruffling a girl's skirt isn't exactly the same thing. Not pre-morphing ) If only her skirt were to turn into an elephant, that would be different )))))).

 
Andrei Novichkov:

And I know how to work in Max too )))) And not only in it )) And I've worked with television too. One of the documentaries I did a screenplay for won an award not so long ago))

Of course, it would be naive to consider the first example as morphing in the full sense of the word. But Artem, ruffling a girl's skirt isn't exactly the same thing. Not pre-morphing ) If only her skirt were to turn into mmmmm an elephant, that would be another matter )))))).

:)

That's what I said, a bit of a stretch. But I wasn't talking about the skirt, where rippling is probably already pre-calculated (I wasn't looking), but about the dummy itself - you can make it move in different ways, including with the "Morphing" modifier, which would be just morphing. But they probably move the biped - I don't know, I didn't look.

 
Artyom Trishkin:

:)

That's what I said, a bit of a stretch. But I wasn't talking about the skirt, where the wobble is probably already pre-calculated (I wasn't looking), but about the dummy itself - you can make it move in different ways, including with the "Morphing" modifier, which would be just morphing. But they probably move the biped - I don't know, I didn't look.

I don't think it's Max at all. How's that clothing modelling software?

The model's movements are good, the way she walks. Maybe it's just a girl covered in sensors. But the movements of arms, it seems to me, not finished and it turned out as if the bodybuilder goes to push off a mobile)).

The model itself could be a bit better looking. This is some kind of cannibal from "Call of Cthulhu".

Loud and clear )))). We should probably wrap this up.