Older Newer
Thu, 28 Nov 2019 03:29:16 . . . . SyneRyder [First function definition]


Changes by last author:

Added:
= mix2 =

== Syntax ==

int mix2(int a, int b, int n, int d)

== Arguments ==

:a

::An integer value to be mixed in.

:b

::An integer value for the base value.

:n

::An integer value which controls the mixture.

:d

::An integer value for the range.

== Return ==

An integer which is a mix of a into b, based on the position of n in range [0,d].

== Description ==

This function calculates how much of a will be mixed into b, proportional to the position of n in the range from 0 to d. If n is 0, the value of b is returned, if n is equal to d, the value of a is returned. For any values of n in between 0 and d, a proportional value is calculated.

This version of the mix function uses a slightly different algorithm, of the form (d == 0) ? 0 : (b - a)*n >= 0 ? b - ((b - a)*n*2 + d)/(2*d) : b + ((a - b)*n*2 + d)/(2*d) ;

== Example ==

<code>

%ffp

ctl[0]: "Darken", Range=(0,100)

ctl[1]: COMBOBOX, "mix\nmix1\nmix2", Val=0, Size=(*,60)

ForEveryTile: {

for (y = y_start; y &lt; y_end; y++) {

for (x = x_start; x &lt; x_end; x++) {

for (z=0; z &lt; 3; z++) {

switch(ctl(1)) {

case 0:

pset(x,y,z, mix(0, src(x,y,z), ctl(0), 100) );

break;

case 1:

pset(x,y,z, mix1(0, src(x,y,z), ctl(0), 100) );

break;

case 2:

pset(x,y,z, mix2(0, src(x,y,z), ctl(0), 100) );

break;

default:

pset(x,y,z, mix(0, src(x,y,z), ctl(0), 100) );

}

}

}

}

return true;

}

</code>

== See Also ==

scl, mix, mix1