Jump to content

Random Gradient Bars


Recommended Posts

Generates random gradient bars onto the canvas. It can be seen as a upgrade of Gradient Bars made by @pyrochild though the code for both are very much different. Random Gradient Bars plugin offers being able to define multiple color modes, symmetry, origin, randomized inversion, differing random modes. This is very near completely identical port of the gmic version.

 

Plugin Download -> Random Gradient Bars.zip

 

After installation, you will see Random Gradient Bars under Effects->Render.

 

Note: Reseed Button does not work until after you press it twice. I don't know how to fix that bug or even if it is fixable.

 

Preview of output:

 

m5ofNP7.png

- Source Codes -

License: CeCILL v2.0 - http://cecill.info/licences/Licence_CeCILL_V2-en.html

 

C# Codelab

Spoiler
// Name: Random Gradient Bars
// Submenu: Render
// Author: Reptillian
// Title: Random Gradient Bars
// Version: .75
// Desc: Generates Random Gradient Bars onto the canvas
// Keywords: Render, Bars
// URL: https://forums.getpaint.net/profile/85868-reptillian/
// Help:
#region UICode
ReseedButtonControl seed = 0; // Reseed
IntSliderControl bar_size = 50; // [1,256] Bar Size
IntSliderControl space_size = 0; // [0,256] Space Size
AngleControl degree = 45; // [-180,180] Angle
DoubleSliderControl skew_degree = 0; // [-89,89] Skew Angle
PanSliderControl origin = Pair.Create(0.000, 0.000); // Origin
DoubleSliderControl shift = 0; // [0,100] Shift
DoubleSliderControl mult_1 = 0.1; // [0.1,256] Multiplier A
DoubleSliderControl mult_2 = 100; // [0.1,256] Multiplier B
ListBoxControl repetition_mode = 0; // Repetition|Random|Cut|Periodic|Continuous
ListBoxControl<Random_Repetition_Mode> repetition_random_repetition_modes = 0; // {repetition_mode} Random Bar Repetition|All|Cut and Periodic|Cut and Continuous|Periodic and Continuous
ListBoxControl<CS_Mode> color_space = 0; // Color|Gray|Duotone|Random-RGB|Random-HSV
ListBoxControl<Space_Mode> space_mode = 0; // Space Mode|Alpha|Cut|Gradient
ListBoxControl<Sym_Mode> symmetry = 0; // Symmetry Mode|N/A|A|B
CheckboxControl inversion_mode = false; // Use Inversion
IntSliderControl sublevel = 1; // [0,3] Subpixel Level
ColorWheelControl space_color_a = ColorBgra.FromBgr(0, 140, 255); // [DarkOrange] Space Color A
ColorWheelControl space_color_b = ColorBgra.FromBgr(0, 215, 255); // [Gold] Space Color B
#endregion
double[] v_base = null;
double[] v_shift = null;
double[] v_mult = null;
int[] v_modulo_out = null;
bool[] v_invert = null;
int[] v_hue = null;
int[] v_rgb_r = null;
int[] v_rgb_g = null;
int[] v_rgb_b = null;

double ang;
int number_of_bars;
int shift_bars;
int new_seed;

double cut(double a,double b,double c){
    double min_val = Math.Min(b,c);
    double max_val = Math.Max(b,c);
    return (a < min_val) ? min_val : (a > max_val) ? max_val : a;
}

double fmod(double a, double b){
    return a - Math.Floor(a / b) ;
}

int imod(int a, int b){
    int r = a % b;
    return r < 0 ? r + b : r;
}

double fmod_cont(double a, double b){
    double ind = imod((int)(Math.Floor(a/b)),2) ;
    return ind == 1 ? b - fmod(a,b) : fmod(a,b) ;
}

double fcut(double a, double b){
    return (cut(a,-b,b)+b)/2 ;
}


double rot_x(double a, double b, double sin_ang, double cos_ang){
    return a * cos_ang - b * sin_ang ;
}


double rot_y(double a, double b, double sin_ang, double cos_ang){
    return a * sin_ang + b * cos_ang ;
}


double lerp(double a, double b, double t){
    return a * (1 - t) + b * t ;
}

ColorBgra lerp_HSV(HsvColor B,HsvColor A,double t){

    double A_H = (double)(A.Hue);
    double A_S = (double)(A.Saturation);
    double A_V = (double)(A.Value);
    double B_H = (double)(B.Hue);
    double B_S = (double)(B.Saturation);
    double B_V = (double)(B.Value);
    double d_NH = lerp(A_H,B_H,t);
    double d_NS = lerp(A_S,B_S,t);
    double d_NV = lerp(A_V,B_V,t);
    int NH = (int)(Math.Round(d_NH));
    int NS = (int)(Math.Round(d_NS));
    int NV = (int)(Math.Round(d_NV));
    HsvColor new_hsv = new HsvColor(NH,NS,NV);
    return ColorBgra.FromColor(new_hsv.ToColor());
}

ColorBgra fromHueandValue(int Hue,double t){
    HsvColor new_hsv = new HsvColor(Hue,100,(int)(Math.Round(t*100)));
    return ColorBgra.FromColor(new_hsv.ToColor());
}

Random Seed = new Random(int.MaxValue);
Random Seed_2 = new Random(int.MaxValue);
Random Seed_3 = new Random(int.MaxValue);

void PreRender(Surface dst, Surface src)
{
    Random myRandom,myRandom_2,myRandom_3;

    if (new_seed != seed){
        myRandom = Seed;
        myRandom_2 = Seed_2;
        myRandom_3 = Seed_3;
    }
    else{
        myRandom = new Random(int.MaxValue);
        myRandom_2 = new Random(int.MaxValue);
        myRandom_3 = new Random(int.MaxValue);
    }

    new_seed = seed;

    int ww = src.Width - 1 ;
    int hh = src.Height - 1 ;
    double cx = (double)(ww) / 2 ;
    double cy = (double)(hh) / 2 ;
    double cut_ang = Math.Atan2(cy,cx) ;
    double cut_ang_2 = Math.PI - cut_ang ;
    ang = ( degree / 180 ) / Math.PI ;
    bool use_shift = shift > 0 ;
    int total_width = bar_size + space_size;
    double d_total_width = (double)(total_width);
    double d_ww = (double)(ww);
    double d_hh = (double)(hh);

    number_of_bars = (int)(Math.Ceiling(Math.Sqrt(ww*ww+hh*hh)/total_width));
    shift_bars = number_of_bars / 2;

    v_base = new double[number_of_bars];
    v_modulo_out = new int[number_of_bars];
    v_invert = new bool[number_of_bars];
    v_shift = new double[number_of_bars];   

    for(int n = 0 ; n < number_of_bars ; n++){
        v_base[n] = 0;
        v_invert[n] = false ;
    }


    Array.Copy(v_base, v_shift, v_base.Length);

    double shift_dist;
    int precision = 100000;

    if (use_shift){
        for(int n = 0 ; n < number_of_bars ; n++){
            shift_dist = (double)(myRandom_3.Next(precision)) / (double)(precision) ;
            shift_dist*=shift;
            if (myRandom_3.Next(255) > 128){
                v_shift[n] = shift_dist;
            }
            else{
                v_shift[n] = -shift_dist;
            }
        }
    }

    if (repetition_mode > 0) {
        int rep_pos=repetition_mode - 1 ;
        for(int n = 0 ; n < number_of_bars ; n++){
            v_modulo_out[n]=rep_pos;
        }
    }
    else{
        switch(repetition_random_repetition_modes){
            case Random_Repetition_Mode.Cut_Periodic:
                for(int n = 0 ; n < number_of_bars ; n++){
                    v_modulo_out[n] = myRandom.Next(2);
                }
                break;
            case Random_Repetition_Mode.Cut_Continuous:
                for(int n = 0 ; n < number_of_bars ; n++){
                    v_modulo_out[n] = myRandom.Next(2)*2;
                }
                break;
            case Random_Repetition_Mode.Periodic_Continuous:
                for(int n = 0 ; n < number_of_bars ; n++){
                    v_modulo_out[n] = myRandom.Next(2)+1;
                }                
                break;
            default:
                for(int n = 0 ; n < number_of_bars ; n++){
                    v_modulo_out[n] = myRandom.Next(3);
                }  
                
                break;
        }
    }

    if (inversion_mode){
        for(int n = 0 ; n < number_of_bars ; n++){
            if (myRandom_2.Next(255) > 128){
                v_invert[n] = true;
            }
        }
    }

    v_hue = new int[number_of_bars];
    v_rgb_r = new int[number_of_bars];
    v_rgb_g = new int[number_of_bars];
    v_rgb_b = new int[number_of_bars];
    v_mult = new double[number_of_bars];

    for(int n = 0 ; n < number_of_bars ; n++){
        v_hue[n] = myRandom.Next(359);
        v_rgb_r[n] = myRandom.Next(255);
        v_rgb_g[n] = myRandom.Next(255);
        v_rgb_b[n] = myRandom.Next(255);
        v_mult[n] = lerp(mult_1,mult_2,(double)(myRandom.Next(precision))/(double)(precision));
    }

}

void Render(Surface dst, Surface src, Rectangle rect)
{
    // Delete any of these lines you don't need
    int ww = src.Width - 1 ;
    int hh = src.Height - 1 ;
    double d_ww = (double)(ww);
    double d_hh = (double)(hh);
    double sd = Math.Max(d_ww,d_hh)/Math.Min(d_ww,d_hh);
    double sx = d_ww>d_hh?sd:1;
    double sy = d_ww>d_hh?1:sd;
    double cx = (double)(ww) / 2 ;
    double cy = (double)(hh) / 2 ;
    double ox = cx - ((double)(cx)*-origin.First);
    double oy = cy - ((double)(cy)*-origin.Second);
    double ww_div_sx = (double)(ww)/sx;
    double hh_div_sy = (double)(hh)/sy;
    double pyth_img = Math.Sqrt(d_ww*d_ww+d_hh*d_hh);
    double ren_ang = ( degree / 180 ) * Math.PI ;
    double skew_ang = ( skew_degree / 180)*Math.PI;
    double cos_ang = Math.Cos(ren_ang);
    double sin_ang = Math.Sin(ren_ang);
    double mdist = Math.Tan(skew_ang)*pyth_img;
    int total_width = bar_size + space_size;
    bool width_test = total_width>1;
    bool bar_and_space_test = (bar_size==1)&&(space_size<2);
    bool space_test = space_size > 0;
    int half_total_width = width_test ? total_width / 2 : 0 ;
    double initial_x,initial_y,spacing,gradient,point_x,new_gradient,final_gradient;
    int bar,bar_id,use_modulo_out;
    bool spaces;
    double temp_result;
    double temp_result_2;
    bool gradient_test;
    int window = sublevel + 1 ;
    int windows_count = window * window;

    int sc_a_B = Convert.ToInt32(space_color_a.B);
    int sc_a_G = Convert.ToInt32(space_color_a.G);
    int sc_a_R = Convert.ToInt32(space_color_a.R);
    int sc_b_B = Convert.ToInt32(space_color_b.B);
    int sc_b_G = Convert.ToInt32(space_color_b.G);
    int sc_b_R = Convert.ToInt32(space_color_b.R);

    
    Color rgb_1 = space_color_a.ToColor();
    Color rgb_2 = space_color_b.ToColor();
    HsvColor hsv_color_a = HsvColor.FromColor(rgb_1);
    HsvColor hsv_color_b = HsvColor.FromColor(rgb_2);

    ColorBgra result;
    int r,g,b,a;
    double d_r,d_g,d_b,d_a;

    double xp,yp,wxp,wyp;

    if (bar_and_space_test){
        spacing = (space_size>0)?.5:0;
    }
    else{
        spacing = 1 - ((double)(space_size)/((double)(total_width) - 1));
    }

    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
             r = 0;
             g = 0;
             b = 0;
             a = 0;
             d_r = 0;
             d_g = 0;
             d_b = 0;
             d_a = 0;
             for (int iwpx = 0 ; iwpx < window ; iwpx++){
                 for (int iwpy = 0 ; iwpy < window ; iwpy++){
                    wxp = (double)(iwpx)/(double)(window);
                    wyp = (double)(iwpy)/(double)(window);
                    xp = (double)(x) + wxp;
                    yp = (double)(y) + wyp;
                    initial_x = (xp - ox) / d_ww * sx;
                    initial_y = (yp - oy ) / d_hh * sy;
                    gradient = -rot_y(initial_x,initial_y,sin_ang,cos_ang)*hh_div_sy/pyth_img;
                    point_x = rot_x(initial_x,initial_y,sin_ang,cos_ang)*ww_div_sx+gradient*mdist+half_total_width;
                    bar_id = (int)(Math.Floor(point_x/total_width));

                    switch(symmetry){
                        case Sym_Mode.A:   bar = imod(-Math.Abs(bar_id)+shift_bars,number_of_bars);break;
                        case Sym_Mode.B:   bar = imod(Math.Abs(bar_id)+shift_bars,number_of_bars);break;
                        default:  bar = imod(bar_id+shift_bars,number_of_bars);break;
                    }

                    if(bar_and_space_test) {
                        if (space_test){
                            spaces = imod((int)(point_x),2) == 1 ;   
                            }
                        else{
                            spaces = true;         
                        }
                    }
                    else {
                        spaces = 2*Math.Abs(fmod(point_x/total_width,1)-.5)<=spacing; 
                    }

                new_gradient = gradient * v_mult[bar] + v_shift[bar];
                use_modulo_out = v_modulo_out[bar];

                switch(use_modulo_out){
                    case 2: final_gradient = v_invert[bar] ? 1 - fmod_cont(new_gradient,1) : fmod_cont(new_gradient,1); break;
                    case 1: final_gradient = v_invert[bar] ? 1 - fmod(new_gradient,1) : fmod(new_gradient,1); break;
                    default: final_gradient= v_invert[bar] ? 1 - fcut(new_gradient,1) : fcut(new_gradient,1); break;
                }

                switch(color_space){
                    case CS_Mode.HSV_Random: switch(space_mode){
                        case Space_Mode.Gradient:
                            temp_result = cut(gradient*2+.5,0,1);
                            if (spaces){
                                result=fromHueandValue(v_hue[bar],final_gradient);
                            }
                            else{
                                result=lerp_HSV(hsv_color_a,hsv_color_b,temp_result);
                            }
                            break;
                        case Space_Mode.Cut:
                            gradient_test = gradient >= 0;
                            if (spaces){
                                result=fromHueandValue(v_hue[bar],final_gradient);
                            }
                            else{
                                result=ColorBgra.FromBgr(
                                    (byte)((int)(gradient_test?sc_a_B:sc_b_B)),
                                    (byte)((int)(gradient_test?sc_a_G:sc_b_G)),
                                    (byte)((int)(gradient_test?sc_a_R:sc_b_R))
                                );
                            }
                        break;
                        default:
                            if (spaces){
                                result=fromHueandValue(v_hue[bar],final_gradient);
                            }
                            else{
                                result=ColorBgra.FromBgra(0,0,0,0);
                            }
                            break;
                        }
                        break;
                    case CS_Mode.RGB_Random: switch(space_mode){
                        case Space_Mode.Gradient:
                            temp_result = cut(gradient*2+.5,0,1);
                            result=ColorBgra.FromBgr(
                                (byte)(spaces ? (int)(v_rgb_b[bar] * final_gradient) : (int)(lerp((double)(sc_b_B),(double)(sc_a_B),temp_result))),
                                (byte)(spaces ? (int)(v_rgb_g[bar] * final_gradient) : (int)(lerp((double)(sc_b_G),(double)(sc_a_G),temp_result))),
                                (byte)(spaces ? (int)(v_rgb_r[bar] * final_gradient) : (int)(lerp((double)(sc_b_R),(double)(sc_a_R),temp_result)))
                            );
                        break;
                        case Space_Mode.Cut:
                            gradient_test = gradient >= 0;
                            result=ColorBgra.FromBgr(
                                (byte)(spaces ? (int)(v_rgb_b[bar] * final_gradient) : (int)(gradient_test ? sc_a_B : sc_b_B)),
                                (byte)(spaces ? (int)(v_rgb_g[bar] * final_gradient) : (int)(gradient_test ? sc_a_G : sc_b_G)),
                                (byte)(spaces ? (int)(v_rgb_r[bar] * final_gradient) : (int)(gradient_test ? sc_a_R : sc_b_R))
                            );
                        break;
                        default: 
                            result=ColorBgra.FromBgra(
                                (byte)((int)(v_rgb_b[bar] * final_gradient)),
                                (byte)((int)(v_rgb_g[bar] * final_gradient)),
                                (byte)((int)(v_rgb_r[bar] * final_gradient)),
                                (byte)(spaces ? 255 : 0)
                            );
                            break;
                        }
                        break;
                    case CS_Mode.Duotone: switch(space_mode){
                        case Space_Mode.Gradient:
                            temp_result = cut(gradient*2+.5,0,1);
                            result=ColorBgra.FromBgr(
                                (byte)(spaces ? (int)(lerp((double)(sc_a_B),(double)(sc_b_B),final_gradient)) : (int)(lerp((double)(sc_b_B),(double)(sc_a_B),temp_result))),
                                (byte)(spaces ? (int)(lerp((double)(sc_a_G),(double)(sc_b_G),final_gradient)) : (int)(lerp((double)(sc_b_G),(double)(sc_a_G),temp_result))),
                                (byte)(spaces ? (int)(lerp((double)(sc_a_R),(double)(sc_b_R),final_gradient)) : (int)(lerp((double)(sc_b_R),(double)(sc_a_R),temp_result)))
                            );
                            break;
                        case Space_Mode.Cut:
                            gradient_test = gradient >= 0;
                            result=ColorBgra.FromBgr(
                                (byte)(spaces ? (int)(lerp((double)(sc_a_B),(double)(sc_b_B),final_gradient)) : (int)(gradient_test ? sc_a_B : sc_b_B)),
                                (byte)(spaces ? (int)(lerp((double)(sc_a_G),(double)(sc_b_G),final_gradient)) : (int)(gradient_test ? sc_a_G : sc_b_G)),
                                (byte)(spaces ? (int)(lerp((double)(sc_a_R),(double)(sc_b_R),final_gradient)) : (int)(gradient_test ? sc_a_R : sc_b_R))
                            );
                            break;
                        default: 
                            result=ColorBgra.FromBgra(
                                (byte)((int)(lerp((double)(sc_a_B),(double)(sc_b_B),final_gradient))),
                                (byte)((int)(lerp((double)(sc_a_G),(double)(sc_b_G),final_gradient))),
                                (byte)((int)(lerp((double)(sc_a_R),(double)(sc_b_R),final_gradient))),
                                (byte)(spaces ? 255 : 0)
                            );
                        break;
                        }
                        break;
                    default: switch(space_mode){
                        case Space_Mode.Gradient:
                            temp_result = Math.Round(255 * final_gradient);
                            temp_result_2 = cut(gradient*2+.5,0,1) * 255;
                            temp_result = spaces ? temp_result : temp_result_2;
                            result=ColorBgra.FromBgr((byte)(temp_result),(byte)(temp_result),(byte)(temp_result));
                            break;
                        case Space_Mode.Cut:
                            temp_result = spaces ? Math.Round(255 * final_gradient) : (gradient >= 0 ? 255 : 0);
                            result=ColorBgra.FromBgr((byte)(temp_result),(byte)(temp_result),(byte)(temp_result));
                            break;
                            default: 
                            temp_result = Math.Round(255 * final_gradient);
                            result=ColorBgra.FromBgra((byte)(temp_result),(byte)(temp_result),(byte)(temp_result),(byte)(spaces ? 255 : 0));
                        break;
                        }
                        break;
                    }
                    d_r += (double)(result.R);
                    d_g += (double)(result.G);
                    d_b += (double)(result.B);
                    d_a += (double)(result.A);
                }
            }
            d_r /= (double)(windows_count);
            d_g /= (double)(windows_count);
            d_b /= (double)(windows_count);
            d_a /= (double)(windows_count);
            r = (int)(Math.Round(d_r));
            g = (int)(Math.Round(d_g));
            b = (int)(Math.Round(d_b));
            a = (int)(Math.Round(d_a));
            dst[x,y] = ColorBgra.FromBgra((byte)(b),(byte)(g),(byte)(r),(byte)(a));
        }
    }
}
enum Random_Repetition_Mode{
    All,
    Cut_Periodic,
    Cut_Continuous,
    Periodic_Continuous
}

enum CS_Mode{
    Grayscale,
    Duotone,
    RGB_Random,
    HSV_Random
}

enum Space_Mode{
    Alpha,
    Cut,
    Gradient
}

enum Sym_Mode{
    None,
    A,
    B,
}

 

 

G'MIC-QT

Spoiler
#@cli rep_randgradbar : eq. to 'rep_random_gradient_bars' : (+)
rep_randgradbar:rep_random_gradient_bars $*
#@cli rep_random_gradient_bars: width>0,spacing>0,-360<=_angle<=360,-90<_skew_angle<90,-1<=_pos_x<=1,-1<=_pos_y<=1,_sublevel>=0,_gradient_shift,_gradient_mul_a,gradient_mul_b,_bar_modulo={ -1=random | 0=cut | 1=periodic | 2=continuous },_random_modulo_out={ 0=cut_and_periodic | 1=cut_and_continuous | 2=periodic_and_continuous },_gradient_color={ 0=B&W | 1=Duotone | 2=Rand-RGB | 3=Rand-HSV },_space_color={ 0=Alpha | 1=Binary Duotone | 2=Gradient Duotone },_symmetry_mode={ 0=none | 1=sym_a | 2=sym_b },_inversion_mode={ 0=n/a | 1=random-inverse | 2=complete-inverse},_bar_hex_rgb_color_a,_bar_hex_rgb_color_b : width>0,spacing>0,-360<=_angle<=360,-90<_skew_angle<90,-1<=_pos_x<=1,-1<=_pos_y<=1,_sublevel>=0,_gradient_shift,_gradient_mul_a,gradient_mul_b,_bar_modulo={ -1=random | 0=cut | 1=periodic | 2=continuous },_random_modulo_out={ 0=cut_and_periodic | 1=cut_and_continuous | 2=periodic_and_continuous },_gradient_color={ 0=B&W | 1=Duotone | 2=Rand-RGB | 3=Rand-HSV },_space_color={ 0=Alpha | 1=Binary Duotone | 2=Gradient Duotone },_symmetry_mode={ 0=none | 1=sym_a | 2=sym_b },_inversion_mode={ 0=n/a | 1=random-inverse | 2=complete-inverse},red_1,green_1,blue_1,red_2,green_2,blue_3
#@cli : Create image filled with random bars.
#@cli :
#@cli : (eq. to 'rep_randgradbar')
rep_random_gradient_bars:
skip ${3=0},${4=0},${5=0},${6=0},${7=1},${8=0},${9=1},${10=100},${11=-1},${12=},${13=0},${14=0},${15=0},${16=0},${17=000000},${18=ffffff}
check "(abs($4)<90)&&((narg($*)==22)||(narg($*)==18))"

sub={abs($7)+1}

if narg(${17--1})==2
 color_a=${rep_hex2int8\ $17}
 color_b=${rep_hex2int8\ $18}
else
 color_a=${17-19}
 color_b=${20-22}
fi

repeat $! l[$>]
 ow={w}
 oh={h}
 {w*$sub},{h*$sub},1,{$13?4:2},"*begin(
   const ww=w-1;
   const hh=h-1;
   const sd=max(ww,hh)/min(ww,hh);
   const sx=ww>hh?sd:1;
   const sy=ww>hh?1:sd;
   const pyth_img=sqrt(ww^2+hh^2);
   const ww_div_sx=ww/sx;
   const hh_div_sy=hh/sy;
   const cx=ww/2;
   const cy=hh/2;
   const ox=cx-(ww*-$5);
   const oy=cy-(hh*$6);
   const skew_ang=-($4/180)*pi;
   const mdist=tan(skew_ang)*pyth_img;
   const ang=-($3/180)*pi;
   const cos_ang=cos(ang);
   const sin_ang=sin(ang);
   const cut_ang=atan2(cy,cx);
   const cut_ang2=pi-cut_ang;
   const symmetry_mode=$15%3;
   const inversion_mode=($16+2)%3;
   
   "${is_percent\ $1}"?(
    const bar_width=max("$sub",round((abs($1)*pyth_img/4)));
   ):(
    const bar_width=max("$sub",round(abs($1)*"$sub"));
   );
   "${is_percent\ $2}"?(
    const space_width=abs($2)>0?max("$sub",round((abs($2)*pyth_img/4)));
   ):(
    const space_width=round(abs($2)*"$sub");
   );
   const total_width=bar_width+space_width;
   const half_total_width=total_width>1?int(total_width/2);

   (bar_width==1&&space_width<2)?(
    const spacing=space_width>0?.5:0;
    abs(space_width)?(calc_spacing()=int(point_x)%2?1;):(calc_spacing()=1;);
   ):(
    const spacing=1-(space_width/(total_width-1));
    calc_spacing()=abs(1-fmod(point_x,total_width)/total_width-.5)*2<=spacing;
   );

   rot_x(a,b)=a*cos_ang-b*sin_ang;
   rot_y(a,b)=a*sin_ang+b*cos_ang;
   fmod(a,b)=a-b*floor(a/b);
   fmod_cont(a,b)=floor(a/b)%2?b-fmod(a,b):fmod(a,b);
   fcut(a,b)=(cut(a,-b,b)+b)/2;

   const number_of_bars=ceil(sqrt(ww^2+hh^2)/total_width);
   const shift_bars=int(number_of_bars/2);
  
   symmetry_mode==1?(calc_bar()=(-1*abs(floor(point_x/total_width))+shift_bars)%number_of_bars;):
   symmetry_mode==2?(calc_bar()=(abs(floor(point_x/total_width))+shift_bars)%number_of_bars;):
                    (calc_bar()=(floor(point_x/total_width)+shift_bars)%number_of_bars;);
  
   v_mult=expr('u($9,$10)',number_of_bars,1,1,1);
   $8!=0?v_shift=expr('u(-$8,$8)',number_of_bars,1,1,1):v_shift=vectornumber_of_bars(0);
   
   v_use_invert=expr('round(u(0,1))',number_of_bars,1,1,1);
   inversion_mode==1?(v_use_invert=vectornumber_of_bars(0);):(
   inversion_mode==2?(v_use_invert=vectornumber_of_bars(1);););
  
   const use_only_one_mode=$11>=0;

   use_only_one_mode?(
    const modulo_out=$11%3;
    v_modulo_mode=vectornumber_of_bars(modulo_out);
   ):(
    narg($12)?(
     const modulo_out=$12%3;    
     modulo_out==0?(v_modulo_mode=expr('round(u(0,1))',number_of_bars,1,1,1);):
     modulo_out==1?(v_modulo_mode=expr('round(u(0,1))*2',number_of_bars,1,1,1);):            
                   (v_modulo_mode=expr('round(u(0,1))+1',number_of_bars,1,1,1););
    ):(
     v_modulo_mode=expr('round(u(0,2))',number_of_bars,1,1,1);
    );
   );

   rgb2hsv(a)=(
    R=a[0];
    G=a[1];
    B=a[2];
    M = max(R,G,B);
    C = M - min(R,G,B);
    H = 60*(C==0?0:M==R?((G - B)/C)%6:M==G?(B - R)/C + 2:(R - G)/C + 4);
    S = M<=0?0:C/M;
    [H,S,M/255];
   );

   ($14||$13==1)?(
    color_a=["$color_a"];
    color_b=["$color_b"];
    $13==3?(
     color_a=rgb2hsv(color_a);
     color_b=rgb2hsv(color_b);
    );
   ); 
   
   const bc=$13%4; #bc==bar color mode#
   const sc=$14%3; #sc==space color mode#

   bc==3?(
    v_hue=expr('u(0,360)',number_of_bars,1,1,1);
    sc==2?(
     calc_gradient()=spaces?[v_hue[bar],1,final_gradient,255]:[lerp(color_b,color_a,cut(gradient*2+.5,0,1)),255];
    ):
    sc==1?(
     calc_gradient()=spaces?[v_hue[bar],1,final_gradient,255]:[gradient>=0?color_a:color_b,255];
    ):(
     calc_gradient()=[v_hue[bar],1,final_gradient,255*spaces];
    );
   ):
   bc==2?(
    v_rgb_r=expr('u(0,255)',number_of_bars,1,1,1);
    v_rgb_g=expr('u(0,255)',number_of_bars,1,1,1);
    v_rgb_b=expr('u(0,255)',number_of_bars,1,1,1);
    sc==2?(
     calc_gradient()=spaces?[final_gradient*v_rgb_r[bar],final_gradient*v_rgb_g[bar],final_gradient*v_rgb_b[bar],255]:[lerp(color_b,color_a,cut(gradient*2+.5,0,1)),255];
    ):
    sc==1?(
     calc_gradient()=spaces?[final_gradient*v_rgb_r[bar],final_gradient*v_rgb_g[bar],final_gradient*v_rgb_b[bar],255]:[gradient>=0?color_a:color_b,255];
    ):(
     calc_gradient()=[final_gradient*v_rgb_r[bar],final_gradient*v_rgb_g[bar],final_gradient*v_rgb_b[bar],255*spaces];
    );
   ):
   bc==1?(
    sc==2?(
     calc_gradient()=spaces?[lerp(color_a,color_b,final_gradient),255]:[lerp(color_b,color_a,cut(gradient*2+.5,0,1)),255];
    ):
    sc==1?(
     calc_gradient()=spaces?[lerp(color_a,color_b,final_gradient),255]:[gradient>=0?color_a:color_b,255];
    ):(
     calc_gradient()=[lerp(color_a,color_b,final_gradient),255*spaces];
    );
   ):(
    sc==2?(
     calc_gradient()=spaces?[final_gradient,255]:[cut(gradient*2+.5,0,1),255];
    ):
    sc==1?(
     calc_gradient()=spaces?[final_gradient,255]:[gradient>=0,255]
    ):(
     calc_gradient()=[final_gradient,255*spaces];
    );
   );
  );

  initial_x=(x-ox)/ww*sx;
  initial_y=(y-oy)/hh*sy;
  gradient=-rot_y(initial_x,initial_y)*hh_div_sy/pyth_img;
  point_x=rot_x(initial_x,initial_y)*ww_div_sx+gradient*mdist+half_total_width;
  bar=calc_bar();
  spaces=calc_spacing();
  new_gradient=gradient*v_mult[bar]+v_shift[bar];
  use_modulo_out=v_modulo_mode[bar];
  use_modulo_out==2?(final_gradient=v_use_invert[bar]?1-fmod_cont(new_gradient,1):fmod_cont(new_gradient,1);):
  use_modulo_out==1?(final_gradient=v_use_invert[bar]?1-fmod(new_gradient,1):fmod(new_gradient,1);):
                    (final_gradient=v_use_invert[bar]?1-fcut(new_gradient,1):fcut(new_gradient,1););
  calc_gradient();
  "
  rm..
  if $13==3 hsv2rgb. fi
  if $sub!=1 r. $ow,$oh,100%,100%,5 fi
endl done

 

 

Edited by Reptillian
Now featuring anti-aliasing!
  • Like 2
  • Upvote 2

G'MIC Filter Developer

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...