WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Site Design > Flash Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Flash Discussion Forum Flash design presents a limitless number of possibilities for your sites and designs. Discuss your Flash ideas, questions and issues here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-20-2003, 11:50 AM
WebProWorld Member
 

Join Date: Nov 2003
Posts: 35
dbh_21 RepRank 0
Default lightning efects

how would i create lightning effects in flash
Reply With Quote
  #2 (permalink)  
Old 12-20-2003, 05:24 PM
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Posts: 1,087
Sualdam RepRank 0
Default

I emphasise that this isn't my coding - it is something I picked up off the web, but I can't remember where.

The credit must go to whoever wrote it.

Paste the code into the first frame of an empty movie. Set the background colour to black (or dark). Then test it - click the mouse to trigger the effect.

Code:
function makeLightning () {
        
}
max_sub_branch = 4 ;
max_sub_angle = 3*Math.PI/5 ;
max_size = 6 ;
length = 10 ;

function makeBranch ( targ, start_x, start_y, angle, size ) {
        if (size > 0 ) {
                c++ ;
                var cl = targ.createEmptyMovieClip ("light" + c, c) ;
                cl.lineStyle ( size, 0xffffff, 100 ) ;
                cl.moveTo ( start_x, start_y ) ;
                while (start_y < 400) {
                        var end_x = start_x + length * Math.cos ( angle ) + random(10) - 5 ;
                        var end_y = start_y + length * Math.sin ( angle ) //+ random(10) - 5 ;
                        cl.lineTo ( end_x, end_y ) ;
                        start_x = end_x ;
                        start_y = end_y ;
                        
                        if ( Math.random() > .9 && cl.sub < max_sub_branch ) {
                                cl.sub ++ ;
                                var newLength = length -1 ;
                                var newAngle = Math.PI/4 + Math.random() * Math.PI/2 ;
                                var newSize = size - 1 ;
                                makeBranch ( cl, end_x, end_y, newAngle, newSize ) ;
                        }
                }
        }
}

this.onMouseDown = function () {
        c = 0 ;
        this.light1.removeMovieClip ()  ;
        makeBranch ( this, 250, 0, Math.PI/6 + Math.random() * 2/3*Math.PI, max_size ) ;
        this.light1.onEnterFrame = function () {
                if ((this._alpha -= 5) < 5) this.removeMovieClip () ;
        }
}
__________________
Sualdam
Reply With Quote
Reply

  WebProWorld > Site Design > Flash Discussion Forum
Tags: ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0