class Root extends TextureFilter{ Root(){ super("Root",1,0); replaceSource(0,new Swirl()); } //---------------------- Color output( float x, float y , float z){ return sources[0].output(x,y,z); } //---------------------- void drawNode(){ noStroke(); fill(255,192); ellipse(x,y,3*radius,3*radius); super.drawNode(); } } //################################################################# class Mix extends TextureFilter{ //---------------------- Mix(){ super("Mix",3,0,"Middle source is the mixing rule."); sourceDescriptions("Source B","Mixing rule","Source A"); replaceSource(0, new Paint(255,0,0) ); replaceSource(1, new Noise() ); replaceSource(2, new Paint(0,255,0) ); } //---------------------- Color output( float x, float y , float z){ float H = sources[1].output(x,y,z).getMax(); float L = 1-H; Color a = sources[0].output(x,y,z); Color b = sources[2].output(x,y,z); return new Color( a.r*H + b.r*L , a.g*H + b.g*L , a.b*H + b.b*L ); } } //################################################################# class Invert extends TextureFilter{ Invert(){ super("Invert",1,0); } Color output( float x, float y , float z){ Color a = sources[0].output(x,y,z); return new Color( 1-a.r, 1-a.g, 1-a.b ); } } //################################################################# class Add extends TextureFilter{ Add(){ super("Add",2,0); } Color output( float x, float y , float z){ Color a = sources[0].output(x,y,z); Color b = sources[1].output(x,y,z); return new Color( a.r+b.r, a.g+b.g, a.b+b.b ); } } //################################################################# class Multiply extends TextureFilter{ Multiply(){ super("Multiply",2,0); } Color output( float x, float y , float z){ Color a = sources[0].output(x,y,z); Color b = sources[1].output(x,y,z); return new Color( a.r*b.r, a.g*b.g, a.b*b.b ); } } //################################################################# class Overlay extends TextureFilter{ Overlay(){ super("Overlay",2,0); } Color output( float x, float y , float z){ Color a = sources[0].output(x,y,z); Color b = sources[1].output(x,y,z); return new Color( max(a.r,b.r), max(a.g,b.g), max(a.b,b.b) ); } } //################################################################# class NewsPrint extends TextureFilter{ public NewsPrint(){ super("NewsPrint",2,2); replaceSource(0, new Noise() ); replaceSource(1, new White() ); sourceDescriptions("Source","Background"); setAttribute(0,"Zoom",EXPONENTIAL,32,1.2); setAttribute(1,"Blackness",LINEAR,0.5,1f/16); } //---------------------- Color output( float x, float y , float z){ float zoom = getAttribute(0); float blackness = getAttribute(1); float ix = round( x*zoom )/zoom; float iy = round( y*zoom )/zoom; float value = sources[0].output(ix,iy,z).getMax(); if( (1-value)*blackness > zoom*dist(ix,iy,x,y) ) return new Color(0); else return sources[1].output(x,y,z); } } //################################################################# class ColorPrint extends TextureFilter{ public ColorPrint(){ super("ColorPrint",2,2); replaceSource(0, new Hue() ); replaceSource(1, new White() ); sourceDescriptions("Source","Background"); setAttribute(0,"Zoom",EXPONENTIAL,16,1.2); setAttribute(1,"Blackness",LINEAR,0.5,1f/16); } //---------------------- Color output( float x, float y , float z){ float zoom = getAttribute(0); float blackness = getAttribute(1); float ix = round( x*zoom )/zoom; float iy = round( y*zoom )/zoom; Color sample = sources[0].output(ix,iy,z); float value = sample.getMax(); colorMode(RGB,1); color c = color( sample.r, sample.g, sample.b ); float hueValue = hue(c); float satValue = saturation(c); float briValue = brightness(c); colorMode(RGB,255f); if( max(briValue,1-satValue)*blackness > zoom*dist(ix,iy,x,y) ){ colorMode(HSB,1); c = color( hueValue, satValue, 1); colorMode(RGB,1); float r = red(c); float g = green(c); float b = blue(c); colorMode(RGB,255f); return new Color(r,g,b); } else return sources[1].output(x,y,z); } } //################################################################# class Threshold extends TextureFilter{ public Threshold(){ super("Threshold",1,2); replaceSource(0, new Noise() ); setAttribute(0,"Threshold",LINEAR, 0.5, 1f/64); setAttribute(1,"Softness", LINEAR, 1f/32, 1f/64); } //---------------------- Color output( float x, float y , float z){ float threshold = getAttribute(0); float softness = getAttribute(1); float minimum = threshold-softness/2; float value = sources[0].output(x,y,z).getMax(); return new Color( constrain( (value-minimum)/softness, 0, 1 ) ); } } //################################################################# class Crease extends TextureFilter{ public Crease(){ super("Crease",1,0); replaceSource(0, new Noise() ); } //---------------------- Color output( float x, float y , float z){ float value = sources[0].output(x,y,z).getMax(); return new Color( 1 - abs(2*value-1) ); } } //################################################################# class Hue extends TextureFilter{ Hue(){ super("Hue",1,0,"Uses brightness as hue value"); replaceSource(0,new Noise()); } Color output( float x, float y , float z){ float value = sources[0].output(x,y,z).getMax(); colorMode(HSB,1); color c = color( value, 1, 1); colorMode(RGB,1); float r = red(c); float g = green(c); float b = blue(c); colorMode(RGB,255f); return new Color(r,g,b); } } //################################################################# class Monochrome extends TextureFilter{ Monochrome(){ super("Monochrome",1,0,""); replaceSource(0,new White()); } Color output( float x, float y , float z){ return new Color(sources[0].output(x,y,z).getMax() ); } } //################################################################# class Tint extends TextureFilter{ Tint(){ super("Tint",1,3); setAttribute(0,"Red", LINEAR, random(255), 16); setAttribute(1,"Green", LINEAR, random(255), 16); setAttribute(2,"Blue", LINEAR, random(255), 16); } //---------------------- Color output( float x, float y , float z){ float val = sources[0].output(x,y,z).getMax(); return new Color( getAttribute(0)*val/255, getAttribute(1)*val/255, getAttribute(2)*val/255 ); } //---------------------- void drawNode(){ super.drawNode(); noStroke(); fill(getAttribute(0),getAttribute(1),getAttribute(2)); ellipse(x+radius/1.414,y+radius/1.414,5,5); } } //#################################################################