• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Random circles

Advocate ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

I would like to create white circles in my document
the size of the circle and the position must be random

an example of what I'm looking for I used a black background
to see better what I'm looking for.

 

Schermata 2020-04-04 alle 12.44.00.png

TOPICS
Actions and scripting

Views

3.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 04, 2020 Apr 04, 2020
The below code produces something like this, to amend the number, colors and radii of the circles amend the line
createCircle(Math.random()*theWidth, Math.random()*theHeight, 10+Math.random()*90, Math.random()*255, Math.random()*255, Math.random()*255);
Screenshot 2020-04-04 at 14.25.27.png
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var theWidth = myDoc.width;
var theHeight = myDoc.height;
for (var m = 0; m < 20; m++){
createCircle(Math.random()*theWidth, Math.random()*theHeight, 10+Math.random()*90, Math.random()*255
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

So what is the question or problem? 

 

You could use a randomized Brush with Scattering or a Script. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

if you can a ui dialog
if it is too much a script is also fine.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

What do you mean? 

Please elaborate. 

And if you want to pursue a Scripting-approach: Do you have any JavaScript-experience? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

The below code produces something like this, to amend the number, colors and radii of the circles amend the line
createCircle(Math.random()*theWidth, Math.random()*theHeight, 10+Math.random()*90, Math.random()*255, Math.random()*255, Math.random()*255);
Screenshot 2020-04-04 at 14.25.27.png
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var theWidth = myDoc.width;
var theHeight = myDoc.height;
for (var m = 0; m < 20; m++){
createCircle(Math.random()*theWidth, Math.random()*theHeight, 10+Math.random()*90, Math.random()*255, Math.random()*255, Math.random()*255);
};
};
//////////////////
function createCircle (theCenterX, theCenterY, theRadius, theR, theG, theB) {
var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
var idmake = stringIDToTypeID( "make" );
var desc15 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var ref4 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref4.putClass( idcontentLayer );
desc15.putReference( idnull, ref4 );
var idusing = stringIDToTypeID( "using" );
var desc16 = new ActionDescriptor();
var idtype = stringIDToTypeID( "type" );
var desc17 = new ActionDescriptor();
var idcolor = stringIDToTypeID( "color" );
var desc18 = new ActionDescriptor();
var idred = stringIDToTypeID( "red" );
desc18.putDouble( idred, theR );
var idgrain = stringIDToTypeID( "grain" );
desc18.putDouble( idgrain, theG );
var idblue = stringIDToTypeID( "blue" );
desc18.putDouble( idblue, theB );
var idRGBColor = stringIDToTypeID( "RGBColor" );
desc17.putObject( idcolor, idRGBColor, desc18 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc16.putObject( idtype, idsolidColorLayer, desc17 );
var idshape = stringIDToTypeID( "shape" );
var desc19 = new ActionDescriptor();
var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );
desc19.putInteger( idunitValueQuadVersion, 1 );
var idtop = stringIDToTypeID( "top" );
desc19.putUnitDouble( idtop, idpixelsUnit, theCenterY - theRadius );
var idleft = stringIDToTypeID( "left" );
desc19.putUnitDouble( idleft, idpixelsUnit, theCenterX - theRadius );
var idbottom = stringIDToTypeID( "bottom" );
desc19.putUnitDouble( idbottom, idpixelsUnit, theCenterY + theRadius );
var idright = stringIDToTypeID( "right" );
desc19.putUnitDouble( idright, idpixelsUnit, theCenterX + theRadius );
var idellipse = stringIDToTypeID( "ellipse" );
desc16.putObject( idshape, idellipse, desc19 );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
desc15.putObject( idusing, idcontentLayer, desc16 );
var idlayerID = stringIDToTypeID( "layerID" );
desc15.putInteger( idlayerID, 3 );
executeAction( idmake, desc15, DialogModes.NO );
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

This would work on a Smart Object. 
Screenshot 2020-04-05 at 19.01.31.pngScreenshot 2020-04-05 at 19.02.05.png
// distributes smart object-copies on the canvas;
// 2020, use it at your own risk;
#target photoshop
var checksOut = true;
checksOut = checkPhotoshop(checksOut);
// do the operation if everything has checked out;
if (checksOut == true) {
app.activeDocument.suspendHistory("stuff", "main()")
};
////////////////////////////////////
function main() {
var myDocument = app.activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// change the resolution;
var theResolution = myDocument.resolution;
myDocument.resizeImage(null, null, 72, ResampleMethod.NONE);
var theWidth = myDocument.width;
var theHeight = myDocument.height;
// the duplication etc;
app.togglePalettes();
var myLayer = smartify(myDocument.activeLayer);
var theID = getLayerId(myLayer);
var theBounds = myLayer.bounds;
var theHorMiddle = theBounds[0]+(theBounds[2]-theBounds[0])/2;
var theVerMiddle = theBounds[1]+(theBounds[3]-theBounds[1])/2;
for (var m = 0; m < 20; m++) {
// the actual duplication and rotation;
var horizontalOffset = Math.random()*theWidth - theHorMiddle;
var verticalOffset = Math.random()*theHeight - theVerMiddle;
var thePercentage = 50 + (Math.random() * 50);
// move, rotate and scale in one go;
var thePlacedLayer = duplicateMoveRotateScale (myLayer, theID, horizontalOffset, verticalOffset, thePercentage, thePercentage, Math.random()*360);
};
myLayer.visible = false;
// reset;
app.togglePalettes();
myDocument.resizeImage(null, null, theResolution, ResampleMethod.NONE);
app.preferences.rulerUnits = originalRulerUnits;
};
////////////////////////////////////
////// duplicate layer and move, rotate and scale it //////
function duplicateMoveRotateScale (theLayer, theID, theX, theY, theScaleX, theScaleY, theRotation) {
selectLayerByID(theID,false);
try{
var idTrnf = charIDToTypeID( "Trnf" );
var desc10 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
ref6.putIdentifier( charIDToTypeID( "Lyr " ), theID );
/* ref6.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );*/
desc10.putReference( idnull, ref6 );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc10.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc11 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idHrzn, idPxl, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idVrtc, idPxl, theY );
var idOfst = charIDToTypeID( "Ofst" );
desc10.putObject( idOfst, idOfst, desc11 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc10.putUnitDouble( idWdth, idPrc, theScaleX );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc10.putUnitDouble( idHght, idPrc, theScaleY );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc10.putUnitDouble( idAngl, idAng, theRotation );
var idIntr = charIDToTypeID( "Intr" );
var idIntp = charIDToTypeID( "Intp" );
var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
desc10.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
var idCpy = charIDToTypeID( "Cpy " );
desc10.putBoolean( idCpy, true );
executeAction( idTrnf, desc10, DialogModes.NO );
var thisCopy = app.activeDocument.activeLayer;
return thisCopy
} catch (e) {}
};
////// the check-functions largely thanks to kasyan servetsky //////
function checkPhotoshop(checksOut) {
if (app.documents.length == 0) {
alert("no documents are open. please open a document and try again");
checksOut = false
};
var theLayers = getSelectedLayersIdxAndName();
if (theLayers == undefined) {
alert ("please select one layer");
return false};
var theKinds = ["LayerKind.BLACKANDWHITE", "LayerKind.BRIGHTNESSCONTRAST", "LayerKind.CHANNELMIXER", "LayerKind.COLORBALANCE", "LayerKind.CURVES", "LayerKind.EXPOSURE",
"LayerKind.GRADIENTMAP", "LayerKind.HUESATURATION", "LayerKind.INVERSION", "LayerKind.LAYER3D", "LayerKind.LEVELS", "LayerKind.PHOTOFILTER", "LayerKind.POSTERIZE",
"LayerKind.SELECTIVECOLOR", "LayerKind.THRESHOLD", "LayerKind.VIBRANCE"];
for (var n = 0; n < theKinds.length; n++) {
if (app.activeDocument.activeLayer.kind == theKinds[n]) {
alert ("layer is ineligible");
checksOut = false;
}
};
return checksOut
};
// by mike hale, via paul riggott;
function getLayerId(theLayer){
app.activeDocument.activeLayer = theLayer;
//Assumes activeDocument and activeLayer
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
d = executeActionGet(ref);
return d.getInteger(charIDToTypeID('LyrI'));
};
// based on code by mike hale, via paul riggott;
function selectLayerByID(id,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
////// function to smartify if not //////
function smartify (theLayer) {
// make layers smart objects if they are not already;
if (theLayer.kind != LayerKind.SMARTOBJECT) {
activeDocument.activeLayer = theLayer;
var id557 = charIDToTypeID( "slct" );
var desc108 = new ActionDescriptor();
var id558 = charIDToTypeID( "null" );
var ref77 = new ActionReference();
var id559 = charIDToTypeID( "Mn " );
var id560 = charIDToTypeID( "MnIt" );
var id561 = stringIDToTypeID( "newPlacedLayer" );
ref77.putEnumerated( id559, id560, id561 );
desc108.putReference( id558, ref77 );
executeAction( id557, desc108, DialogModes.NO );
return activeDocument.activeLayer
};
return theLayer
};
////// get array of arrays of index, name //////
function getSelectedLayersIdxAndName(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count;
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
};
}
}else{
return /*
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
};*/
};
////////////////////////////////////
var theArray = new Array;
var theIDs = new Array;
for (var m = 0; m < selectedLayers.length; m++) {
var thisIndex = selectedLayers[m];
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Lyr "), thisIndex);
var layerDesc = executeActionGet(ref);
var thisID = layerDesc.getInteger(stringIDToTypeID("layerID"));
var theName = layerDesc.getString(stringIDToTypeID("name"));
var theVisibility = layerDesc.getInteger(stringIDToTypeID("visible"));
// is visible;
if (theVisibility == true) {
theIDs.push ([thisID, theName])
}
};
////////////////////////////////////
return theIDs
////////////////////////////////////
};
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

This is an example of a Brish randomized Shape Dynamics and Scattering applied to a straight Path. 

Screenshot 2020-04-04 at 13.30.28.png

Screenshot 2020-04-04 at 13.30.57.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

I have tried this method m is not good for me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Could you elaborate without having to be asked to each time? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Perfect what I was looking for
you are a great.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

A question
if instead of ellipse
I would like to put polygon what I have to change.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

You’d need to change the body of the function createCircle. 

I would recommend you record the creation of a Shape Layer of the polygon you want and exchange the pertinent code in the function with that. 

Naturally you would need to fill in the correct arguments at the pertinent places again (the coordinates, colors, …). 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

My problem is how to configure these 4 lines
that I don't know how

 

Schermata 2020-04-04 alle 19.44.24.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

I suspect desc597 describes the center and desc598 a point on a circumscribed circle, so one of the two values unchanged and the other offset by the radius might work. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Thanks
always kind

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Hi

 

I love C_P's scripting solution!

 

If you have Illustrator, though, it's super simple.

  1. Draw your shape, either the circle or the polygon or anything else.
    Drag it into symbols to make a symbol.
    Delete the shape from the artboard
    40.png
  2. Use the Symbol Sprayer tool to spray a symbol set.
    Use the Symbol Sizer tool to make the shapes larger (add Option to do the opposite)
    Use the Symbol Shifter tool to scoot them around.
    41.png
  3. If you start with a circle and then want the polygon, create a new symbol and use the replace symbol command to update wherever the symbol is in use.

 

If you think you will have edits and customization, you might want to use Illustrator for this project.

 

~ Jane

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

Come to think of it I tinkered with a Script a couple years ago to distribute Smart Object instances based on a Channel. 

Screenshot 2020-04-05 at 13.30.55.pngScreenshot 2020-04-05 at 13.31.30.png

Using Smart Objects allows for summary editing later on. 

treesConfettiTest4_Scr.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

Yea, I do a lot of images using scripts to place random shapes. Mine have gradients that are applied by sampling a reference layer.

Script talk-031.jpgScript talk-032.jpgScript talk-033.jpgScript talk-037.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

I see a Ghost, a Man, a Dog and a Fish.  You did create a colorful Rorschach test Chuck.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

Not fish, but turtle.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

It's a turtle. Yes, I created these from reference photos. One of the things I like doing, now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

Image #2 looks a lot like you, Chuck. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

It is, Jane.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

These are really good, Chuck. I've seen some of your other images you've created with scripts on Behance, but I hadn't seen these before. Is it your child, your dog, and your turtle? Don't you have a horse? 

 

I'm in awe!

 

~ Jane

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

LATEST

The turtle was taken from a pier in Florida. The child is the daughter of a friend. The dogs are mine, but long gone. Yes, I still have a horse.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines