class Perlin extends TextureFilter{ float zoom; float[][] nodeMatrix; //---------------------- public Perlin(){ super("Perlin",0,0); zoom = 0.15f; // Skapar en rutnät av slumpade punkter att interpolera över nodeMatrix = new float[20][20]; for(int i=0 ; i<20 ; i++ ){ for(int j=0 ; j<20 ; j++ ){ nodeMatrix[i][j] = random(0f,1f); } } } //---------------------- Color output( float x, float y , float z){ int xP,yP,xPp,yPp; float a,b,c,d,u,v; float shade; xP = ((int)floor(x/zoom)) % 20; yP = ((int)floor(y/zoom)) % 20; xPp = (xP+1) % 20; yPp = (yP+1) % 20; a = nodeMatrix[xP ][yP ]; b = nodeMatrix[xPp][yP ]; c = nodeMatrix[xP ][yPp]; d = nodeMatrix[xPp][yPp]; u = (x/zoom)-floor(x/zoom); u = 3*u*u - 2*u*u*u; v = (y/zoom)-floor(y/zoom); v = 3*v*v - 2*v*v*v; shade = (float)( (1-v)*( a*(1-u) + b*u ) + v*( c*(1-u) + d*u ) ); return new Color( constrain( shade, 0, 1f) ); } } //################################################################# class White extends TextureFilter{ White(){ super("White",0,0); } //---------------------- Color output( float x, float y , float z){ return new Color(1); } } //################################################################# class Grid extends TextureFilter{ Grid(){ super("Grid",0,2); setAttribute(0,"Scale",EXPONENTIAL, 0.05, 1.2); setAttribute(1,"Thickness",EXPONENTIAL, 0.005, 1.2); } //---------------------- Color output( float x, float y , float z){ float scale = getAttribute(0); float thickness = getAttribute(1); return new Color( (abs(x+0.5)%scale