123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- class DRAWGENERATIVE extends Shader {
-
- // choose channel
- int channel = HUE;
-
- // run, after 30 iterations result will be saved automatically
- // or press SPACE
-
-
- // channels to work with
- final static int RED = 0;
- final static int GREEN = 1;
- final static int BLUE = 2;
- final static int HUE = 3;
- final static int SATURATION = 4;
- final static int BRIGHTNESS = 5;
- final static int NRED = 6;
- final static int NGREEN = 7;
- final static int NBLUE = 8;
- final static int NHUE = 9;
- final static int NSATURATION = 10;
- final static int NBRIGHTNESS = 11;
-
- int n=2000;
- float [] cx=new float[n];
- float [] cy=new float[n];
-
- int len;
-
- // working buffer
- PGraphics buffer;
-
-
- int tick = 0;
-
-
- DRAWGENERATIVE() {
- name = "fxDrawGenerative";
- buffer = createGraphics(renderer.width, renderer.height);
- buffer.noFill();
- buffer.beginDraw();
- buffer.strokeWeight(0.3);
- //buffer.background(0); //ENABLE THIS TO DRAW FROM BLANK
- buffer.endDraw();
- rw = renderer.width;
- len = (renderer.width<renderer.height?renderer.width:renderer.height)/6;
-
- for (int i=0; i<n; i++) {
- cx[i]=random(renderer.width);
- cy[i]=random(renderer.height);
- }
- }
-
-
- int rw;
- void apply() {
- if (rw != renderer.width) {
- rw = renderer.width;
- PGraphics save = createGraphics(renderer.width, renderer.height);
- save.beginDraw();
- save.image(buffer, 0, 0, save.width, save.height);
- save.endDraw();
- buffer.setSize(renderer.width, renderer.height);
- buffer.beginDraw();
- buffer.image(save,0,0,buffer.width,buffer.height);
- buffer.endDraw();
- }
- buffer.beginDraw();
- for (int i=1; i<n; i++) {
- color c = renderer.get((int)cx[i], (int)cy[i]);
- buffer.stroke(c);
- buffer.point(cx[i], cy[i]);
- // you can choose channels: red(c), blue(c), green(c), hue(c), saturation(c) or brightness(c)
- cy[i]+=sin(map(getChannel(c), 0, 255, 0, TWO_PI));
- cx[i]+=cos(map(getChannel(c), 0, 255, 0, TWO_PI));
- }
- if (frameCount>len) {
- frameCount=0;
- println("iteration: " + tick++);
- for (int i=0; i<n; i++) {
- cx[i]=random(renderer.width);
- cy[i]=random(renderer.height);
- }
- }
- buffer.endDraw();
- renderer.beginDraw();
- renderer.image(buffer, 0, 0, renderer.width, renderer.height);
- renderer.endDraw();
- }
-
-
- float getChannel(color c) {
- int ch = channel>5?channel-6:channel;
- float cc;
-
- switch(ch) {
- case RED:
- cc = red(c);
- break;
- case GREEN:
- cc = green(c);
- break;
- case BLUE:
- cc = blue(c);
- break;
- case HUE:
- cc = hue(c);
- break;
- case SATURATION:
- cc = saturation(c);
- break;
- default:
- cc= brightness(c);
- break;
- }
-
- return channel>5?255-cc:cc;
- }
- }
|