How to find all the colors between two colors?

前端 未结 5 2027
时光说笑
时光说笑 2021-01-16 12:26

I need to pick two colors, then find X colors (or tones) between them, each one separated with the same \'distance\' of the other.

I still don\'t understand how colo

5条回答
  •  难免孤独
    2021-01-16 13:04

    The simplest thing to do is to take the RGB values of the first and the second color and interpolate them together ie.

    $b1 = $color1['blue'];
    $b2 = $color2['blue'];
    
    for($i=0; $i<$X; $i++){
        $b = round($b1 + (1.0 * ($b2 - $b1) * $i / $X));
        // Do the same for the red / green values
    }
    

    EDIT: You can also use the HSV value instead of the RGB value

提交回复
热议问题