compositor for 2d shader
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shader.pde 2.6KB

9 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. class Shader {
  2. int id;
  3. int number;
  4. String name;
  5. boolean animating = true;
  6. ArrayList<Param> params = new ArrayList<Param>();
  7. class Param {
  8. int type;
  9. String name;
  10. float minValue, maxValue;
  11. float value;
  12. float inc;
  13. boolean animating;
  14. int[] osciModes;
  15. //Osci[] oscis;
  16. Osci osci;
  17. //incrementer -- in bpm
  18. Param(String paramName, int maxValue_, int[] osciModes_) {
  19. name = paramName;
  20. maxValue = maxValue_;
  21. minValue = 0;
  22. type = INTVAL; //int
  23. osciModes = osciModes_;
  24. makeOsci();
  25. play();
  26. }
  27. Param(String paramName, float minValue_, float maxValue_, int[] osciModes_) {
  28. name = paramName;
  29. minValue = minValue_;
  30. maxValue = maxValue_;
  31. type = FLOATVAL; //float
  32. osciModes = osciModes_;
  33. makeOsci();
  34. play();
  35. }
  36. void makeOsci() {
  37. int[] possibleBeats = {1, 2, 4, 8, 16, 32, 64};
  38. int beats = possibleBeats[(int)random(possibleBeats.length)];
  39. int mode = osciModes[(int)random(osciModes.length)];
  40. float phaseshift = (random(1) > .8) ? .25 : 0;
  41. osci = new Osci(beats, phaseshift, mode);
  42. }
  43. void play() {
  44. animating = true;
  45. }
  46. void pause() {
  47. animating = false;
  48. }
  49. void animate() {
  50. osci.update();
  51. value = getValue(osci.value, false);
  52. };
  53. void randomize() {
  54. if (type == INTVAL) {
  55. value = (int)random(minValue, maxValue);
  56. } else if (type == FLOATVAL) {
  57. //value = random(minValue, maxValue);
  58. value = random(minValue, maxValue);
  59. }
  60. }
  61. String formattedValue() {
  62. if (type == INTVAL) {
  63. return str((int)value);
  64. } else if (type == FLOATVAL) {
  65. return nf(getValue(value, true), 0, 2).replace(',', '.').replace(' ', ',');
  66. } else {
  67. return "";
  68. }
  69. }
  70. float getValue(float val, boolean normalize) { //used for other function, dont use it
  71. return normalize ? map(val, minValue, maxValue, 0, 1) : map(val, 0, 1, minValue, maxValue);
  72. }
  73. void setValue(float value_) {
  74. if (type == INTVAL) {
  75. value = constrain((int)value_, 0, maxValue);
  76. } else if (type == FLOATVAL) {
  77. value = getValue(value_, false);
  78. }
  79. }
  80. }
  81. void apply() {
  82. }; //override me
  83. String[] getParamNames() {
  84. String[] pnames = new String[params.size()];
  85. for (int i = 0; i < params.size(); i++) {
  86. pnames[i] = params.get(i).name;
  87. }
  88. return pnames;
  89. }
  90. int paramIdByName(String name_) {
  91. for (int i = 0; i < params.size(); i ++) {
  92. if (params.get(i).name.equals(name_)) {
  93. return i;
  94. }
  95. }
  96. return -1;
  97. }
  98. }
  99. /*
  100. */