Script Exchange - RealWorld forums

Log-in or register.

Script Exchange

Post your scripts, and find some more
___xed___
on September 21st 2013

I hope users will post various scripts here to enhance the general awesomeness of the RealWorld applications suite and help each other.

Following is a template (for ease of browsing) to post scripts.

Description: describe what the script does.

Code:
Configuration (optional)

place config script here. Using a space before lines makes a codeblock.

Execution

place main script here.

Notes: (optional) special usage instructions, variable descriptions, or comments etc.

Scope: (optional, recommended) whether the script only works with certain RW apps, or works with selection masks, or affects all layers, or needs plugin(s) etc.

Download:(optional, recommended) the script as a downloadable RWcommands file.
Preview (add a preview only if necessary, otherwise the page might take a long time to load in case of too many images)

PAEz
on October 30th 2013

Got tired of having to put a space at the beginning of ever line for code so here's a bookmarklet to do it for you....
http://jsbin.com/ovazew/2
...go to that page and drag the link on it to your bookmarks bar or where ever.
Select the text to indent, then click on the bookmark. Make sure on the first line you select from the very beginning of the line.

Only tested in Chrome on Windows.

If you feel like editing the code for it, then click the edit button on the right and the code for the bookmarklet is in the JS tab, there's code in the html tab to do the conversion. Just click Run JS on the right to create the link. The links title is in the html near the top. And dont remove the //noprotect on the first line, thats a JsBin thing.

PAEz
on October 31st 2013

Congrats on the new section, it looks great!
You never want a dead looking part of a forum and you've fleshed it out and organised it lovely.
Good stuff!

Oh and thanks for doing mine :-)

Small Samson
on July 30th 2018

Code:
Execution

//  _______
// |       |                    _ _
// |_______|___   ___ _ _ _ ___| | |___ ___ _ _ _ ___ ___ _ _
// |           | |___| | | |_  | | |___|_  | | | |___| _ | | |
// |___ _______| |___|_|_|_|_|_|_|_|___|_|_|_|_|_|___|___|_|_|
//     |       |
//     |_______|  Alpha-map generator
//                _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
//               |                                           |
//                 Variables:
//               |                                           |
var n=             true
//               | If true, some pixels will be random.      |
//                 If false, they will all be interpolated.
//               |                                           |
var s=             0
//               | Smoothness. Increasing by 1 halves the    |
//                 chance of a pixel being random. Increases
//               | by 1 each pass. 0 is 50% on the first     |
//                 pass.
//               |                                           |
var t=             .5
//               | Chance that a random pixel will be on,    |
//                 out of 1.
//               |                                           |
var r=             false
//               | If true, all pixels of a different value  |
//                 than surrounding ones will be switched.
//               |                                           |
var k=             0
//               | Maximum number of neighboring pixels of   |
//                 the same value for a pixel to be
//               | switched. Higher values take much longer. |
//                 Maximum is 3 to avoid an infinite loop.
//               |                                           |
//                 Note: Biggest possible area of 2^n+1 x
//               | 2^n+1 will be filled.                     |
//
//               |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|
//
s=Math.pow(2,s)
if(k>3) k=3;
var i=Document.RasterImage;
var x=0,y=0;
var p=0;
if(i.sizeX<i.sizeY) p=i.sizeX;
else p=i.sizeY;
p=Math.pow(2,Math.floor(Math.log(p-1)/Math.log(2)));
var q=1;
var c=0,v=0;
if(n){
i.setPixelAlpha(0,0,0,0,(Math.random()<t)*255);
i.setPixelAlpha(0,p,0,0,(Math.random()<t)*255);
i.setPixelAlpha(p,0,0,0,(Math.random()<t)*255);
i.setPixelAlpha(p,p,0,0,(Math.random()<t)*255);
}
else{
i.setPixelAlpha(0,0,0,0,0);
i.setPixelAlpha(0,p,0,0,255);
i.setPixelAlpha(p,0,0,0,255);
i.setPixelAlpha(p,p,0,0,0);
}
while(p>1){
p=p/2;
s=s*2;
q=q*2;
for(x=0;x<=q;x=x+1)for(y=1;y<q;y=y+2){
if(n){if(Math.random()*s<1) c=1;
else c=0;}
else c=0;
if(c==1) i.setPixelAlpha(x*p,y*p,0,0,(Math.random()<t)*255);
else i.setPixelAlpha(x*p,y*p,0,0,i.getPixelAlpha(x*p,(y+Math.floor(Math.random()*2)*2-1)*p,0,0));
}
for(x=1;x<q;x=x+2)for(y=0;y<q+1;y=y+1){
if(n){if(Math.random()*s<1) c=1;
else c=0;}
else c=0;
if(c==1) i.setPixelAlpha(x*p,y*p,0,0,(Math.random()<t)*255);
else i.setPixelAlpha(x*p,y*p,0,0,i.getPixelAlpha((x+Math.floor(Math.random()*2)*2-1)*p,y*p,0,0));
}
for(x=1;x<q;x=x+2)for(y=1;y<q;y=y+2){
if(n){if(Math.random()*s<1) c=1;
else c=0;}
else c=0;
if(c==1) i.setPixelAlpha(x*p,y*p,0,0,(Math.random()<t)*255);
else{
v=i.getPixelAlpha((x-1)*p,y*p,0,0)+i.getPixelAlpha((x+1)*p,y*p,0,0)+i.getPixelAlpha(x*p,(y-1)*p,0,0)+i.getPixelAlpha(x*p, (y+1)*p,0,0)+i.getPixelAlpha((x-1)*p,(y-1)*p,0,0)+i.getPixelAlpha((x-1)*p,(y+1)*p,0,0)+i.getPixelAlpha((x+1)*p,(y- 1)*p,0,0)+i.getPixelAlpha((x+1)*p,(y+1)*p,0,0);
if(v>255*5-1) i.setPixelAlpha(x*p,y*p,0,0,255)
else if(v<255*3+1) i.setPixelAlpha(x*p,y*p,0,0,0)
else i.setPixelAlpha(x*p,y*p,0,0,(Math.random()<.5)*255)
}
}
}
while(r==true){
r=false;
var a=new Array();
for(x=1;x<q;x++){
a.push(new Array());
for(y=1;y<q;y++){
a[x-1].push(i.getPixelAlpha(x,y,0,0));
v=i.getPixelAlpha(x-1,y,0,0)+i.getPixelAlpha(x+1,y,0,0)+i.getPixelAlpha(x,y-1,0,0)+i.getPixelAlpha(x,y +1,0,0)+i.getPixelAlpha(x-1,y-1,0,0)+i.getPixelAlpha(x-1,y+1,0,0)+i.getPixelAlpha(x+1,y-1,0,0)+i.getPixelAlpha(x+1,y +1,0,0);
if(i.getPixelAlpha(x,y,0,0)==0 && v>255*(8-k)-1){
a[x-1][y-1]=255;
r=true;
}
if(i.getPixelAlpha(x,y,0,0)==255 && v<255*k+1){
a[x-1][y-1]=0;
r=true;
}
}
}
for(x=1;x<q;x++)for(y=1;y<q;y++) i.setPixelAlpha(x,y,0,0,a[x-1][y-1]);
if(k==0)r=false;
}

Notes: In the code

Scope: Generates a somewhat random alpha map in the largest area of 2^n+1 x 2^n+1 that can fit in the image. For example: 9x9, 17x17, 33x33, 65x65, etc.

Preview: (with more detailed explanation) imgur.com/a/ieFb5XS

Page views: 4262       Posts: 4      
Vista & Win 7 icons
Select background
What about ICL files?