compositor for 2d shader
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DRAWGENERATIVE.pde 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. class DRAWGENERATIVE extends Shader {
  2. // choose channel
  3. int channel = HUE;
  4. // run, after 30 iterations result will be saved automatically
  5. // or press SPACE
  6. // channels to work with
  7. final static int RED = 0;
  8. final static int GREEN = 1;
  9. final static int BLUE = 2;
  10. final static int HUE = 3;
  11. final static int SATURATION = 4;
  12. final static int BRIGHTNESS = 5;
  13. final static int NRED = 6;
  14. final static int NGREEN = 7;
  15. final static int NBLUE = 8;
  16. final static int NHUE = 9;
  17. final static int NSATURATION = 10;
  18. final static int NBRIGHTNESS = 11;
  19. int n=2000;
  20. float [] cx=new float[n];
  21. float [] cy=new float[n];
  22. int len;
  23. // working buffer
  24. PGraphics buffer;
  25. int tick = 0;
  26. DRAWGENERATIVE() {
  27. name = "fxDrawGenerative";
  28. buffer = createGraphics(renderer.width, renderer.height);
  29. buffer.noFill();
  30. buffer.beginDraw();
  31. buffer.strokeWeight(0.3);
  32. //buffer.background(0); //ENABLE THIS TO DRAW FROM BLANK
  33. buffer.endDraw();
  34. rw = renderer.width;
  35. len = (renderer.width<renderer.height?renderer.width:renderer.height)/6;
  36. for (int i=0; i<n; i++) {
  37. cx[i]=random(renderer.width);
  38. cy[i]=random(renderer.height);
  39. }
  40. }
  41. int rw;
  42. void apply() {
  43. if (rw != renderer.width) {
  44. rw = renderer.width;
  45. PGraphics save = createGraphics(renderer.width, renderer.height);
  46. save.beginDraw();
  47. save.image(buffer, 0, 0, save.width, save.height);
  48. save.endDraw();
  49. buffer.setSize(renderer.width, renderer.height);
  50. buffer.beginDraw();
  51. buffer.image(save,0,0,buffer.width,buffer.height);
  52. buffer.endDraw();
  53. }
  54. buffer.beginDraw();
  55. for (int i=1; i<n; i++) {
  56. color c = renderer.get((int)cx[i], (int)cy[i]);
  57. buffer.stroke(c);
  58. buffer.point(cx[i], cy[i]);
  59. // you can choose channels: red(c), blue(c), green(c), hue(c), saturation(c) or brightness(c)
  60. cy[i]+=sin(map(getChannel(c), 0, 255, 0, TWO_PI));
  61. cx[i]+=cos(map(getChannel(c), 0, 255, 0, TWO_PI));
  62. }
  63. if (frameCount>len) {
  64. frameCount=0;
  65. println("iteration: " + tick++);
  66. for (int i=0; i<n; i++) {
  67. cx[i]=random(renderer.width);
  68. cy[i]=random(renderer.height);
  69. }
  70. }
  71. buffer.endDraw();
  72. renderer.beginDraw();
  73. renderer.image(buffer, 0, 0, renderer.width, renderer.height);
  74. renderer.endDraw();
  75. }
  76. float getChannel(color c) {
  77. int ch = channel>5?channel-6:channel;
  78. float cc;
  79. switch(ch) {
  80. case RED:
  81. cc = red(c);
  82. break;
  83. case GREEN:
  84. cc = green(c);
  85. break;
  86. case BLUE:
  87. cc = blue(c);
  88. break;
  89. case HUE:
  90. cc = hue(c);
  91. break;
  92. case SATURATION:
  93. cc = saturation(c);
  94. break;
  95. default:
  96. cc= brightness(c);
  97. break;
  98. }
  99. return channel>5?255-cc:cc;
  100. }
  101. }