Cool stuff!
The second example, although a bit cheesy was more what I was going for, but I knocked up a quick version myself which is more directional:
package {
import com.robotacid.geom.Dot;
import com.robotacid.geom.Line;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
[SWF(width = "640", height = "480", frameRate="30", backgroundColor = "#000000")]
/**
* ...
* @author Aaron Steed, robotacid.com
*/
public class Main extends Sprite {
public function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
scaleX = scaleY = 2;
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event = null):void{
graphics.clear();
graphics.lineStyle(1, 0xFFFFFF);
drawLightning(graphics, 160, 120, mouseX, mouseY);
}
private function drawLightning(gfx:Graphics, start_x:Number, start_y:Number, finish_x:Number, finish_y:Number, step:Number = 10):void{
var line:Line = new Line(new Dot(start_x, start_y), new Dot(finish_x, finish_y));
line.b.x = line.a.x + (line.dx + Math.random()) * line.lx + (Math.random() * line.rx) * Math.random() * step;
line.b.y = line.a.y + (line.dy + Math.random()) * line.ly + (Math.random() * line.ry) * Math.random() * step;
line.draw(gfx);
var i:int = 0;
while(line.b.x != finish_x && line.b.y != finish_y){
line.a.x = line.b.x;
line.a.y = line.b.y;
line.b.x = finish_x;
line.b.y = finish_y;
line.updateLine();
line.b.x = line.a.x + (line.dx + (Math.random() * line.lx) + (Math.random() * line.rx)) * Math.random() * step;
line.b.y = line.a.y + (line.dy + (Math.random() * line.ly) + (Math.random() * line.ry)) * Math.random() * step;
if(line.b.dist(new Dot(finish_x, finish_y)) < step){
line.b.x = finish_x;
line.b.y = finish_y;
}
line.draw(gfx);
if(i++ > 200) break;
}
}
}
}
The lightning will be random, but it will also target nearby monsters (think of it as a smart bomb that looks like the "quickening" in the Highlander films).
Rather than jumping about wildly around the next node, I've gone with stepping forwards but throwing the vector off randomly towards the right or left normal.
I need to optimise this a lot though. I'll upload when I can isolate this in one class rather than relying on my own geom package. I doubt I'll be able to afford to indulge in filters either.
My major concern is getting the forking effect. With a Tesla bolt it arcs towards a specific target, but sends off the odd little tendril, as this video shows: