Jump to content
How to Install Plugins ×

TR's Tesla Coil Plugin


TechnoRobbo

Recommended Posts

TechnoRobbo's Tesla Coil Plugin

 

A Simulation of an electrical arc and the arc breaking down.

Lots of adjustments so you can go from Realistic to Comic Book style.

 

Menu: Effects->Render

 

TeslaMenu.PNG?raw=1

 

 

Instructions on Youtube: https://youtu.be/ucSD7olugi0

 

A Lady's Wrath

Tesla.png?raw=1

 

 

The Code

 

Spoiler
// Submenu: Render
// Name: TR's Tesla Coil
// Title: TR's Tesla Coil PlugIn - v1.0
// Author: TechnoRobbo
// URL: http://www.technorobbo.com


#region UICode
Pair<double, double> Amount1 = Pair.Create( 0.0 , 0.0 ); // From
Pair<double, double> Amount2 = Pair.Create( 0.0 , 0.0 ); // To
double Amount3 = 25; // [10,75] Flux size
int Amount4 = 2; // [1,10] Thickness
int Amount5 = 192; // [30,255] Intensity
byte Amount6 = 0; // [255] Next Shape
byte Amount7 = 0; // [255] Next Sub-Shape
int Amount8 = 4; // [0,20] Spawn
int Amount9 = 500; // [100,1000] Resolution
byte Amount10 = 0; // Arc Color|Blue Lightning|Red Lightning|Green Lightning|White Lightning
#endregion


void spark(ref Surface dst,Rectangle rect, ref Random rndm, RectangleF field ,double thickness, 
    double flux , int intensity , int spawn,int rez,int arc){
    
    PointF[] pt = new PointF[(int)(rez)];
    double fx = field.Left;
    double fy =field.Top;
    double tx = field.Width;
    double ty = field.Height;
    double width=thickness;
    double glow=thickness * 1.75 ;
    double glow2=thickness * 2.25;
    
    Color[] arcColor ={Color.FromArgb(intensity,255,255,255),Color.FromArgb(intensity,255,255,255),
        Color.FromArgb(intensity,255,255,255),Color.FromArgb(intensity,255,255,255)};
    
    Color[] glowColor ={Color.FromArgb((int)(intensity * .5) ,0,0,255) , Color.FromArgb((int)(intensity * .5) ,255,0,0) ,
        Color.FromArgb((int)(intensity * .5) ,0,255,0) , Color.FromArgb((int)(intensity * .5) ,255,255,255)};
   
    Color[] glowColor2 ={Color.FromArgb((int)(intensity * .25) ,0,0,255) , Color.FromArgb((int)(intensity * .25) ,255,0,0) ,
        Color.FromArgb((int)(intensity * .25) ,0,255,0) , Color.FromArgb((int)(intensity * .25) ,255,255,255)};
    
    Pen DotPen = new Pen(arcColor[arc]); 
    DotPen.Width = (float)width; 
    Pen GlowPen = new Pen(glowColor[arc]);
    GlowPen.Width = (float)glow;
    Pen GlowPen2 = new Pen(glowColor2[arc]);
    GlowPen.Width = (float)glow2;
    
    Graphics g = new RenderArgs(dst).Graphics;
    g.Clip = new Region(rect);
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    
    //--------------------------------
    
    double rad = Math.Atan2(tx - fx,ty - fy);
    double tang=0;
    double i = 0;
    double span = Math.Sqrt((fx-tx)*(fx-tx)+(fy-ty)*(fy-ty));//actual length
    
   
    for (int count=0; count<( pt.Length); count++){
        
        //interpolate location
        double Z = Math.Pow(i, 10);
        double Y2 = fy * (1 - i) + i * ty;
        double X2 = fx * (1 - i) + i * tx;
        
        //semi random misdirection
        tang = tang + Math.Truncate(rndm.NextDouble()  * (flux + 1)) - flux / 2;
        double X = X2 + Math.Cos(rad) * tang;
        double Y = Y2 + Math.Sin(-rad) * tang;
        
        //interpolate direct course
        pt[count].X  =(float)(X * (1 - Z) + X2 * Z);
        pt[count].Y = (float)(Y * (1 - Z) + Y2 * Z);
        
        if (spawn !=0){      
            int subdiv =(pt.Length/spawn);
            
            //spawn a sput at sub division
            if ((count % subdiv) ==0){
                if ((count > 0) && ((pt.Length-count) > subdiv/2)){
                    
                    //random spur rotation
                    double spur= rndm.NextDouble() *  Math.PI/2 + Math.PI/4 - rad ; 
                    
                    //random spur length (0-1)
                    double span2 =span * (rndm.NextDouble() * .15  + .05);
                    
                    RectangleF field2= new RectangleF(pt[count].X,pt[count].Y,(float)(pt[count].X + Math.Cos(spur) * span2),
                        (float)( pt[count].Y + Math.Sin(spur) * span2));
                    
                    //respawn params
                    
                    double thick2 = Math.Max(thickness * 1/2,1);
                    int rez2 = Math.Max(rez/3,50);
                    
                    spark(ref dst,rect, ref rndm, field2, thick2 , flux ,intensity ,0,rez2, arc);
                }
            }
        
        }
        
        i+= 1/(float) (pt.Length); //increment interpolation
    }
    g.DrawLines(GlowPen2 , pt);
    g.DrawLines(GlowPen , pt);
    g.DrawLines(DotPen , pt);
}




void Render(Surface dst, Surface src, Rectangle rect)
{
    Random rndm = new Random(Amount6*256+Amount7);
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    float CenterX = ((selection.Right - selection.Left) / 2)+selection.Left;
    float CenterY= ((selection.Bottom - selection.Top) / 2)+selection.Top;
    
    RectangleF field= new RectangleF(CenterX * (float)Amount1.First + CenterX,
        CenterY * (float)Amount1.Second + CenterY,
        CenterX * (float)Amount2.First + CenterX, 
        CenterY * (float)Amount2.Second + CenterY);


    double thickness = Amount4;
    double flux = CenterX/(100-Amount3);
    int intensity=Amount5;
    int spawn = Amount8+1;
    if (Amount8==0){spawn=0;}
    int rez=Amount9;
    int arc = Amount10;
    
    //test variables
    //field.X=0;
    //field.Y=0;
    //field.Width=CenterX;//selection.Right;
    //field.Height=CenterY;//selection.Bottom;
    //spawn=5;
    //rez=500;
    //thickness=4;
    //arc=0;
    
    //end test
    
    dst.CopySurface( src,rect.Location,rect);




    //----------------------------------


    
   spark(ref dst,rect, ref rndm, field, thickness, flux, intensity, spawn, rez,arc);
}

 

 

 

TRsTeslaCoil.zip

 

  • Upvote 2

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

Oh man I have been waiting for someone to make a plugin like this. I am definitely going to play with this after i eat something,maybe for the rest of the night,lol. You da Man!! 

 

                                                              http://forums.getpaint.net/index.php?/topic/21233-skullbonz-art-gallery

Link to comment
Share on other sites

That's a pretty cool effect.  +1 for the source code which should be an inspiration to aspiring plugin coders out there.

 

 

Oh man I have been waiting for someone to make a plugin like this.  

 

You could have used this: Lightning.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...