Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Created January 27, 2015 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylemcdonald/3cd7a6f94981f05de3f6 to your computer and use it in GitHub Desktop.
Save kylemcdonald/3cd7a6f94981f05de3f6 to your computer and use it in GitHub Desktop.
Generating smooth wavetables for LEDs.
size(500, 256);
translate(0, 256);
scale(1, -1);
background(255);
int n = 497;
float inScale = 100;
float outScale = 255;
//float[] data = {0,100,0}; // one cycle
//float[] data = {0,55,10,70,30,90,60,100,60,90,30,70,10,55,0}; // 7 cycles
for(int x = 0; x < n; x++) {
float i = map(x, 0, n, 0, data.length - 1);
int iL = floor(i), iR = ceil(i);
float t = i - iL;
float tt = (3 - 2*t)*t*t;
float y = lerp(data[iL], data[iR], tt);
y = y * outScale / inScale;
y = round(y);
point(x, y + .5);
print(int(y) + ", ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment