I
I
Ilyusha Prokopiev2015-10-22 19:48:52
JavaScript
Ilyusha Prokopiev, 2015-10-22 19:48:52

Who can help with the final touch in creating an html color generator?

The generator consists of two blocks. The first is the choice of the main color, it has a height of 255 pixels, and itself is a set of gradients, the user can choose any color. The colors on it change as follows. First the gradient is from #ff0000 to #ff00ff, then red goes down to 00, then green goes up, then blue goes down, and so on until all the options have been iterated. There are 6 options in total - the first block is divided into 6 parts. The second block is a square of 255*255 pixels. In the upper right corner, the color selected by the user on the first block, the upper left corner is white, the lower pixels are black.
I wrote a code to get the color code. one of the colors is determined simply by the vertical position of the second block pointer (I removed it from the code). ll - horizontal position of the pointer in the second block, lt - vertical. score_2 - in which part of the first block the pointer is located (Since we have broken the first block into 6 parts).

var color2 = 255 / (255 - ll);
var color2 = lt / color2;
var color2 = Math.round((255 - ll) - color2).toFixed(0);
var color3 = 255 / (255 - score_2);
var color3 = (255 - ll) / color3;
var color31 = 255 - Math.round(255 - score_2 - color3).toFixed(0);
var color3 = 255 / color31;
var color3 = lt / color3;
var color3 = Math.round(color31 - color3).toFixed(0);

And this code works perfectly. But the code works with jambs, to which you give the code, and in response it changes the position of the pointers. It works like this: if you know in which 1/6th the pointer of the first block is located, then you can find out which color (red, blue, green) is the largest and which is the smallest (the same can be used in the opposite direction - the idea is based on this code). The largest color in the upper right corner is 255, the smallest is 0. pt is the vertical position of the second pointer, pl is horizontal, rtf is the position of the first pointer, sh is where the first pointer should be, zero is the smallest color, nzero is medium, h is the largest color.
var pt = 255 - h; 
var pl1 = 255 - pt;
var pl = 255 / pl1;
var pl2 = pl1 - zero;
var pl = pl2 * pl;
var rt = (255 - pt) / nzero;
var rt = pt / rt;
var rt1 = nzero + rt;
var rt = pl / (255 - rt1);
var rt = (255 - pl) / rt;
var rt = Math.round(rt1 + rt).toFixed(0);
if(sh % 2 == 0){
    var rt = 255 - rt;
}

So this code works every other time, but more often it works incorrectly. If anyone can figure it out, please help, because the ideas have long run out

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question