# Simple 2 color wipe

**URL:** <https://forum.electromage.com/t/simple-2-color-wipe/792>\
**Category:** Patterns and Code\
**Created:** [December 5, 2020, 2:48am UTC](https://forum.electromage.com/t/simple-2-color-wipe/792 "2020-12-05T02:48:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jeff](https://forum.electromage.com/user_avatar/forum.electromage.com/jeff/32/3473_2.png) [@jeff](https://forum.electromage.com/u/jeff)\
**Post date:** [December 5, 2020, 9:44am UTC](https://forum.electromage.com/t/simple-2-color-wipe/792/2 "2020-12-05T09:44:43Z")

</div>

Hey @jpm!

I really appreciate how you contributed the 3D printable open PB mount, so I made you a video explaining how you might think about designing it (and working code below).

[![](https://img.youtube.com/vi/P30WYpHSbEk/maxresdefault.jpg "Coding a basic color wipe on Pixelblaze") ](https://www.youtube.com/watch?v=P30WYpHSbEk)

Square wave approach:

```javascript
export function beforeRender(delta) {
  t1 = time(2 / 65.536) // 2 seconds to repeat
}

export function render(index) { 
  pos = index/pixelCount
  s = square(pos - t1, .5) // .5 => 50% blue
  hsv(.666, s, 1)
}

```

More flexible sawtooth wave (`time()`) approach:

```javascript
var speed
export function sliderSpeed (_v) { speed = _v }

export function beforeRender(delta) {
  t1 = time(.1 / speed / 65.536)
}

export function render(index) { 
  pos = index/pixelCount
  v = (1 + pos * 3 - t1) % 1 // 3 is the number of repetitions we see at once

  // .95 is where white starts (5% white)
  // .15 is where any brightness starts (15% black)
  // The remainder is blue 
  hsv(.666, v < .95, v > .15) 
}

```

---

_[View the full topic](https://forum.electromage.com/t/simple-2-color-wipe/792)._
