The function of decomposing color into shades. - page 2

 
Alexey Viktorov:

For CodeBade you should definitely write in an international language. But why insist on it in Russian-language forum???

Personally, I'm disgusted by this international... because I don't know it at all and it's much clearer to me than our native Russian.

The main problem with this code is that Cyrillic is not supported when debugging.


and also Alt+G does not work (go to variable definition).


 
And the component word is masculine.
 
Алексей Тарабанов:
And the component word is masculine.

And the component word is feminine.

 
HSL
HSL — Википедия
HSL — Википедия
  • ru.wikipedia.org
HSL, HLS или HSI (от англ.  ()) — цветовая модель, в которой цветовыми координатами являются тон, насыщенность и светлота. Следует отметить, что HSV и HSL — две разные цветовые модели (lightness — светлота, что отличается от яркости). L = 1 2 ( M A X + M I N ) {\displaystyle L={\begin{matrix}{\frac...
 

Реter Konow
:

It's also very interesting how this problem is solved with the CCanvas class. How can you get all the shades of the original colour through it?

#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164 union rgb {uint clr; uchar c[4];}; void OnStart()   {    rgb c,cc;    double d=5;    while(!IsStopped())      {       c.c[2]=uchar(127.5*(1+sin(d*1.2))+0.4999); c.c[1]=uchar(127.5*(1+sin(d*1.9))+0.4999); c.c[0]=uchar(127.5*(1+sin(d*2.8))+0.4999); // генерируем новый цвет       cc.clr=c.clr;       double k0,k1,k2;       if(c.c[2]>=c.c[1] && c.c[2]>=c.c[0]) {k2=1; if(c.c[2]==0) {k1=1; k0=1;} else {k1=(double)c.c[1]/c.c[2]; k0=(double)c.c[0]/c.c[2];}}// если Red - максимальный цвет       else if(c.c[1]>=c.c[2] && c.c[1]>=c.c[0]) {k1=1; k2=(double)c.c[2]/c.c[1]; k0=(double)c.c[0]/c.c[1];} // если Green - максимальный цвет       else {k0=1; k2=(double)c.c[2]/c.c[0]; k1=(double)c.c[1]/c.c[0];} // если Blue - максимальный цвет       for(int y=0; y<W.Height; y++)         {          double k=255.0*(double)y/(W.Height-1);          c.c[2]=uchar(k2*k+0.4999);          c.c[1]=uchar(k1*k+0.4999);          c.c[0]=uchar(k0*k+0.4999);          Canvas.LineHorizontal(0,W.Width-1,y,ColorToARGB(c.clr,240));         }       Canvas.FillRectangle(W.Width/2-80,W.Height/2-50,W.Width/2+80,W.Height/2+50,ColorToARGB(cc.clr,240));       Canvas.CurentFont("Tahoma",20,22,ColorToARGB(~cc.clr)); // 20 -  размер шрифта, 22 - межстрочный интервал       Canvas.TextPosition(W.Width/2-70,W.Height/2-40);       Canvas.Comm("Текущий цвет:");       Canvas.Comm("R = "+string(cc.c[2]));       Canvas.Comm("G = "+string(cc.c[1]));       Canvas.Comm("B = "+string(cc.c[0]));       ChartChanged(); // на всякий случай контролируем изменение размеров окна, т.к. это скрипт (в индикаторах и экспертах это происходит автоматически)       Canvas.Update();       d+=0.01;       Sleep(30);      } }

The gradient calculation is highlighted, the rest is the output.


Files:
Gradient.mq5  4 kb
 
Nikolai Semko:

The main problem with such code is that Cyrillic is not supported when debugging.

..

and also Alt+G does not work (go to variable definition).

Ha !

This is a very serious drawback of this "Russian" code !

Peter, how do you debug your code? How do you look at the values of certain "russian-speaking" variables?

* * *

As correctly pointed out above - there are HSL and HLS systems, which have long been standardized, and transfers from RGB are made using standard formulas. Besides, there is the Lab system. What's the point of re-inventing the wheel ?

It is not quite clear to me where these functions can be applied. This is a very common mistake of local programmers - they write very interesting programs, but with demonstration of the application - hit a snag. Six months ago, I remember, a class of work with Canvas was presented - there was a very impressive demo. But I haven't seen any use for these features, the author promised to demonstrate them but never did.

I have an impression, that most of these demos are created to amuse one's ego - "look how I can do it". I'm sure it's a good thing... but for most people it's useless, because most people are interested in application, but there's a problem with application.

A lot of people write small useful attachments. But, so far, I see that only fxsaber has presented a library which I think is very useful for literally everyone. I don't know of such a voluminous, yet generally useful work. In this case, with Canvas, it's even sadder - I can't imagine where it all could be applied in a way that would be useful for any discernible part of the forum audience.

I'd like to see concrete examples of applications, even without revealing the source code - just the idea of where it all could be usefully applied ?

 
Nikolai Semko:

The main problem with this code is that Cyrillic is not supported when debugging.


and also Alt+G does not work (go to variable definition).

The problem, Nikolai, is not the code or the debugger, the problem is the people, the relationships. If I am interested in this code, I will replace variable names without much effort and debugging will work. But to demand to use an international one where foreigners don't know our great language... And demanding not to download and test this code...

 
Georgiy Merts:

Ha !

This is a very serious drawback of this "Russian" code !

Peter, how do you debug your code? How do you view the values of specific "Russian-speaking" variables?

* * *

As correctly pointed out above - there are HSL and HLS systems, which have long been standardized, and transitions from RGB are made using standard formulas. Besides, there is a Lab system. What's the point of re-inventing the wheel ?

It is not quite clear to me where these functions can be applied. This is a very common mistake of local programmers - they write very interesting programs, but with demonstration of the application - hit a snag. Six months ago, I remember, a class of work with Canvas was presented - there was a very impressive demo. But I haven't seen any use for these features, the author promised to demonstrate them but never did.

I have an impression, that most of these demos are created to amuse one's ego - "look how I can do it". I'm sure it's a good thing... but for most people it's useless, because most people are interested in application, but there's a problem with application.

A lot of people write small useful attachments. But, so far, I see that only fxsaber has presented a library which I think is very useful for literally everyone. I don't know of such a voluminous, yet generally useful work. In this case, with Canvas, it's even sadder - I can't imagine where it all could be applied in a way that would be useful to any discernible part of the forum.

I'd like to see concrete examples of applications, even without revealing the source code - just the idea of where it all could be usefully applied ?

George, I'm debugging the code in my head. :) I've always done it that way. I look for errors logically. Alert() function helps me a lot;

For me it's always necessary to look for one's own solution. I don't mind the MetaEditor's lack of debugging. I have adapted to it and found my own methods of error detection. But in a global development to use only another's (albeit very clear) language is a real barrier. If you were a global developer on your own, you would understand me. The Russian language helps me to squeeze the maximum productivity out of my own brain. In fact, I program in two languages. 60% Russian and 40% English. Bilingual code is much more memorable than monolingual code. It's also better readable. Looking only at the English code (with a lot of syntax) you cannot remember much and cannot program much. That's why everybody uses libraries. I, on the other hand, can memorize my program easily, because I care about my own ease of reading and memorizing, rather than adhering to someone else's invented standards. This is why I have done so much on my own.

Applying graphics to trading programmes will make them more attractive to sell on the Marketplace. You have to take care of that too. That is the practical application.


In general, tables, controlling programme behaviour, setting up automatics, outputting information - that's what graphics are for. It's strange that you think that trading programs don't need it.

 
Nikolai Semko:

The marker is highlighted as far as the gradient calculation is concerned, the rest is output on the screen.


Thank you, Nikolai. Is it possible to send a colour and get all shades at once? Is there such a method?

 
Nikolai Semko:

The marker is highlighted for the gradient calculation, the rest of the output is on the screen.


By the way, judging from the picture, the colour decomposition here is not complete. Only half of it. The range should extend from absolute white to absolute black, through all the shades of a particular colour.