About | Details | Instructions
A training project in which you can
- check the contrast of colours
- choose a palette of colours
- get colours from an image (it might take quite a time)
- React
- React-router-dom
Here are several algorithms that translate colour from one system to another.
For every algorithm:
For each colour we translate hex value to rgb, where each parameter must be
Calculate Max and Min value in a R’G’B’:
Then calculate the delta:
To calculate the Hue:
To calculate the Saturation:
To calculate the Lightness:
Calculate the black colour:
Calculate the cyan colour:
Calculate the magenda colour:
Calculate the yellow colour:
Using FileReader we get information about the image file. To be precise, it is an array of all pixels containing information about the image. So, this is RGBA (rgb + alpha channel).
For example, if we have an image with parameters
When we get the RGB array (in this case), we need to process it. So, without a server that could probably check every value, we will check some of them using the median cut algorithm.
- Determine the maximum depth, for example 8;
- Using the biggestColourRange method, we get the largest range of colour channels (red, green or blue);
- Using recursion we will sort the array by its channel (red, green or blue);
- Divide the array in half;
- Repeat this (2-4 steps) until we reach our maximum depth;
- As a result we will get something like 256 arrays (because of the depth = 8,
$\ 2^8=256$ ); - For each array we will calculate the average rgb value for each channel.
It is based on two colours: text colour and background colour.
This is the ratio of the luminosity of one colour to another:
Where L1 is lightest and L2 is darkest.
For each colour we translate hex value to rgb, where each parameter must be
And the luminance for each colour for each channel:
Where
Now we can calculate Luminocity:
[More info] (Link to w3)
Each colour consists of three channels: red, green and blue.
- Tints is when we add white colour
- Shades is when we add black colour
- Tones is when we add gray colour
In case of Tints and Shades we need to calculate factor.
In this case, the factor (in this example I took simpler numbers to simplify the calculation) is:
For each factor we will calculate the new colour:
For each factor we will calculate the new colour:
The basic idea here is that we have a range for each channel from 0 to 256. To get a range of tones, we need to add a gray colour to it.
So we divide our range in half (256/2=128).
We took each channel from this number (
And I will add this number to the current channel. So every new colour is based on previous one.
For example:
For the colour #80E380 RGB will be $\ [128,227,128] $ (<- Our start colour ).
Then we took 128 from each channel and divide into len (7 in our case):
And Add it to our current Colour (and change it to new one):
$$[R,G, B]= \begin{cases} R+R'=128\\ G+G'=213\\ B+B'=128\\ \end{cases}\\$$And the formula is:
Where
Desctiption | Command |
---|---|
Installing all the necessary dependencies | npm install |
Running the app in the development mode | npm run dev |