-
Notifications
You must be signed in to change notification settings - Fork 0
/
bingo.jsx
135 lines (105 loc) · 3.94 KB
/
bingo.jsx
1
displayDialogs = DialogModes.NO; // function to absolute position a layer. Assumes the layer is cetered. function pos(layer, num, num2) { startRulerUnits = app.preferences.rulerUnits, app.preferences.rulerUnits = Units.INCHES; var width = 8.5, height = 11, pos = layer.bounds, left_x = parseFloat(pos[0], 10), top_y = parseFloat(pos[1], 10); layer.translate(num-(left_x),num2-(top_y)); preferences.rulerUnits = startRulerUnits; }for (var r = 0; r < 10; r++) { var BG = "G";// LayerOrder.js// For Photoshop 7// Scrambles all layers in the foreground file, without user input// This will damage anything with layer sets, effects layers, etc.if (documents.length > 0){ // Count number of layers in document and collect layer names in array. var layersNum = activeDocument.layers.length; if (layersNum > 2) { // Needs at least two movable layers to be useful layersAll = activeDocument.layers; // Target array layersList contains names of every layer except background layersList = new Array(); var o=0; for (var i=0;i<layersNum;i++) { if (layersAll[i].isBackgroundLayer==false || layersAll[i] == "LayerSet "+BG) { layersList[o] = layersAll[i].name; o++; //alert(layersList); } } // For a more effective shuffle: fisherYates(layersList); // For a less effective shuffle: // layersList = layersList.sort(arrayShuffle); // Use the shuffled array as a list of which layers to move to the top in turn. // This probably isn't efficient. lLl = layersList.length; for (var i=0 ; i < lLl ; i++) { var thisLayer = layersList[i]; activeDocument.activeLayer = activeDocument.layers[thisLayer]; activeDocument.activeLayer.moveToEnd(activeDocument); // This command will change in CS2 etc. to something like: // app.activeDocument.activeLayer.move(app.activeDocument.layers.ElementPlacement.PLACEATEND); } //alert ("Reordered "+lLl+" layers"); } else { alert ("Not enough layers to randomize"); }}else {alert ( "You must have at least one open document to run this script"); }var g = app.activeDocument.layerSets.getByName(BG);g.moveToEnd(activeDocument);// More effective shuffle: any layer is inserted above any other layer// F-Y function by Ashley Pond V: http://sedition.com/perl/javascript-fy.htmlfunction fisherYates ( myArray ) { var i = myArray.length; if ( i == 0 ) return false; while ( --i ) { var j = Math.floor( Math.random() * ( i + 1 ) ); var tempi = myArray[i]; var tempj = myArray[j]; myArray[i] = tempj; myArray[j] = tempi; }}// Less effective shuffle: any layer is inserted above any adjacent layer, // iterated /n/ times, which might be preferred in certain designs// function arrayShuffle(a,b) { return Math.round(Math.random()) - 0.5; }// Art Delano, http://www.cloudiness.com/// No copyright 2005: Swipe at your leisure, blame me for nothing. var layers = app.activeDocument.artLayers, length = layers.length, row = 4, column = 4, width = 1.875, height = 2.109, margin = .5, hgutter = 0, vgutter = 0, hshift = 0, h = 0,t = 0; //start the master loop, esch loop is a document // pos(layers[k], k * width , 0 ); for (k = 0; k < row; k++) { for(j = 0; j < column; j++){ if (j == 0 && k == 0) { pos( layers[t] , k* width + margin, k * height + margin + 1.3 ); } else { pos( layers[t] , j * width + margin, k * height + margin + 1.3 ); } t++ } } var jpegOptions = new JPEGSaveOptions();jpegOptions.quality = 10;var fold = "~/Desktop/bingo";app.activeDocument.saveAs(new File(fold + "/bingo_game " + r + ".jpg"), jpegOptions);}