Guest User

Noise shifting

a guest
Apr 3rd, 2022
522
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. //// The never ending quest for better LED animations
  2. ////
  3. //// Today: Some complex noise shifting and overlaying by Stefan Petrick 2022
  4. //// written in Processing 4, meant to be used with FastLED
  5.  
  6. void setup() {
  7. size(600, 600);
  8. background(0);
  9. }
  10.  
  11. float scale = 200; // the zoom factor for the layers
  12. float scale2 = 100;
  13. float c, d, time;
  14. float shift1, shift2;
  15. float r, g, b;
  16.  
  17.  
  18. void draw() {
  19.  
  20. time = millis(); // lets have the animation speed independent from the framerate
  21. time = time / 2; // global speed setting, could also be time*3 or anything
  22. c = time / 3000; // speeds of the linear scrollings relative to global speed
  23. d = time / 4000;
  24.  
  25. for (int i = 0; i < 400; i++) {
  26. for (int j = 0; j < 400; j++) {
  27.  
  28. shift1 = (g-127)/100;
  29. shift2 = (r-127)/500;
  30.  
  31. r = noise( (i)/scale , (j/scale) + c ); // just a linear scrolling along y
  32. // please note that we use 2 dimensional noise only
  33. r = map(r, 0.3, 0.8, 0, 255); // increase contrast by constraining and magnifying a value range
  34. // it works like histogram manipulation which sets a black
  35. // and a white value, everything smaller or bigger "bleeds out"
  36.  
  37. g = noise( (i/scale/2) + shift2 , (j/scale/2) + d ); // x wobble and y linear scrolling, different zoom level than layer r
  38. g = map(g, 0.2, 0.7, 0, 255);
  39.  
  40. b = noise( (i/scale2) + shift1, (j/scale2) + shift2 ); // x and y wobble
  41. b = map(b, 0.3, 0.7, 0, 255);
  42.  
  43. color c = color( (b*r) / 255, b-g, (b-r) * g/255 ); // some modulation & delta stuff to make it more interesting
  44. set(i+100, j+100, c ); // done!
  45.  
  46. if ((i%20==0) && (j==399)) { // show a horizontal line of values as rectangles
  47. fill((b*r)/255, b-g, (b-r)*g/255);
  48. rect (i+100, 520, 18, 18, 5);
  49.  
  50. }
  51. if ((i==0) && (j%20==0)) { // same vertical
  52. fill((b*r)/255, b-g, (b-r)*g/255);
  53. rect (60, j+100, 18, 18, 5);
  54. }
  55. }
  56. }
  57. updatePixels();
  58. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment