|  | 
|  | 1 | +[](https://jitpack.io/#micycle1/PeasyGradients) | 
|  | 2 | + [](https://sonarcloud.io/summary/new_code?id=micycle1_PeasyGradients) | 
|  | 3 | + | 
| 1 | 4 | <h1 align="center"> | 
| 2 | 5 |   <a href="https://github.com/micycle1/PeasyGradients"> | 
| 3 | 6 |   <img src="resources/logo/Banner-2.png" alt="PeasyGradients"/></a> | 
| 4 | 7 | </h1> | 
| 5 | 8 | 
 | 
| 6 |  | -[](https://jitpack.io/#micycle1/PeasyGradients) | 
| 7 |  | - [](https://sonarcloud.io/summary/new_code?id=micycle1_PeasyGradients) | 
| 8 |  | - | 
| 9 |  | - | 
| 10 | 9 | # PeasyGradients | 
| 11 | 10 | A Processing library for creating and rendering color gradients. | 
| 12 | 11 | 
 | 
| @@ -94,56 +93,92 @@ _Zoom and rotation can be adjusted for most gradient types; certain gradient typ | 
| 94 | 93 | _For many of the gradient types, there are multiple methods available to call, offering varying degrees of customisation of the gradient's spectrum shape._ | 
| 95 | 94 | 
 | 
| 96 | 95 | 
 | 
| 97 |  | -## Interpolation: Easing Functions | 
| 98 |  | -In the parts of a `Gradient` between color stops, colors are composed via interpolating the neighbouring two color stops. Easing functions affect how these two adjacent stops contribute to the color of each point between them. | 
|  | 96 | +## Color Interpolation | 
| 99 | 97 | 
 | 
| 100 |  | -For example, with *linear* interpolation, a point in a `Gradient` which is midway between 2 color stops is composed of 50% of the first color and 50% of the second color — there is a linear relationship between its position and the weighting of color it receives from each color stop. Other easing functions are non-linear (for example a point closer to one color stop may in some cases receive more color from the second color stop) which can result in more interesting gradients. | 
| 101 |  | -  | 
| 102 |  | -Certain easing functions suit some gradient types better than others — for example, the `BOUNCE` function works well with polygon gradients but rather more poorly with linear gradients. Therefore, and as with color spaces, experimentation with different interpolation functions is encouraged. | 
|  | 98 | +In 1D gradients, colors between stops are calculated by interpolating between adjacent stop colors. The interpolation/easing function controls how colors blend: | 
| 103 | 99 | 
 | 
| 104 |  | -Set the interpolation (easing) function for a given `Gradient` with `.setInterpolationMode()`, like so: | 
|  | 100 | +- **Linear**: Colors blend evenly based on position (50% position = 50% of each color) | 
|  | 101 | +- **Non-linear**: Colors blend with varying weights, creating more dynamic transitions | 
| 105 | 102 | 
 | 
|  | 103 | +```java | 
|  | 104 | +// Set interpolation mode | 
|  | 105 | +gradient.setInterpolationMode(Interpolation.SMOOTH_STEP); | 
| 106 | 106 | ``` | 
| 107 |  | -myGradient.setInterpolationMode(Interpolation.SMOOTH_STEP); | 
| 108 |  | -``` | 
| 109 |  | - | 
| 110 |  | -See for a comparison of all available easing functions modes in expandable section below: | 
| 111 |  | - | 
| 112 |  | -| **Linear** | **Identity** | **Smooth Step** | **Smoother Step** | | 
| 113 |  | -|:---:|:---:|:---:|:---:| | 
| 114 |  | -| **Exponential** | **Cubic** | **Circular** | **Bounce** | | 
| 115 |  | -| **Sine** | **Parabola** | **Gain 1** | **Gain 2** | | 
| 116 |  | -| **Exponential Impulse** | **Heartbeat** | | | | 
| 117 |  | - | 
| 118 |  | -<details><summary style="font-size:135%; color:blue">💥See Interpolation Comparison...</summary> | 
| 119 | 107 | 
 | 
| 120 |  | -| **Linear** | **Identity** | | 
| 121 |  | -|:---:|:--:| | 
| 122 |  | -| **Smooth Step** | **Smoother Step** | | 
| 123 |  | -| **Exponential** | **Cubic** | | 
| 124 |  | -| **Circular** | **Bounce** | | 
| 125 |  | -| **Sine** | **Parabola** | | 
| 126 |  | -| **Gain 1** | **Gain 2** | | 
| 127 |  | -| **Exponential Impulse** | **Heartbeat** | 
|  | 108 | +Different interpolation modes suit different rendering patterns. For example, `BOUNCE` works well with polygon gradients but can appear jarring in linear gradients. Experiment with different modes to achieve desired effects. | 
|  | 109 | + | 
|  | 110 | +Here's a comparison between all available interpolation modes: | 
|  | 111 | + | 
|  | 112 | +<table> | 
|  | 113 | +  <tr> | 
|  | 114 | +    <td align="center" valign="center"><b>Linear</b></td> | 
|  | 115 | +    <td align="center" valign="center"><b>Identity</b></td> | 
|  | 116 | +    <td align="center" valign="center"><b>Smooth Step</b></td> | 
|  | 117 | +    <td align="center" valign="center"><b>Smoother Step</b></td> | 
|  | 118 | +  </tr> | 
|  | 119 | +  <tr> | 
|  | 120 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/linear.png"></td> | 
|  | 121 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/identity.png"></td> | 
|  | 122 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/smooth_step.png"></td> | 
|  | 123 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/smoother_step.png"></td> | 
|  | 124 | +  </tr> | 
|  | 125 | +  <tr> | 
|  | 126 | +    <td align="center" valign="center"><b>Exponential</b></td> | 
|  | 127 | +    <td align="center" valign="center"><b>Cubic</b></td> | 
|  | 128 | +    <td align="center" valign="center"><b>Circular</b></td> | 
|  | 129 | +    <td align="center" valign="center"><b>Bounce</b></td> | 
|  | 130 | +  </tr> | 
|  | 131 | +  <tr> | 
|  | 132 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/exponential.png"></td> | 
|  | 133 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/cubic.png"></td> | 
|  | 134 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/circular.png"></td> | 
|  | 135 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/bounce.png"></td> | 
|  | 136 | +  </tr> | 
|  | 137 | +  <tr> | 
|  | 138 | +    <td align="center" valign="center"><b>Sine</b></td> | 
|  | 139 | +    <td align="center" valign="center"><b>Parabola</b></td> | 
|  | 140 | +    <td align="center" valign="center"><b>Gain 1</b></td> | 
|  | 141 | +    <td align="center" valign="center"><b>Gain 2</b></td> | 
|  | 142 | +  </tr> | 
|  | 143 | +  <tr> | 
|  | 144 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/sine.png"></td> | 
|  | 145 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/parabola.png"></td> | 
|  | 146 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/gain1.png"></td> | 
|  | 147 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/gain2.png"></td> | 
|  | 148 | +  </tr> | 
|  | 149 | +  <tr> | 
|  | 150 | +    <td align="center" valign="center"><b>Exponential Impulse</b></td> | 
|  | 151 | +    <td align="center" valign="center"><b>Heartbeat</b></td> | 
|  | 152 | +    <td align="center" valign="center"></td> | 
|  | 153 | +    <td align="center" valign="center"></td> | 
|  | 154 | +  </tr> | 
|  | 155 | +  <tr> | 
|  | 156 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/expimpulse.png"></td> | 
|  | 157 | +    <td valign="top" width="25%"><img src="resources/interpolation_examples/heartbeat.png"></td> | 
|  | 158 | +    <td valign="top" width="25%"></td> | 
|  | 159 | +    <td valign="top" width="25%"></td> | 
|  | 160 | +  </tr> | 
|  | 161 | +</table> | 
| 128 | 162 | 
 | 
| 129 | 163 | </details> | 
| 130 | 164 | 
 | 
| 131 | 165 | ## Color Spaces | 
| 132 | 166 | 
 | 
| 133 |  | -Color spaces define how the color value at each color stop is represented. | 
|  | 167 | +Color space determines how colors are numerically represented, and this affects how colors blend during interpolation. Different color spaces can produce noticeably different gradients even with the same color stops. | 
| 134 | 168 | 
 | 
| 135 |  | -Remember that a 1D `Gradient` consists of only a few defined color stops; all other colors in a `Gradient`'s spectrum are **composed** by **interpolating** between any two adjacent color stops. Representing color stops differently (in different color spaces) affects the results of interpolation, and this can have a noticeable effect on the overall spectrum of a gradient (so experimentation with different color spaces is encouraged). A rule of thumb: avoid the `RGB`, `RYB` and `HSB` color spaces as they don't interpolate luminosity well. | 
|  | 169 | +<b> main comparison is perceptually uniform vs not!</b> | 
|  | 170 | +  ideally uniform hue perception and  | 
| 136 | 171 | 
 | 
|  | 172 | +  A smooth transition using a model designed to mimic human perception of color. The blending is done so that the perceived brightness and color varies smoothly and evenly. | 
| 137 | 173 | 
 | 
| 138 |  | - Set the color space for a given `Gradient` with `.setColorSpace()`, like so: | 
| 139 |  | -  | 
| 140 |  | - ``` | 
| 141 |  | - myGradient.setColorSpace(ColorSpace.RGB); | 
| 142 |  | - ``` | 
| 143 | 174 | 
 | 
| 144 |  | - PeasyGradients supports many different color spaces — all possible color spaces are accessible via `ColorSpace.class` and examples of each are shown in the expandable section below: | 
|  | 175 | +```java | 
|  | 176 | +gradient.setColorSpace(ColorSpace.LAB);  // Perceptually uniform blending | 
|  | 177 | +``` | 
|  | 178 | + | 
|  | 179 | +For smooth, perceptually uniform gradients, prefer spaces like `OKLAB`, `ITP`, or `K_MUNK` over `RGB`, `RYB`, or `HSB`. This is because the latter don't maintain consistent perceived brightness during interpolation. | 
| 145 | 180 | 
 | 
| 146 |  | -<details><summary style="font-size:135%; color:blue">💥See Color Space Comparison...</summary> | 
|  | 181 | +All available spaces are accessible via `ColorSpace.class` and demonstration of each are shown in the expandable section below: | 
| 147 | 182 | 
 | 
| 148 | 183 | *Note that with the chosen gradient, the spectrum differences aren't too apparent between many of the colorspaces in the images below. Other gradients (i.e. using different colors) may exhibit more substantial differences between the different colorspaces.* | 
| 149 | 184 | 
 | 
|  | 
0 commit comments