View Full Version : Pixelated - Javascript


byRo
01-29-2005, 10:43 AM
Following Doug's suggestion I'm posting here the script that I used to make the "punched-out" image (http://www.retouchpro.com/forums/showpost.php?p=80312&postcount=43) in Doug's "Pixelated" thread.

Some observations:
- Many times I find the "normal" method() syntax too unweildy and instead make a function from the ScriptListener output.
docRef.selection.select([[x,y], [x2,y], [x2,y2], [x, y2]], SelectionType.REPLACE, 0, false);
comes out as:
fnSELECT ( pxTOP_ , pxLEFT , pxBTOM , pxRGHT );
- I am trying to follow a naming convention as suggested by here (http://www.retouchpro.com/forums/showpost.php?p=77195&postcount=6) by Michael:
ly = Layer;
fn - Funcion;
db = Double precision number;
with user names in capitals, so you'll find:lyBASE, pxMAX_H, dcDOC etc......

Comments and suggestions most welcome - as always


byRo
01-29-2005, 10:59 AM
Replying to Danny's post (http://www.retouchpro.com/forums/showpost.php?p=80348&postcount=46) on the original thread:
If I may offer my "wishlist..."
* Selection based (to isolate what area got pixelated). Default = all.
* A variable that would control amount (or ~ %) of pixelation, e.g., 1 = a few random squares, 10 = lots of squaresI had thought of using a layer - but your suggestion of using an alpha channel would be more concise solution. Though not black a white - but greyscale where the lighter parts would increase the probability.
* Ability to choose size of squareThis should be the easiest part, but I haven't found a good way to do it yet!
* Squares isolated on a separate layer to which layer effects could be applied. The second version (to be posted) that I used here (http://www.retouchpro.com/forums/showpost.php?p=80346&postcount=44) does just that - although it takes a lot longer to run.

Thanks for the feedback!

byRo
01-30-2005, 01:15 PM
Here's the latest effort. (image) (http://www.retouchpro.com/forums/showthread.php?p=80530#post80530)
Not quite as clean-cut as I'd like it - but it works. :ditsy:
Apparently working with selections isn't that straightforward!
Had to use a pre-defined layer style ("byRo Tiles") to be able to do the bevel and emboss. :sad:

Any help or comments would be most welcome.


DannyRaphael
01-30-2005, 03:57 PM
It was instructive to see the line of code to apply the layer style within the .js. IMO you'll get a lot fewer implementation questions if you comment out that line (but include instructions within the script on "how" to utilize it).

Just let folks apply a LS of their choosing after the script runs.

Bottom line: Pretty slick.

byRo
01-31-2005, 03:33 AM
Danny, good to see it worked for you!

Just let folks apply a LS of their choosing after the script runs.But that was the whole problem..
I had to apply the style while I had an individual tile isolated. When I applied a bevel-and-emboss-type style after, the tiles becames pretty shapeless blobs. However you're right - not much good posting a script that won't work, will substitute.

I had to fight this program all the way:
- apparently a Selection can't be an object;
- after copying to a new layer the selection gets deselected;
- layer merges don't include layer styles, have to use merge visible;
- only way to apply bevel and emboss is by using a pre-defined style, can't define layer styles on the run;
- selection.transform doesn't work (at least not for PS 7.0), had to wriggle out using Edit>Transform on the layer.

If anybody has some experience with selections I'd be real glad to hear.

DannyRaphael
01-31-2005, 10:32 AM
I'm shooting in the dark here...

Does "- apparently a Selection can't be an object" = you can't do the script equivalent of Select > Save selection to create a named alpha channel which could (in theory) be repeatedly invoked via the .js equ. of Select > Load selection?

byRo
01-31-2005, 01:30 PM
I'm shooting in the dark here...A near miss!
I'll try and turn the lights on...
I had imagined that, with all the used-defined objects that javascript allows, I could simply write something like:
var slTILE = dcDOC.selectionand I'd have a nice little selection object to play with - but PS javascript didn't seem to agree on that.
The method you suggested will work fine (I hadn't thought of that), and if I need more than one selection I'll sure do it that way. This time I just needed to repeat the select line.

Just got a little disappointed that my cunning sly move didn't work!