New to coding. looking to create a symmetrical pattern in a series wired aray

id like to alter the stock linear patterns in PB to repeat simultaneously every 50 pixels on a 600 pixel strip? how can i add that into the code line?

Hi Eddy!

First, you’ll want to redefine the value thats been put into the pixelCount variable. Put this:

pixelCount = 50

at the top of your code, and as the first line inside the definition of beforeRender(). If there’s no beforeRender(), just put it right inside render(), at the top.

Click to expand an example

So, for example, if you found this (from the KITT pattern on v3):

leader = 0
direction = 1
pixels = array(pixelCount)

speed = pixelCount / 800
fade = .0007
export function beforeRender(delta) {
  lastLeader = floor(leader)

You need to turn it into this:

pixelCount = 50
leader = 0
direction = 1
pixels = array(pixelCount)

speed = pixelCount / 800
fade = .0007
export function beforeRender(delta) {
  pixelCount = 50
  lastLeader = floor(leader)

Then you’ll want to transform index to be a number between 0 and 49. Put this right under the definition of render(index):

index %= 50

Example

Find this in the KITT pattern:

export function render(index) {
  v = pixels[index]

And add the aforementioned line so it looks like this:

export function render(index) {
  index %= 50
  v = pixels[index]

This should work for about 90% of the linear patterns!

3 Likes

Very elegant solution, Jeff.

You didn’t quite explain how this works, so I’ll see if I can explain:

By redefining pixelCount, most patterns won’t look beyond the 60. But PB itself will still run thru all pixels (600), so by using mod (%=) the index will just keep calculating 0-59 over as it does 60-600. Nifty trick. Super easy.

Except he asked for 50… But luckily, just substitution of 50 for where you used 60, it will also evenly divide up 600, so it’ll still work with 50 , smoothly. Using some non evenly dividing number would, of course, mean the final segment would be incomplete. [Now fixed, ignore my correction]

1 Like