public void Start() { // Create it: Filter = new SurfaceTexture(); // Apply initial properties (inputs into the filter): Filter.Set("contours", Contours); Filter.Set("uniformity", Uniformity); Filter.Set("frequency", Frequency); // Start building our voronoi node. // Voronoi is, in short, a kind of cellular noise. Voronoi v = new Voronoi(); // *All* are required: v.Frequency = new Property(Filter, "frequency"); v.Distance = new Property((int)VoronoiDistance.Euclidean); v.DrawMode = new Property((int)VoronoiDraw.Normal); v.MinkowskiNumber = new Property(0f); v.Function = new Property((int)VoronoiMethod.F2minusF1); v.Jitter = new Property(Filter, "uniformity"); // If we just displayed 'v' as our root node, we'd just // get some voronoi noise which looks like a bunch of black and white balls. // So, next, we'll tonemap for interesting effects. // Create a sine wave with a variable frequency (to be used by the tonemapper): TextureNode graph = new ScaleInput( new SineWave(), new Property(Filter, "contours") ); // Create the tonemapper node now. // -> We're mapping the black->white range of pixels from the voronoi noise via our sine graph. // That creates a kind of hypnotic black-and-white 'rippling' effect. ToneMap map = new ToneMap(v, graph); // Let's make it some more exciting colours. // Create a gradient from a background->foreground colour, and use lookup to map from our b+w to that gradient. Blaze.Gradient2D rawGradient = new Blaze.Gradient2D(); rawGradient.Add(0f, Color.blue); rawGradient.Add(1f, Color.white); // Create that lookup now: Filter.Root = new Lookup( new Loonim.Gradient(rawGradient, null), map ); // Create the draw information: // - GPU mode // - Size px square // - HDR (true) DrawInfo = new DrawInfo((int)Size); }
public void Add(Gradient2D gradient, float at) { RenderedGradient rendition = gradient.Render(PixelCount); if (Gradients == null) { Gradients = new Gradient2D[] { gradient }; RenderedGradients = new RenderedGradient[1] { rendition }; Positions = new float[] { at }; } else { Gradient2D[] newGradients = new Gradient2D[Gradients.Length + 1]; RenderedGradient[] newRenders = new RenderedGradient[Gradients.Length + 1]; float[] newPositions = new float[Gradients.Length + 1]; int index = 0; bool inserted = false; for (int i = 0; i < Gradients.Length; i++) { //Copy everything across. if (!inserted && Positions[i] > at) { inserted = true; newGradients[index] = gradient; newRenders[index] = rendition; newPositions[index++] = at; } newGradients[index] = Gradients[i]; newRenders[index] = RenderedGradients[i]; newPositions[index++] = Positions[i]; } if (!inserted) { newGradients[index] = gradient; newRenders[index] = rendition; newPositions[index] = at; } Gradients = newGradients; Positions = newPositions; RenderedGradients = newRenders; } }