kernel SquareGradient < namespace: "com.27Bobs"; vendor: "Todd Yard"; version: 1; description: "Creates a square gradient."; > { parameter int rotation < minValue: int(0); maxValue: int(360); defaultValue: int(0); description: "The rotation of the gradient."; >; parameter float2 center < minValue: float2(0.0,0.0); maxValue: float2(1024.0,1024.0); defaultValue: float2(256.0,256.0); description: "The center of the gradient."; >; input image4 gradient; output pixel4 result; void evaluatePixel() { float2 coord = outCoord(); float2 relativePos = coord - center; // find angle of current pixel coordinate relative to the center of the gradient float theta = atan(relativePos.y, relativePos.x); // adjust angle based on rotation parameter theta = degrees(theta) - float(rotation); // keep angle between 0 and 360 if (theta < -360.0) { theta += 720.0; } else if (theta < 0.0) { theta += 360.0; } else if (theta > 360.0) { theta -= 360.0; } theta = clamp(theta, 0.0, 360.0); result = sampleNearest(gradient, float2(floor(theta), 1)); } }