So, here is another script. Since the XCom:Enemy Within game is going to be released soon, I though it would be nice to create a script that would make it easy to duplicate the distortion effect used in many places in the game.
Basically, it can create from .
Configuration:
Configuration.AddEditBox("stripes", "Stripe count", "", 10);
if (Context.ItemIndex+Context.ItemsRemaining == 0)
Configuration.AddSlider("phase", "Phase", "", 0, 99, 0);
Configuration.AddSlider("outline", "Outline width", "", 0, 100, 30);
Configuration.AddSlider("blur", "Blur strength", "", 0, 100, 30);
Execution:
var img = Document.RasterImage;
var phase = Context.ItemIndex+Context.ItemsRemaining == 0 ?
Configuration.phase*0.01 :
Context.ItemIndex/(1+Context.ItemIndex+Context.ItemsRemaining);
var stripes = Configuration.stripes;
var sx = img.sizeX;
var sy = img.sizeY;
var s = sx < sy ? sx : sy;
var l2 = Document.Duplicate();
var blur = Operation.Create("Raster Image - Blur");
blur.Type = 0;
blur.Radius = s*Configuration.blur*0.003;
Operation.Execute(blur, Document);
for (var i= 0; i<sy; ++i)
{
var str = Math.round((Math.sin(i/sy*6.283*stripes+phase*6.283)+1)*127.5)<<24;
Blender.Compose(img, 0, i, sx, i+1, null, 0, 0, str|0x7f7f7f, Blender.OpRGBAMultiply2x);
}
var l3 = l2.Duplicate();
var outline = Operation.Create("Raster Image - Outline");
outline.Position = 0;
outline.Width = s*Configuration.outline*0.0007;
outline.BlendingMode = 0;
outline.Color = [1.0, 1.0, 1.0, 1.0];
Operation.Execute(outline, l3);
Blender.Compose(l2, 0, 0, sx, sy, l3, 0, 0, 0, Blender.OpRGBAMultiply);
blur.Radius = s*0.01;
Operation.Execute(blur, l2);
var l4 = Document.Duplicate();
Blender.Compose(Document, 0, 0, sx, sy, l2, 0, 0, 0, Blender.OpScreen);
var i1 = l2.RasterImage;
var i2 = l4.RasterImage;
for (var y = 0; y<sy; ++y)
{
for (var x = 0; x<sx; ++x)
{
var a1 = i1.GetPixelAlpha(x, y, 0, 0);
var a2 = i2.GetPixelAlpha(x, y, 0, 0);
var a = a1+a2;
a = a*a/255;
if (a > 255) a = 255;
img.SetPixelAlpha(x, y, 0, 0, a);
}
}
Create an animated image with single raster layer with transparent background and draw a shape. If you do not want animation, simply run the script and pick parameters you like.
If you want animation, duplicate the frame with the shape as many times as many animation frames you want, then select all the frames and run the script. It will apply the effect on all selected frames, but using different phase for each frame.
For the image above, I have also used the Image->Blend with background command to make the background black, because the effect is not so great over bright backgrounds - maybe using Blender.OpMultiply instead of Blender.OpScreen would work better for dark colors over bright backgrounds.
You can also download a slightly differently packaged command here: X-Com.rwcommands. After you download it, drag and drop it onto the toolbar with Adjust exposure, Drop shadow, etc. in the (and this is IMPORTANT) animation layout - not will not work in the non-animated layout. A tiny change is needed, but since this is mainly an animation effect, I won't bother posting the other version.