The function of decomposing color into shades. - page 9

 
Nikolai Semko:

Peter, the issue is that you have posted a function on the forum for all to see and apply colour decomposition. But this function does not generate the necessary color array, but only a string array, which is only good for Print output, instead of demonstrating your gradient on the screen. It is a pig in a poke and no respect for others. You may translate it yourselves if you want.

This is already an outright libel and slander. I deliberately chose string type, to make it easier to see the components and to isolate them. I explained my solution technique in detail on the first page. You haven't explained anything. I'm not sure you yourself fully understand how your method of colour decomposition works. If you don't, explain it in as much detail as I did.

And do not make such loud accusations. You may slip up on them yourself.

 
And don't get into an argument. Let's get to the bottom of this.
 
Реter Konow:

This is outright slander and slander. I chose the type of string deliberately, in order to make it easier to see the components and pick them out. I explained in detail the technique of my solution on the first page. You have not explained anything. I'm not sure you yourself fully understand how your colour decomposition method works. If you don't, explain it in as much detail as I did.

And don't make such loud accusations. You might slip up on them yourself.

Sorry - I've only just read your explanation:

  • First, I decomposed the colour into three main components, defining senior, middle, junior.
  • Then, I started making graphs and drawing lines through the component values.
  • As I watched the numbers change in the palette as I dragged the slider, I realized that there was a refraction in the angle of ascent of the lines, because at some point the rate of change of the numbers changed.
  • I placed the refraction axis of the lines in the centre of the graph, and saw that each line, consists of two segments, each with its own ascension angle.
  • Also, by experimenting with the colour palette, I realised that there is a maximum angle of ascent for the higher component. At first I thought it was 67.5 degrees. However, practice showed that it is 63.5 degrees.
  • For a long time, I could not figure out how to correctly plot the line segments of the colour components. There were many unknowns. But the main thing - how to find the coordinate of the original colour on the graph?
  • As I continued to experiment with the palette, I noticed that by changing the value of the colour by a certain number, the slider moved by a certain distance. Gradually, I realized that the distance the slider moves is half the value of the low-order component.
  • I assumed that if I found the coordinate of the higher component in the line of maximum ascent angle and added half of the lower component to that point, I would find the coordinate of the original colour in the plot. Practice has proved, that the assumption was correct.
  • Having a co-ordinate of initial colour and an axis of refraction, I could calculate angles of each of pieces and receive values for each component along its line. I used high school trigonometry for that.

I can't do that. It's more prosaic and primitive.
It is difficult to explain more capaciously than the code itself:

void Gradient(uint clr,uint &arr[],uint size)
  {
   if(size==0) return;
   ArrayResize(arr,size);
   rgb c;
   c.clr=clr;
   uchar R=c.c[2],G=c.c[1],B=c.c[0];
   uint i=0, tone=uint((size-1)*(((double)R+(double)G+(double)B)/765.0)+0.4999);
   double kR,kG,kB;
   if(tone!=0)
     {
      kR=(double)R/tone; 
      kG=(double)G/tone;
      kB=(double)B/tone;
      for(i=0;i<=tone;i++)
        {
         c.c[2]=uchar(i*kR+0.4999);
         c.c[1]=uchar(i*kG+0.4999);
         c.c[0]=uchar(i*kB+0.4999);
         arr[i]=c.clr;
        }
     }
   if(tone!=(size-1))
     {
      kR=(double)(255-R)/(size-i);
      kG=(double)(255-G)/(size-i);
      kB=(double)(255-B)/(size-i);
      for(uint j=1;i<size;i++,j++)
        {
         c.c[2]=uchar(R+j*kR+0.4999);
         c.c[1]=uchar(G+j*kG+0.4999);
         c.c[0]=uchar(B+j*kB+0.4999);
         arr[i]=c.clr;
        }
     }
  }
 
Nikolai Semko:


One more time:

  • Take my algorithm as I created it. Without your corrections.
  • Set your colour. Run the script on MT4.
  • You'll get all the colours through the alert.
  • Enter the original colour into the Windows palette.
  • Check the match.

This is the best check that the algorithm is working correctly.

Then, you can move on to a speed check.

You, on the other hand, took my algorithm, changed the lines in it as you saw fit, then ran it on a different platform and displayed it according to your drawing technique. Having made so many independent changes, you judge my algorithm as if you don't notice how you yourself changed it and put it in different conditions. Conditions where you yourself might have an error. So, let's calmly find out.

 
Реter Konow:

One more time:

  • Take my algorithm as I created it. Without your corrections.
  • Set your colour. Run the script on MT4.
  • You'll get all the colours through the alert.
  • Enter the original colour into the Windows palette.
  • Check the match.

This is the best check that the algorithm is working correctly.

Then, you can move on to a speed check.

You, on the other hand, took my algorithm, changed the lines in it as you saw fit, then ran it on a different platform and displayed it according to your drawing technique. Having made so many independent changes, you judge my algorithm as if you don't notice how you yourself changed it and put it in different conditions. Conditions where you yourself might have an error. So, let's find out calmly.

Peter, I don't need 256 combinations of three digits in my alert. I need colour. All I did in your function was to convert colour to uint, as it should be. I did not get into your algorithm, because its logic is beyond my comprehension.

 
Nikolai Semko:

Peter, I don't want 256 combinations of three digits of colour in the alert. I need colour. All I did in your function was to convert colour to uint instead of string, as it should be. I haven't got into your algorithm, as its logic is beyond my comprehension.

Checking by numbers is the best. You cannot compare colour shades by eye. Monitors are different and perception can be different. That is why figures are the best check.

And there's no inordinate logic involved. School trigonometry.

1. Calculate the angles of six segments.

2. Then, calculate the values at each point of these segments and write them into an array.

That's it.

 
Реter Konow:

Checking by the numbers is the best. You can't exactly compare colour shades by eye. Monitors are different and perception can be different. That's why numbers are the best check.

And there's no inordinate logic involved. School trigonometry.

1. Calculate the angles of six segments.

2. Then, calculate the values at each point of these segments and write them into an array.

That's it.

But in fact, my function works without glitches and is 4 times faster. I'm waiting for your result when you provide your algorithm on 5. It took me a while just copying via clipboard, and you took something longer.

 
Nikolai Semko:

But in fact my function works without glitches and is 4 times faster. I'm waiting for your result, when you provide your algorithm on 5. It took me a while to simply copy through the clipboard, and you took something longer.

Nikolai, that sounds like kindergarten. The statement "4 times faster" is invalid because it's not proven.


  1. Comment out the line in your version of my solution on MT5 and you will see the difference.

canvas.TextOut(300,10,"Время формирования градиентного массива из 256 элементов = "+string(t)+" микросекунд",ColorToARGB(clrWhite));

This line affects the drawing of the whole rectangle for some reason. But it's not my glitch. Check it out.

Continuing to look into those glitches you've got. I want to see if it's really because of my algorithm.


And turn off the unnecessary flickering of numbers. Take out all the unnecessary stuff. Let a simple rectangle with a gradient of one original colour be displayed once. Without any unnecessary gimmicks.

 
Generally speaking, the function to get an array of gradients between two colours is more useful. As it is simpler and more useful in practice.
void Gradient(uint clr1,uint clr2,uint &arr[],uint size)
  {
   if(size==0) return;
   ArrayResize(arr,size);
   rgb c1,c2;
   c1.clr=clr1;
   c2.clr=clr2;
   double R1=c1.c[2],G1=c1.c[1],B1=c1.c[0];
   double R2=c2.c[2],G2=c2.c[1],B2=c2.c[0];
   double deltaR=(R2-R1)/(size-1);
   double deltaG=(G2-G1)/(size-1);
   double deltaB=(B2-B1)/(size-1);
   for(uint i=0;i<size;i++)
     {
      R1+=deltaR; c1.c[2]=uchar (R1+0.4999);
      G1+=deltaG; c1.c[1]=uchar (G1+0.4999);
      B1+=deltaB; c1.c[0]=uchar (B1+0.4999);
      arr[i]=c1.clr;
     }
  }

If you need a gradient of one colour to white or to black, you can get them that way with this function.

   color clr=clrViolet;
   uint CLR[];
   Gradient(clrWhite, clr, CLR,100); // получаем массив из 100 элементов градиента от белого цвета до цвета clr 
   Gradient(clr, clrBlack, CLR,100); // получаем массив из 100 элементов градиента от цвета clr до черног цвета  


Files:
 
Реter Konow:

Checking by the numbers is the best. You can't exactly compare colour shades by eye. Monitors are different and perception can be different. That's why numbers are the best check.

I'll join in the "accusations", couldn't take it :)

A good example of how not to program. If this is how your entire GUI is written, we won't see it for a long time. :(

Every line is a "masterpiece": such a pile of errors and bloopers, so much hope that mql4 will work out. I now understand why mt4 is being used.

I think that publishing of such codes and the subsequent reaction to criticism is not respecting the forum audience. They don't want to do you harm, they want to help you.

As for comparing algorithms, you can compare them visually. It's not like you offered proof in numbers that your algorithm gives shades 99% close to "windows shades".

On the left is sort of your approach, on the right isNikolai Semko's. (A modifiedNikolai Semko script was used)


Files: