Easy way to create repeating custom radial gradient?

I want to create a simple repeating gradient for a Gradient Overlay effect in Photoshop. I had to manually create this:

Is there an easier way to make a repeating pattern by designing a small one then extrapolating from it? If there is no way to design a gradient like this in the Gradient Editor, is there a way to simulate it (with the style set as Radial)?

Answer

Create a new layer, and execute the following code as a script. It will create a new layer style with 0% fill and the new gradient as an overlay. The for-loop towards the bottom creates a 21-stop gradient in the foreground color. Every other stop alternates between opaque and transparent.

You can then save the gradient as a preset within the Layer Styles menu.

var idsetd = charIDToTypeID( "setd" );
    var desc120 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref29 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref29.putEnumerated( idLyr, idOrdn, idTrgt );
    desc120.putReference( idnull, ref29 );
    var idT = charIDToTypeID( "T   " );
        var desc121 = new ActionDescriptor();
        var idfillOpacity = stringIDToTypeID( "fillOpacity" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc121.putUnitDouble( idfillOpacity, idPrc, 0.000000 );
        var idLefx = charIDToTypeID( "Lefx" );
            var desc122 = new ActionDescriptor();
            var idScl = charIDToTypeID( "Scl " );
            var idPrc = charIDToTypeID( "#Prc" );
            desc122.putUnitDouble( idScl, idPrc, 100.000000 );
            var idGrFl = charIDToTypeID( "GrFl" );
                var desc123 = new ActionDescriptor();
                var idenab = charIDToTypeID( "enab" );
                desc123.putBoolean( idenab, true );
                var idMd = charIDToTypeID( "Md  " );
                var idBlnM = charIDToTypeID( "BlnM" );
                var idNrml = charIDToTypeID( "Nrml" );
                desc123.putEnumerated( idMd, idBlnM, idNrml );
                var idOpct = charIDToTypeID( "Opct" );
                var idPrc = charIDToTypeID( "#Prc" );
                desc123.putUnitDouble( idOpct, idPrc, 100.000000 );

                //Gradient Definition
                var idGrad = charIDToTypeID( "Grad" );
                        var desc34 = new ActionDescriptor();
                        var idNm = charIDToTypeID( "Nm  " );
                        desc34.putString( idNm, "Custom" );
                        var idGrdF = charIDToTypeID( "GrdF" );
                        var idGrdF = charIDToTypeID( "GrdF" );
                        var idCstS = charIDToTypeID( "CstS" );
                        desc34.putEnumerated( idGrdF, idGrdF, idCstS );
                        var idIntr = charIDToTypeID( "Intr" );
                        desc34.putDouble( idIntr, 4096.000000 );
                        var idClrs = charIDToTypeID( "Clrs" );
                            var list5 = new ActionList();
                                var desc35 = new ActionDescriptor();
                                var idType = charIDToTypeID( "Type" );
                                var idClry = charIDToTypeID( "Clry" );
                                var idFrgC = charIDToTypeID( "FrgC" );
                                desc35.putEnumerated( idType, idClry, idFrgC );
                                var idLctn = charIDToTypeID( "Lctn" );
                                desc35.putInteger( idLctn, 0 );
                                var idMdpn = charIDToTypeID( "Mdpn" );
                                desc35.putInteger( idMdpn, 50 );
                            var idClrt = charIDToTypeID( "Clrt" );
                            list5.putObject( idClrt, desc35 );
                                var desc38 = new ActionDescriptor();
                                var idType = charIDToTypeID( "Type" );
                                var idClry = charIDToTypeID( "Clry" );
                                var idFrgC = charIDToTypeID( "FrgC" );
                                desc38.putEnumerated( idType, idClry, idFrgC );
                                var idLctn = charIDToTypeID( "Lctn" );
                                desc38.putInteger( idLctn, 4096 );
                                var idMdpn = charIDToTypeID( "Mdpn" );
                                desc38.putInteger( idMdpn, 50 );
                            var idClrt = charIDToTypeID( "Clrt" );
                            list5.putObject( idClrt, desc38 );
                        desc34.putList( idClrs, list5 );

                        // Gradient Stops
                        var idTrns = charIDToTypeID( "Trns" );
                            var list6 = new ActionList();
                                // Create 21 stops
                                for (i = 0; i < 22; i++){
                                    var desc39 = new ActionDescriptor();
                                    var idOpct = charIDToTypeID( "Opct" );
                                    var idPrc = charIDToTypeID( "#Prc" );
                                    // Alternate opacity from 100 to 0 every other stop
                                    desc39.putUnitDouble( idOpct, idPrc, 100.000000 * ((i+1)%2) );
                                    var idLctn = charIDToTypeID( "Lctn" );
                                    // Distribute stops evenly from 0 to 4096
                                    desc39.putInteger( idLctn, 4096 * (i/20));
                                    var idMdpn = charIDToTypeID( "Mdpn" );
                                    // Set midpoint halfway between stops
                                    desc39.putInteger( idMdpn, 50 );
                                    var idTrnS = charIDToTypeID( "TrnS" );
                                    list6.putObject( idTrnS, desc39 );
                                }
                        desc34.putList( idTrns, list6 );
                var idGrdn = charIDToTypeID( "Grdn" );
                desc123.putObject( idGrad, idGrdn, desc124 );
                var idAngl = charIDToTypeID( "Angl" );
                var idAng = charIDToTypeID( "#Ang" );
                desc123.putUnitDouble( idAngl, idAng, 90.000000 );
                var idType = charIDToTypeID( "Type" );
                var idGrdT = charIDToTypeID( "GrdT" );
                var idLnr = charIDToTypeID( "Rdl " );
                desc123.putEnumerated( idType, idGrdT, idLnr );
                var idRvrs = charIDToTypeID( "Rvrs" );
                desc123.putBoolean( idRvrs, false );
                var idAlgn = charIDToTypeID( "Algn" );
                desc123.putBoolean( idAlgn, true );
                var idScl = charIDToTypeID( "Scl " );
                var idPrc = charIDToTypeID( "#Prc" );
                desc123.putUnitDouble( idScl, idPrc, 100.000000 );
                var idOfst = charIDToTypeID( "Ofst" );
                    var desc154 = new ActionDescriptor();
                    var idHrzn = charIDToTypeID( "Hrzn" );
                    var idPrc = charIDToTypeID( "#Prc" );
                    desc154.putUnitDouble( idHrzn, idPrc, 0.000000 );
                    var idVrtc = charIDToTypeID( "Vrtc" );
                    var idPrc = charIDToTypeID( "#Prc" );
                    desc154.putUnitDouble( idVrtc, idPrc, 0.000000 );
                var idPnt = charIDToTypeID( "Pnt " );
                desc123.putObject( idOfst, idPnt, desc154 );
            var idGrFl = charIDToTypeID( "GrFl" );
            desc122.putObject( idGrFl, idGrFl, desc123 );
        var idLefx = charIDToTypeID( "Lefx" );
        desc121.putObject( idLefx, idLefx, desc122 );
    var idLyr = charIDToTypeID( "Lyr " );
    desc120.putObject( idT, idLyr, desc121 );
executeAction( idsetd, desc120, DialogModes.NO );

Play around with the values, I think you’ll find it quite useful. Here’s a quick example:

enter image description here

Scripting a gradient with Illustrator is much more straightforward. But of course, you can’t manipulate (or animate, or…) the gradient inside of Photoshop. Save the following to a .js file and run through File > Scripts > Other Script...

// Create a color 
var startColor = new RGBColor();
startColor.red = 0;
startColor.green = 0;
startColor.blue = 0;

// Create a new gradient
// A new gradient always has 2 stops
var newGradient = app.activeDocument.gradients.add();
// Name the gradient to be the current time in POSIX
newGradient.name = new Date().getTime().toString();
newGradient.type = GradientType.RADIAL;

// Insert a number of intermediate stops. Here, 17.
for (i=0; i < 18; i += 1) {
   newGradient.gradientStops.add();
}

for (var i = 0; i < newGradient.gradientStops.length; i++){
    // Distribute each stop equally from 0 to 100
    newGradient.gradientStops[i].rampPoint = i * (100/(newGradient.gradientStops.length-1));
    // Each Midpoint is halfway to the next
    newGradient.gradientStops[i].midPoint = 50;
    // All colors are startColor
    newGradient.gradientStops[i].color = startColor;
    // Alternate the opacity between 0 and 100
    newGradient.gradientStops[i].opacity = ((i + 1) % 2) * 100;
}

It creates a gradient like this:
enter image description here

Attribution
Source : Link , Question Author : Keavon , Answer Author : Alex Blackwood

Leave a Comment