grad2D

Syntax

int grad2D(int x, int y, int X, int Y, int grad, int dist, int repeat)

Arguments

x
Current x coordinate in the gradient field
y
Current y coordinate in the gradient field
X
Vertical size of the gradient field
Y
Horizontal size of the gradient field
grad
Gradient type (0 = Horizontal, 1 = Vertical, 2 = Diagonal, 3 = Diagonal2, 4 = Radial, 5 = Ellipsoid, 6 = Pyramid, 7 = Beam, 8 = Angular, 9 = Star, 10 = Quarter Pyramid , 11 = Quarter Pyramid 2, 12 = Quarter Radial)
dist
0 for linear output, 1 for sine distributed output
repeat
number of gradient repetitions, 0 for no repetition

Return

Returns the gradient value at the coordinates (x,y)

Description

This is a gradient engine. It lets you choose between currently 12 gradient types and contains a parameter for switching between linear and sine distributed output. Additionally there's a parameter for setting the number of gradient repetitions. grad2D() returns a grayscaled gradient value. To produce color gradients, you have to scale the output for the r, g and b values yourself or use the function for each r, g and b value individually. You could also use grad2d() twice with different parameters and use blend() to merge the gradients. So there are a lot of different possibilities. Currently only returns 8-bit color values.

Example

%ffp

ctl(0): combobox(vscroll),action=preview, color=#FFFFFF,fontcolor=#0000ff,
	size=(60,200), text="Horizontal\nVertical\nDiagonal\nDiagonal2\nRadial\nEllipsoid\nPyramid\nBeam\nAngular\nStar\nQuarterPyramid1\nQuarterPyramid2\nQuarter Radial",
	val=0
ctl(5): "Repeat", pos=(270,30),Range=(0,128)
ctl(1): checkbox, text="Invert", pos=(270,40)
ctl(2): checkbox, text="Sine Distribution", pos=(270,50)

ctl(3): checkbox, text="Do Some Color Mixing", pos=(270,70)


ForEveryTile:
{
	int gradient,col;

	for (y=y_start; y<y_end; y++){
		updateProgress(y,y_end);
	for (x=x_start; x<x_end; x++){ 

	for (z=0; z<Z; z++){ 
		
		if (ctl(3)) col=(z+1); else col=1;

		gradient = grad2D(x,y,X*col,Y*col,ctl(0),ctl(2),ctl(5));
		
		if (ctl(1)) gradient = 255 - gradient;

		pset(x, y, z, gradient);

	}}}

	return true;
}

Also see

blend