Skip to main content
Participant
December 10, 2007
Question

Random values for filters

  • December 10, 2007
  • 2 replies
  • 393 views
I'm trying to write a script that will generate random values for the filter parameters everytime it is called. I'm new to java script and I'm just trying to get started with the examples from the scripts folder. Does anyone know how to fix this script to get random values for the Mosaic filters?
Thanks in advance.

// Copyright 2002-2007. Adobe Systems, Incorporated. All rights reserved.
// This script demonstrates how you can use the action manager
// to execute the Mosaic Tiles filter.

// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop

// in case we double clicked the file
app.bringToFront();

// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line

if (!app.documents.length > 0) { // open sample file if no document is opened.
var strtRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var docRef = app.documents.add(320, 240, 72, null, NewDocumentMode.RGB, DocumentFill.WHITE);
app.preferences.rulerUnits = strtRulerUnits;
}

mosaicTiles( 12, 3, (15*Math.random()) );

function mosaicTiles( inTileSize, inWidth, inLighten )
{
// Get ID's for the related keys
var keyTileSizeID = charIDToTypeID( "TlSz" );
var keyGroutWidthID = charIDToTypeID( "GrtW" );
var keyLightenGroutID = charIDToTypeID( "LghG" );
var eventMosaizID = charIDToTypeID( "MscT" );

var filterDescriptor = new ActionDescriptor();
filterDescriptor.putInteger( keyTileSizeID, inTileSize );
filterDescriptor.putInteger( keyGroutWidthID, inWidth );
filterDescriptor.putInteger( keyLightenGroutID, inLighten );

executeAction( eventMosaizID, filterDescriptor );
}
This topic has been closed for replies.

2 replies

Inspiring
February 25, 2008
The code you posted only uses a random value for the grout contrast. You could do something like this to make all three arguments ramdom.

var inTileSize = Math.round(98*Math.random())+2;// integer between 2-100
var inWidth = Math.round(14*Math.random())+1;// integer between 1-15
var inLighten = Math.round(10*Math.random());// integer between 0-10

mosaicTiles( inTileSize, inWidth, inLighten );
Participant
February 23, 2008
Anyone out there that can give me a hand with this random value in scripts?
Thanks
Known Participant
February 25, 2008
casey_farina@adobeforums.com wrote:
> Anyone out there that can give me a hand with this random value in scripts?

There is a Math.random() function. I would start there.

-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com