Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. int gridWidth = 100;
  2. int gridHeight = 100;
  3. float[][] prevState = new float[gridWidth][gridHeight];
  4. float[][] grid = new float[gridWidth][gridHeight];
  5.  
  6. float maxHue = 100;
  7.  
  8. void setup() {
  9. size(500, 500);
  10. colorMode(HSB, 100, 100, 100);
  11. noStroke();
  12. for (int i = 0; i < prevState.length; i++) {
  13. for (int j = 0; j <prevState[0].length; j++) {
  14. prevState[i][j] = 2 * PI * random(0, 1);
  15. }
  16. }
  17. }
  18.  
  19. void draw() {
  20. int stepX = width / gridWidth;
  21. int stepY = height / gridHeight;
  22.  
  23. float w = 0.10;
  24. float alpha = 0.4;
  25. float K = 0.01;
  26.  
  27. for (int i = 0; i < gridWidth; i+= 1) {
  28. for (int j = 0; j < gridHeight; j+= 1) {
  29. float prevOmega = prevState[i][j];
  30. float accum = 0;
  31.  
  32. for (int k = 0; k < 3; k++) {
  33. for (int p = 0; p < 3; p++) {
  34. int left = i + k - 1;
  35. int right = j + p - 1;
  36. if (left > 0 && right > 0 && left < gridWidth && right < gridHeight) {
  37. float mOmega = prevState[left][right];
  38. accum += sin(prevOmega - mOmega);
  39. }
  40. }
  41. }
  42. accum *= K;
  43.  
  44. float deltaOmega = w + accum;
  45.  
  46. float omega = prevOmega - alpha * deltaOmega;
  47.  
  48. float hue = maxHue * (1.0 + sin(omega))/2.0;
  49. fill(color(hue, 100, 100));
  50. rect(i*stepX, j*stepY, stepX, stepY, 0);
  51. //ellipse(i*stepX, j*stepY, stepX, stepY);
  52. grid[i][j] = omega;
  53. }
  54. }
  55.  
  56. float[][] buff = prevState;
  57. prevState = grid;
  58. grid = buff;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement