Older Newer
Fri, 27 Dec 2019 11:03:43 . . . . SyneRyder [Reformat example code for eBook screens]


Changes by last author:

Added:
= 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 ==

<code>

%ffp

ctl(0): COMBOBOX(vscroll), Action=preview,

Color=#FFFFFF, Fontcolor=#0000ff,

Size=(60,200),

Text="Horizontal\nVertical\n"

"Diagonal\nDiagonal2\nRadial\n"

"Ellipsoid\nPyramid\nBeam\n"

"Angular\nStar\nQuarterPyramid1\n"

"QuarterPyramid2\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;

}

</code>

== See Also ==

blend