# How do I cycle/lerp between multiple colors

**URL:** https://discourse.processing.org/t/how-do-i-cycle-lerp-between-multiple-colors/13441
**Category:** Coding Questions
**Created:** [August 17, 2019, 8:34pm UTC](https://discourse.processing.org/t/how-do-i-cycle-lerp-between-multiple-colors/13441 "2019-08-17T20:34:31Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [August 18, 2019, 5:43am UTC](https://discourse.processing.org/t/how-do-i-cycle-lerp-between-multiple-colors/13441/5 "2019-08-18T05:43:54Z")

</div>

For a quick, off-the-shelf multicolor extension to lerpColor, define a function lerpColors:

```auto
color lerpColors(float amt, color... colors) {
  if(colors.length==1){ return colors[0]; }
  float cunit = 1.0/(colors.length-1);
  return lerpColor(colors[floor(amt / cunit)], colors[ceil(amt / cunit)], amt%cunit/cunit);
}

```

Examples of how to use this function:

- [https://forum.processing.org/two/discussion/comment/92946/#Comment\_92946](https://forum.processing.org/two/discussion/comment/92946/#Comment_92946)

Many past discussions:

- [https://discourse.processing.org/search?q=lerpColors](https://discourse.processing.org/search?q=lerpColors)

---

_[View the full topic](https://discourse.processing.org/t/how-do-i-cycle-lerp-between-multiple-colors/13441)._
