17
Jun
09

Random Gradients Variation

///////////////////////
// CIFilter Kernel Code
///////////////////////

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);  
}

kernel vec4 multiplyChannels(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;
    float shade = R * G * B; 
  
    return vec4(vec3(shade), 1.0);  
}

///////////////////
// JavaScript
///////////////////

function __image main(__boolean Trigger, __index Type) {  
  
    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);  
  
    switch (Type) {
    case 0:
    		// Call kernel function and return result  
    		return combineChannels.apply(gradR.definition, null, gradR, gradG, gradB);
    		break;
    	case 1:
    		return multiplyChannels.apply(gradR.definition, null, gradR, gradG, gradB);
    		break;
	} 
}

Makes greyscale triangles and squares.

EDIT:
Just uploaded a QTZ with three variations on the basic random gradients theme, all in one CIFilter patch.
Download it if you think you’ll find it useful…
‘tb_randomGradients_1.0.qtz’ in the box.net widget on right.

And here’s a clip of it in action, courtesy of Lee Grosbauer:

Cheers, Lee!

Advertisements

5 Responses to “Random Gradients Variation”


  1. June 22, 2009 at 11:40 am

    Good stuff 🙂 Learning a lot from your code!

  2. 3 Lee
    June 23, 2009 at 3:49 am

    Well, I put a short clip called Random Gradients up on Vimeo that utilizes tb_randGradients_1.0, but I’ll be darned if I can figure out how to link to it. Anyway … http://www.vimeo.com/5283659

    Thanks so much for the CIFilter. Really nice!

  3. 4 toneburst
    June 23, 2009 at 8:12 am

    Cheers Lee, I’ve tacked your clip on the end of this post. Nice one!
    Re. linking to the QTZ: I’m not sure you can link directly to stuff in the Box.net widget, but you can link to this post, and people can get to it that way.

    I should really put more stuff on Memo’s QTZ archive page, I guess…

    a|x

  4. 5 Lee
    June 23, 2009 at 4:46 pm

    Cheers Alex! I’ll try some other utilizations, as well. The greatest difficulty on that rendition was getting the patch to toggle smoothly through the variations in synch with the iterator. I never did completely achieve it, frankly.

    Regarding my reference to linking; I had meant that I couldn’t figure out how to link directly to videos at Vimeo. I suspect that they may have recently modified video linking access over there.

    Salut!


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

  • 473,930 hits

%d bloggers like this: