16
Jun
09

Random Gradient CIFilter JavaScript

Creates linear gradients between two random points across RGB channels every time ‘Trigger’ is clicked.

CIFilter Kernel Code (top panel)

kernel vec4 combineChannels(sampler ImageR, sampler ImageG, sampler ImageB)
{
	float R = sample(ImageR, samplerCoord(ImageR)).r;
	float G = sample(ImageG, samplerCoord(ImageG)).r;
	float B = sample(ImageB, samplerCoord(ImageB)).r;

	return vec4(R, G, B, 1.0);
}

Javascript (bottom panel)

function __image main(__boolean Trigger) {
	
	var dims = new Vec(256,256);
	var gradDims = new Vec(0,0,dims.x,dims.y);
	
	var black = new Vec(0,0,0,1);
	var white = new Vec(1,1,1,1);
	
	var p0 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
	var p1 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
	
	var gradR = Filter.CILinearGradient(p0, p1, black, white);
	gradR = Filter.CICrop(gradR, gradDims);

	p0 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
	p1 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
	
	var gradG = Filter.CILinearGradient(p0, p1, black, white);
	gradG = Filter.CICrop(gradG, gradDims);
	
	p0 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
	p1 = new Vec(Math.random() * dims.x, Math.random() * dims.y);
	
	var gradB = Filter.CILinearGradient(p0, p1, black, white);
	gradB = Filter.CICrop(gradB, gradDims);
	
	
	// Call kernel function and return result
	return combineChannels.apply(gradR.definition, null, gradR, gradG, gradB);
}
Advertisements

6 Responses to “Random Gradient CIFilter JavaScript”


  1. 1 Lee
    June 17, 2009 at 2:05 pm

    Thank you! I labeled the resulting file, saved as a clip: tb Random Gradient CIFilter (Clip). It’s really quite nice! Much appreciated.

    • 2 toneburst
      June 17, 2009 at 8:58 pm

      I’ve posted a new version of the code, and there’s a composition with three variations to download in the Box.net widget, if you’re interested.

      a|x

  2. 3 toneburst
    June 17, 2009 at 2:10 pm

    Hi Lee,

    glad you like it. I couldn’t really think of a use for it when I wrote it, so glad you have.
    If you do post anything using it on YouTube/Vimeo let me know, and I’ll put it up here.

    Cheers,

    a|x

  3. 4 Lee
    June 17, 2009 at 2:17 pm

    With pleasure. Thanks again. Permission to use selected grabs as Twitter profile backgrounds?

  4. 5 toneburst
    June 17, 2009 at 2:43 pm

    Permission granted, 4927, Grosbauer, Lee!
    😉

    a|x

  5. 6 Lee
    June 17, 2009 at 3:41 pm

    ahahaha. Très gentil! Thanks. 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Twitter

June 2009
M T W T F S S
« May   Jul »
1234567
891011121314
15161718192021
22232425262728
2930  

Links

Blog Stats

  • 468,884 hits

%d bloggers like this: