├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── build.gradle ├── examples ├── Example1 │ ├── build.gradle │ └── src │ │ └── main │ │ └── actionscript │ │ ├── Context.as │ │ └── Main.as ├── Example2 │ ├── build.gradle │ └── src │ │ └── main │ │ └── actionscript │ │ ├── Context.as │ │ └── Main.as ├── build.gradle └── settings.gradle └── src └── main ├── actionscript └── starling │ └── extensions │ └── lightning │ ├── Lightning.as │ ├── LightningBase.as │ ├── LightningFadeType.as │ ├── LightningPool.as │ └── LightningType.as ├── libs ├── Starling-Extension-Graphics.swc └── starling.swc └── resources └── empty.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License (MIT) 3 | # 4 | # Copyright 2014 Andras Csizmadia (www.vpmedia.eu) 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | # 23 | 24 | # Build and Release Folders 25 | bin/ 26 | bin-debug/ 27 | bin-release/ 28 | build/ 29 | 30 | # Other files and folders 31 | .settings/ 32 | .gradle/ 33 | temp/ 34 | publish/ 35 | 36 | # IntelliJ IDEA 37 | .idea/ 38 | *.iml 39 | *.ipr 40 | *.iws -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License (MIT) 3 | # 4 | # Copyright 2015 Andras Csizmadia (www.vpmedia.eu) 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | # 23 | 24 | # Purpose: Flash SDK Template for Travis-CI and Gradle 25 | # Author: Andras Csizmadia (www.github.com/vpmedia) 26 | # Version: 1.0.0 27 | 28 | git: 29 | depth: 1 30 | 31 | language: objective-c 32 | 33 | env: 34 | - TERM=dumb 35 | 36 | before_script: 37 | # Update Brew silently 38 | - brew update >brew-update.log 39 | # Install Brew Packages silently 40 | - brew tap homebrew/binary 41 | - brew install gradle adobe-air-sdk 42 | # Adobe Flash Player for CLI 43 | - brew install caskroom/cask/brew-cask 44 | - brew cask install flash-player-debugger 45 | # Set env. variable used by FlexUnit 46 | - export FLASHPLAYER_DEBUGGER="$HOME/Applications/Flash Player Debugger.app/Contents/MacOS/Flash Player Debugger" 47 | # Set env. variable used by Gradle 48 | - export FLASH_PLAYER_EXE="$HOME/Applications/Flash Player Debugger.app/Contents/MacOS/Flash Player Debugger" 49 | # Apache Flex SDK 50 | - wget -O flex_sdk.zip http://mirrors.gigenet.com/apache/flex/4.14.0/binaries/apache-flex-sdk-4.14.0-bin.zip 51 | - unzip -q flex_sdk.zip -d flex_sdk 52 | # Init PlayerGlobals 53 | - echo env.PLAYERGLOBAL_HOME=libs/player > flex_sdk/env.properties 54 | # Init Apache Flex SDK 55 | - mkdir -p flex_sdk/frameworks/libs/player/11.1/ 56 | - mkdir -p flex_sdk/frameworks/libs/player/16.0/ 57 | - cp -f /usr/local/opt/adobe-air-sdk/libexec/frameworks/libs/player/16.0/playerglobal.swc flex_sdk/frameworks/libs/player/11.1/ 58 | - cp -f /usr/local/opt/adobe-air-sdk/libexec/frameworks/libs/player/16.0/playerglobal.swc flex_sdk/frameworks/libs/player/16.0/ 59 | # Set env. variable used by Gradle 60 | - export FLEX_HOME="$TRAVIS_BUILD_DIR/flex_sdk" 61 | # Init Adobe AIR SDK 62 | - mkdir -p /usr/local/opt/adobe-air-sdk/libexec/frameworks/libs/player/11.1/ 63 | - cp -f /usr/local/opt/adobe-air-sdk/libexec/frameworks/libs/player/16.0/playerglobal.swc /usr/local/opt/adobe-air-sdk/libexec/frameworks/libs/player/11.1/ 64 | # Set env. variable used by Gradle 65 | - export AIR_HOME="/usr/local/opt/adobe-air-sdk/libexec" 66 | 67 | script: 68 | - gradle -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 4 | Contributor 2014 Andras Csizmadia (www.vpmedia.eu) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | starling-extension-lightning [![Build Status](https://travis-ci.org/vpmedia/starling-extension-lightning.svg)](https://travis-ci.org/vpmedia/starling-extension-lightning) 2 | ============================ 3 | 4 | Starling version of http://blog.oaxoa.com/2009/07/27/actionscript-3-as3-lightning-thunderbolt-electric-discharge-class/ 5 | 6 | External dependencies: 7 | 8 | * https://github.com/PrimaryFeather/Starling-Framework/ 9 | 10 | * https://github.com/StarlingGraphics/Starling-Extension-Graphics/ 11 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // 2 | // =BEGIN MIT LICENSE 3 | // 4 | // Copyright (c) 2014 Andras Csizmadia 5 | // http://www.vpmedia.hu 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // =END MIT LICENSE 26 | // 27 | 28 | // needed for deploying 29 | apply plugin: 'maven' 30 | 31 | repositories { 32 | mavenLocal() 33 | mavenCentral() 34 | maven { 35 | url 'https://raw.githubusercontent.com/vpmedia/mvnrepository/master' 36 | } 37 | maven { 38 | url 'https://oss.sonatype.org/content/groups/public/' 39 | } 40 | } 41 | 42 | configurations { 43 | antClassPath 44 | compile 45 | test 46 | } 47 | 48 | dependencies { 49 | test group: 'org.apache', name: 'flexunit-tasks', version: '4.2.0-20140410', ext: 'jar' 50 | test group: 'org.apache', name: 'flexunit-as3', version: '4.2.0-20140410', ext: 'swc' 51 | test group: 'org.apache', name: 'flexunit-cilistener', version: '4.2.0-20140410', ext: 'swc' 52 | test group: 'org.apache', name: 'flexunit-uilistener', version: '4.2.0-20140410', ext: 'swc' 53 | test group: 'org.apache', name: 'hamcrest-as3', version: '1.1.3', ext: 'swc' 54 | test group: 'org.apache', name: 'flex-pmd-ant-task', version: '1.3', ext: 'jar' 55 | test group: 'org.apache', name: 'flex-pmd-files', version: '1.3', ext: 'jar' 56 | test group: 'org.apache', name: 'flex-pmd-core', version: '1.3', ext: 'jar' 57 | test group: 'org.apache', name: 'flex-pmd-ruleset', version: '1.3', ext: 'jar' 58 | test group: 'org.apache', name: 'flex-pmd-ruleset-api', version: '1.3', ext: 'jar' 59 | test group: 'org.apache', name: 'flex-pmd-cpd', version: '1.3', ext: 'jar' 60 | test group: 'org.apache', name: 'flex-pmd-cpd-ant-task', version: '1.3', ext: 'jar' 61 | test group: 'org.apache', name: 'flex-pmd-metrics', version: '1.3', ext: 'jar' 62 | test group: 'org.apache', name: 'flex-pmd-metrics-ant-task', version: '1.3', ext: 'jar' 63 | test group: 'org.apache', name: 'as3-parser', version: '1.3', ext: 'jar' 64 | test group: 'org.apache', name: 'as3-parser-api', version: '1.3', ext: 'jar' 65 | test group: 'org.apache', name: 'as3-plugin-utils', version: '1.3', ext: 'jar' 66 | test group: 'pmd', name: 'pmd', version: '4.2.5', ext: 'jar' 67 | test group: 'commons-lang', name: 'commons-lang', version: '2.4', ext: 'jar' 68 | test group: 'org.codehaus.plexus', name: 'plexus-utils', version: '3.0.17', ext: 'jar' 69 | antClassPath 'ant-contrib:ant-contrib:1.0b3', 'org.apache.ant:ant-junit:1.9.4' 70 | } 71 | 72 | // add additional jars to the AntBuilder classpath for use within the imported build. 73 | ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader 74 | configurations.antClassPath.each { File f -> 75 | antClassLoader.addURL(f.toURI().toURL()) 76 | } 77 | 78 | //---------------------------------- 79 | // SDK 80 | //---------------------------------- 81 | 82 | def AIR_HOME = System.getenv('AIR_HOME') 83 | def FLEX_HOME = System.getenv('FLEX_HOME') 84 | ant.FLEX_HOME = "${FLEX_HOME}" 85 | 86 | //---------------------------------- 87 | // Core 88 | //---------------------------------- 89 | 90 | // Set default properties 91 | version = '0.0.1' 92 | group = 'hu.vpmedia' 93 | 94 | // Get version from Jenkins CI 95 | if("${System.env.JENKINS_BUILD_VERSION}" != "null") { 96 | version = "${System.env.JENKINS_BUILD_VERSION}" 97 | } 98 | 99 | //---------------------------------- 100 | // Folders 101 | //---------------------------------- 102 | 103 | def binDir = new File(projectDir, '/bin') 104 | def buildDir = new File(projectDir, '/build') 105 | def confDir = new File(projectDir, '/src/main/temp') 106 | def publishDir = new File(projectDir, '/publish') 107 | def reportDir = new File(projectDir, '/build/reports') 108 | def tempDir = new File(projectDir, '/temp') 109 | tempDir.mkdirs() 110 | def tempDirPath = tempDir.absolutePath 111 | def srcDir = new File(projectDir, '/src/main/actionscript') 112 | def testDir = new File(projectDir, '/src/test/actionscript') 113 | def swcDir = new File(projectDir, '/src/main/libs') 114 | 115 | //---------------------------------- 116 | // Tasks 117 | //---------------------------------- 118 | 119 | task clean_init << { 120 | if (binDir.isDirectory()) { 121 | delete(binDir) 122 | } 123 | if (buildDir.isDirectory()) { 124 | delete(buildDir) 125 | } 126 | if (confDir.isDirectory()) { 127 | delete(confDir) 128 | } 129 | } 130 | 131 | task copyDeps(type: Copy) { 132 | from configurations.all 133 | into binDir 134 | } 135 | 136 | task compile(type: JavaExec) { 137 | main = "com.adobe.flash.compiler.clients.COMPC" 138 | classpath = files("${AIR_HOME}/lib/compiler.jar") 139 | workingDir = "${projectDir}" 140 | def argsList = [] 141 | argsList.push('-directory=false') 142 | argsList.push('-debug=true') 143 | def includeSources = '-include-sources=' + srcDir 144 | argsList.push(includeSources) 145 | def libraryPath = '-library-path=' + swcDir 146 | argsList.push(libraryPath) 147 | argsList.push('-output="build/Main.swc"'); 148 | def airConfig = "${AIR_HOME}" + '/frameworks/air-config.xml' 149 | def loadAirConfig = '-load-config+='+"${airConfig}"; 150 | argsList.push(loadAirConfig) 151 | args = argsList 152 | } 153 | 154 | task test << { 155 | if (reportDir.isDirectory()) { 156 | delete("${reportDir}") 157 | } 158 | if(testDir.isDirectory()) { 159 | reportDir.mkdirs() 160 | ant.taskdef(resource: 'flexUnitTasks.tasks', classpath: configurations.test.asPath) 161 | ant.flexunit(workingDir:'bin',toDir:'build/reports',haltonfailure:'false',verbose:'true',player:'flash',headless:'false',localTrusted:'true') { 162 | source(dir: srcDir) 163 | testSource(dir: testDir) { 164 | include(name: '**/*Test.as') 165 | } 166 | library(dir: 'bin') 167 | } 168 | ant.junitreport(todir: reportDir) { 169 | fileset(dir: reportDir, includes: 'TEST-*.xml') 170 | report(format:'frames', todir:'build/reports/html') 171 | } 172 | } 173 | } 174 | 175 | task analyze << { 176 | reportDir.mkdirs() 177 | ant.taskdef(name: 'flexPmd', classname: 'com.adobe.ac.pmd.ant.FlexPmdAntTask', classpath: configurations.test.asPath) 178 | ant.taskdef(name: 'flexCpd', classname: 'com.adobe.ac.cpd.ant.FlexCpdAntTask', classpath: configurations.test.asPath) 179 | ant.flexPmd(sourceDirectory: "${srcDir}", outputDirectory: reportDir ) 180 | } 181 | 182 | task document << { 183 | ant.taskdef(resource: 'flexTasks.tasks', classpath: "${FLEX_HOME}/ant/lib/flexTasks.jar") 184 | ant.asdoc(output: 'build/docs', lenient: true) { 185 | 'doc-sources'("${srcDir}") 186 | 'compiler.source-path'("${srcDir}") 187 | 'external-library-path'(dir: "${AIR_HOME}/frameworks/libs/air", append: true) { 188 | 'include'(name: '*.swc') 189 | } 190 | 'external-library-path'(dir: swcDir, append: true) { 191 | 'include'(name: '*.swc') 192 | } 193 | } 194 | } 195 | 196 | artifacts { 197 | archives file('build/Main.swc') 198 | } 199 | 200 | uploadArchives { 201 | repositories { 202 | mavenLocal() 203 | } 204 | } 205 | 206 | compile.dependsOn copyDeps 207 | 208 | defaultTasks 'clean_init', 'compile', 'test', 'analyze' 209 | -------------------------------------------------------------------------------- /examples/Example1/build.gradle: -------------------------------------------------------------------------------- 1 | // 2 | // =BEGIN MIT LICENSE 3 | // 4 | // Copyright (c) 2014 Andras Csizmadia 5 | // http://www.vpmedia.hu 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // =END MIT LICENSE 26 | // 27 | 28 | -------------------------------------------------------------------------------- /examples/Example1/src/main/actionscript/Context.as: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the MIT License 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package { 25 | 26 | import flash.geom.Point; 27 | import flash.text.TextField; 28 | import flash.text.TextFormat; 29 | 30 | import starling.core.Starling; 31 | import starling.display.Shape; 32 | import starling.display.Sprite; 33 | import starling.events.Event; 34 | import starling.events.Touch; 35 | import starling.events.TouchEvent; 36 | import starling.events.TouchPhase; 37 | import starling.extensions.lightning.Lightning; 38 | import starling.extensions.lightning.LightningFadeType; 39 | import starling.extensions.lightning.LightningPool; 40 | import starling.filters.BlurFilter; 41 | import starling.filters.FragmentFilterMode; 42 | 43 | // http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test_coil.swf&w=727&h=566 44 | 45 | public final class Context extends Sprite { 46 | 47 | private static const CX:uint = 360; 48 | 49 | private static const CY:uint = 320; 50 | 51 | private static const COLOR:uint = 0xDDEEFF; 52 | 53 | private var ll:Lightning; 54 | 55 | private var dot1:Shape; 56 | 57 | private var dot2:Shape; 58 | 59 | private var ball:Shape; 60 | 61 | private var p:Point; 62 | 63 | private var glowFilter:BlurFilter; 64 | 65 | private var debugLabel:TextField; 66 | 67 | private var displayDriver:String; 68 | 69 | public function Context() { 70 | addEventListener(Event.ADDED_TO_STAGE, onAdded); 71 | } 72 | 73 | private function onAdded(event:Event):void { 74 | displayDriver = Starling.current.context.driverInfo; 75 | removeEventListener(Event.ADDED_TO_STAGE, onAdded); 76 | // set starling stage color 77 | stage.color = 0x001A4D; 78 | // debug label 79 | const textFormat:TextFormat = new TextFormat("Arial", 10, 0xFFFFFF); 80 | debugLabel = new TextField(); 81 | Starling.current.nativeOverlay.addChild(debugLabel); 82 | debugLabel.width = 800; 83 | debugLabel.height = 20; 84 | debugLabel.y = 580; 85 | debugLabel.embedFonts = false; 86 | debugLabel.multiline = false; 87 | debugLabel.selectable = false; 88 | debugLabel.defaultTextFormat = textFormat; 89 | debugLabel.text = "Initializing..."; 90 | debugLabel.setTextFormat(textFormat); 91 | // ball 92 | ball = new Shape(); 93 | ball.graphics.beginFill(0x333333); 94 | ball.graphics.drawCircle(0, 0, 15); 95 | ball.graphics.endFill(); 96 | ball.x = 400; 97 | ball.y = 50; 98 | addChild(ball); 99 | // dot1 100 | dot1 = new Shape(); 101 | dot1.graphics.beginFill(COLOR); 102 | dot1.graphics.drawCircle(0, 0, 6); 103 | dot1.graphics.endFill(); 104 | //dot1.alpha = .75; 105 | dot1.x = 100; 106 | dot1.y = 100; 107 | addChild(dot1); 108 | // dot2 109 | dot2 = new Shape(); 110 | dot2.graphics.beginFill(COLOR); 111 | dot2.graphics.drawCircle(0, 0, 3); 112 | dot2.graphics.endFill(); 113 | dot2.x = 600; 114 | dot2.y = 100; 115 | addChild(dot2); 116 | // lightning 117 | ll = new Lightning(COLOR, 2); 118 | //ll.blendMode = BlendMode.ADD; 119 | ll.childrenDetachedEnd = true; 120 | ll.childrenLifeSpanMin = .1; 121 | ll.childrenLifeSpanMax = 2; 122 | ll.childrenMaxCount = 4; 123 | ll.childrenMaxCountDecay = .5; 124 | ll.steps = 150; 125 | ll.alphaFadeType = LightningFadeType.TIP_TO_END; 126 | ll.childrenProbability = .3; 127 | glowFilter = new BlurFilter(4, 4, 2); 128 | glowFilter.mode = FragmentFilterMode.ABOVE; 129 | glowFilter.setUniformColor(true, COLOR, 1); 130 | ll.filter = glowFilter; 131 | addChild(ll); 132 | 133 | p = new Point(); 134 | randomizePoint(); 135 | 136 | ball.addEventListener(TouchEvent.TOUCH, onTouch); 137 | addEventListener(Event.ENTER_FRAME, onFrameEnter); 138 | 139 | // Debug 140 | //addChild(new Bitmap(ll.bBitmapData)).y = 2; 141 | //addChild(new Bitmap(ll.sBitmapData)).y = 4; 142 | } 143 | 144 | private function onFrameEnter(event:Event):void { 145 | debugLabel.text = "LightningPool size= " + LightningPool.getSize() + " | " + ll + " | " + displayDriver; 146 | var rnd:Number = Math.random(); 147 | if (rnd < .05) randomizePoint(); 148 | var dx:Number = CX - ball.x; 149 | var dy:Number = CY - ball.y; 150 | var d:Number = Math.sqrt(dx * dx + dy * dy); 151 | if (d < 310) { 152 | dot2.visible = true; 153 | if (ll.childrenDetachedEnd) { 154 | trace("CLEAR #1"); 155 | ll.filter = glowFilter; 156 | ll.childrenDetachedEnd = false; 157 | ll.alphaFadeType = LightningFadeType.GENERATION; 158 | ll.disposeAllChildren(); 159 | } 160 | 161 | ll.endX = dot2.x = ball.x; 162 | ll.endY = dot2.y = ball.y; 163 | } else { 164 | dot2.visible = false; 165 | if (!ll.childrenDetachedEnd) { 166 | trace("CLEAR #2"); 167 | ll.filter = null; 168 | ll.childrenDetachedEnd = true; 169 | ll.alphaFadeType = LightningFadeType.TIP_TO_END; 170 | ll.disposeAllChildren(); 171 | } 172 | ll.endX = p.x; 173 | ll.endY = p.y; 174 | } 175 | var ddx:Number = CX - ll.endX; 176 | var ddy:Number = CY - ll.endY; 177 | var aangle:Number = Math.atan2(ddy, ddx); 178 | ll.startX = CX - Math.cos(aangle) * 80; 179 | dot1.scaleX = Math.sin(aangle); 180 | ll.startY = CY; 181 | dot1.x = ll.startX; 182 | dot1.y = ll.startY; 183 | ll.update(); 184 | } 185 | 186 | private function randomizePoint():void { 187 | var angle:Number = -Math.random() * Math.PI; 188 | var dist:Number = 160 + Math.random() * 180; 189 | p.x = CX + Math.cos(angle) * dist; 190 | p.y = CY + Math.sin(angle) * dist; 191 | } 192 | 193 | private function onTouch(e:TouchEvent):void { 194 | var touch:Touch = e.getTouch(stage); 195 | if (touch.phase == TouchPhase.MOVED) { 196 | ball.x = touch.globalX; 197 | ball.y = touch.globalY; 198 | } 199 | } 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /examples/Example1/src/main/actionscript/Main.as: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the MIT License 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package { 25 | 26 | import flash.display.Sprite; 27 | import flash.display.StageAlign; 28 | import flash.display.StageQuality; 29 | import flash.display.StageScaleMode; 30 | import flash.display3D.Context3DProfile; 31 | import flash.display3D.Context3DRenderMode; 32 | import flash.events.Event; 33 | 34 | import starling.core.Starling; 35 | 36 | // http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test_coil.swf&w=727&h=566 37 | 38 | [SWF(width="800", height="600", frameRate="60", backgroundColor="#001a4d")] 39 | public final class Main extends Sprite { 40 | 41 | private var starling:Starling; 42 | 43 | public function Main() { 44 | addEventListener(Event.ADDED_TO_STAGE, onAdded); 45 | } 46 | 47 | private function onAdded(event:Event):void { 48 | stage.align = StageAlign.TOP_LEFT; 49 | stage.scaleMode = StageScaleMode.NO_SCALE; 50 | stage.quality = StageQuality.MEDIUM; 51 | stage.frameRate = 60; 52 | removeEventListener(Event.ADDED_TO_STAGE, onAdded); 53 | starling = new Starling(Context, stage, null, null, Context3DRenderMode.AUTO, Context3DProfile.BASELINE); 54 | starling.showStats = true; 55 | starling.enableErrorChecking = false; 56 | starling.simulateMultitouch = false; 57 | starling.antiAliasing = 0; 58 | starling.start(); 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /examples/Example2/build.gradle: -------------------------------------------------------------------------------- 1 | // 2 | // =BEGIN MIT LICENSE 3 | // 4 | // Copyright (c) 2014 Andras Csizmadia 5 | // http://www.vpmedia.hu 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // =END MIT LICENSE 26 | // 27 | 28 | -------------------------------------------------------------------------------- /examples/Example2/src/main/actionscript/Context.as: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the MIT License 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package { 25 | 26 | import flash.events.MouseEvent; 27 | import flash.text.TextField; 28 | import flash.text.TextFormat; 29 | 30 | import starling.core.Starling; 31 | import starling.display.Shape; 32 | import starling.display.Sprite; 33 | import starling.events.Event; 34 | import starling.extensions.lightning.Lightning; 35 | import starling.extensions.lightning.LightningPool; 36 | import starling.filters.BlurFilter; 37 | 38 | // http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test_coil.swf&w=727&h=566 39 | 40 | public final class Context extends Sprite { 41 | 42 | private var fingers; 43 | private var dot1:Shape; 44 | private var dot2:Shape; 45 | private var dot3:Shape; 46 | private var dot4:Shape; 47 | private var ll:Lightning; 48 | private var ll2:Lightning; 49 | 50 | private var glowFilter:BlurFilter; 51 | 52 | private var debugLabel:TextField; 53 | 54 | private var displayDriver:String; 55 | 56 | private static const COLOR:uint = 0xDDEEFF; 57 | 58 | public function Context() { 59 | addEventListener(Event.ADDED_TO_STAGE, onAdded); 60 | } 61 | 62 | private function onAdded(event:Event):void { 63 | displayDriver = Starling.current.context.driverInfo; 64 | removeEventListener(Event.ADDED_TO_STAGE, onAdded); 65 | // set starling stage color 66 | stage.color = 0x001A4D; 67 | // debug label 68 | const textFormat:TextFormat = new TextFormat("Arial", 10, 0xFFFFFF); 69 | debugLabel = new TextField(); 70 | Starling.current.nativeOverlay.addChild(debugLabel); 71 | debugLabel.width = 800; 72 | debugLabel.height = 20; 73 | debugLabel.y = 580; 74 | debugLabel.embedFonts = false; 75 | debugLabel.multiline = false; 76 | debugLabel.selectable = false; 77 | debugLabel.defaultTextFormat = textFormat; 78 | debugLabel.text = "Initializing..."; 79 | debugLabel.setTextFormat(textFormat); 80 | 81 | // 82 | fingers = new Sprite(); 83 | addChild(fingers); 84 | // 85 | dot1 = new Shape(); 86 | dot1.name = "dot1"; 87 | dot1.graphics.beginFill(0x6699CC); 88 | dot1.graphics.drawCircle(0, 0, 8); 89 | dot1.graphics.endFill(); 90 | fingers.addChild(dot1); 91 | // 92 | dot2 = new Shape(); 93 | dot2.name = "dot2"; 94 | dot2.graphics.beginFill(0x6699CC); 95 | dot2.graphics.drawCircle(0, 0, 8); 96 | dot2.graphics.endFill(); 97 | fingers.addChild(dot2); 98 | dot2.x = 50; 99 | 100 | fingers.y = 400; 101 | fingers.x = fingers.y / 2.5 - 10; 102 | 103 | // 104 | dot3 = new Shape(); 105 | dot3.graphics.beginFill(0x336699); 106 | dot3.graphics.drawCircle(0, 0, 8); 107 | dot3.graphics.endFill(); 108 | dot3.x = 20; 109 | dot3.y = 50; 110 | addChild(dot3); 111 | 112 | // 113 | dot4 = new Shape(); 114 | dot4.graphics.beginFill(0x336699); 115 | dot4.graphics.drawCircle(0, 0, 8); 116 | dot4.graphics.endFill(); 117 | dot4.x = 60; 118 | dot4.y = 50; 119 | addChild(dot4); 120 | 121 | // 122 | ll = new Lightning(COLOR, 2); 123 | ll2 = new Lightning(COLOR, 2); 124 | ll.childrenProbability = ll2.childrenProbability = .5; 125 | ll.childrenLifeSpanMin = ll2.childrenLifeSpanMin = .1; 126 | ll.childrenLifeSpanMax = ll2.childrenLifeSpanMax = 2; 127 | ll.maxLength = ll2.maxLength = 50; 128 | ll.maxLengthVary = ll2.maxLengthVary = 200; 129 | 130 | ll.startX = dot3.x; 131 | ll.startY = dot3.y; 132 | ll2.startX = dot4.x; 133 | ll2.startY = dot4.y; 134 | 135 | ll.filter = ll2.filter = glowFilter; 136 | 137 | addChild(ll); 138 | addChild(ll2); 139 | 140 | updatePositions(); 141 | 142 | Starling.current.nativeStage.addEventListener("mouseMove", onMove); 143 | addEventListener(Event.ENTER_FRAME, onFrameEnter); 144 | 145 | } 146 | 147 | private function updatePositions():void { 148 | ll.endX = fingers.x + dot1.x; 149 | ll.endY = fingers.y + dot1.y; 150 | ll2.endX = fingers.x + dot2.x; 151 | ll2.endY = fingers.y + dot2.y; 152 | } 153 | 154 | private function onFrameEnter(event:Event):void { 155 | debugLabel.text = "LightningPool size= " + LightningPool.getSize() + " | " + ll + " | " + displayDriver; 156 | ll.update(); 157 | ll2.update(); 158 | } 159 | 160 | private function onMove(e:MouseEvent):void { 161 | fingers.y = e.stageY - 150; 162 | if (fingers.y > 600) fingers.y = 600; 163 | fingers.x = fingers.y / 2.5 - 10; 164 | updatePositions(); 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /examples/Example2/src/main/actionscript/Main.as: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed under the MIT License 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package { 25 | 26 | import flash.display.Sprite; 27 | import flash.display.StageAlign; 28 | import flash.display.StageQuality; 29 | import flash.display.StageScaleMode; 30 | import flash.display3D.Context3DProfile; 31 | import flash.display3D.Context3DRenderMode; 32 | import flash.events.Event; 33 | 34 | import starling.core.Starling; 35 | 36 | // http://blog.oaxoa.com/wp-content/examples/showExample.php?f=lightning_test_coil.swf&w=727&h=566 37 | 38 | [SWF(width="800", height="600", frameRate="60", backgroundColor="#001a4d")] 39 | public final class Main extends Sprite { 40 | 41 | private var starling:Starling; 42 | 43 | public function Main() { 44 | addEventListener(Event.ADDED_TO_STAGE, onAdded); 45 | } 46 | 47 | private function onAdded(event:Event):void { 48 | stage.align = StageAlign.TOP_LEFT; 49 | stage.scaleMode = StageScaleMode.NO_SCALE; 50 | stage.quality = StageQuality.MEDIUM; 51 | stage.frameRate = 60; 52 | removeEventListener(Event.ADDED_TO_STAGE, onAdded); 53 | starling = new Starling(Context, stage, null, null, Context3DRenderMode.AUTO, Context3DProfile.BASELINE); 54 | starling.showStats = true; 55 | starling.enableErrorChecking = false; 56 | starling.simulateMultitouch = false; 57 | starling.antiAliasing = 0; 58 | starling.start(); 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /examples/build.gradle: -------------------------------------------------------------------------------- 1 | // 2 | // =BEGIN MIT LICENSE 3 | // 4 | // Copyright (c) 2014 Andras Csizmadia 5 | // http://www.vpmedia.hu 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // =END MIT LICENSE 26 | // 27 | 28 | buildscript { 29 | repositories { 30 | mavenCentral() 31 | } 32 | dependencies { 33 | classpath group: 'org.gradlefx', name: 'gradlefx', version: '0.+' 34 | } 35 | } 36 | 37 | subprojects { 38 | 39 | apply plugin: 'gradlefx' 40 | 41 | version = '1.0-SNAPSHOT' 42 | 43 | srcDirs = [ 44 | 'src/main/actionscript', 45 | '../../src/main/actionscript' 46 | ] 47 | 48 | type = 'swf' 49 | frameworkLinkage = 'none' 50 | 51 | playerVersion = '16.0' 52 | mainClass = 'Main.as' 53 | 54 | additionalCompilerOptions = [ 55 | '-debug=true', 56 | '-optimize=true', 57 | '-target-player=16.0', 58 | '-swf-version=27' 59 | ] 60 | 61 | configurations { 62 | all*.exclude group: 'com.adobe.flex.framework' 63 | } 64 | 65 | dependencies { 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /examples/settings.gradle: -------------------------------------------------------------------------------- 1 | // 2 | // =BEGIN MIT LICENSE 3 | // 4 | // Copyright (c) 2014 Andras Csizmadia 5 | // http://www.vpmedia.hu 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // =END MIT LICENSE 26 | // 27 | 28 | include 'Example1','Example2' -------------------------------------------------------------------------------- /src/main/actionscript/starling/extensions/lightning/Lightning.as: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package starling.extensions.lightning { 25 | import starling.display.graphics.Stroke; 26 | 27 | /** 28 | * Lightning Root Class 29 | * 30 | * @author Pierluigi Pesenti (blog.oaxoa.com) 31 | * @contributor Andras Csizmadia (www.vpmedia.eu) 32 | * @contributor IonSwitz (www.github.com/IonSwitz) 33 | * 34 | */ 35 | public class Lightning extends LightningBase { 36 | protected var _stroke:Stroke = null; 37 | 38 | public function Lightning(color:uint = 0xFFFFFF, thickness:Number = 2, generation:uint = 0, isPooled:Boolean = false) { 39 | super(color, thickness, generation, isPooled); 40 | } 41 | 42 | public function update():void { 43 | if (_stroke == null) { 44 | _stroke = new Stroke(); 45 | addChild(_stroke); 46 | } 47 | else 48 | _stroke.clear(); 49 | 50 | updateBase(_stroke); 51 | } 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/main/actionscript/starling/extensions/lightning/LightningBase.as: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package starling.extensions.lightning { 25 | import flash.display.BitmapData; 26 | import flash.display.GradientType; 27 | import flash.events.TimerEvent; 28 | import flash.geom.Matrix; 29 | import flash.geom.Point; 30 | import flash.utils.Timer; 31 | 32 | import starling.display.Sprite; 33 | import starling.display.graphics.Stroke; 34 | import starling.events.Event; 35 | 36 | /** 37 | * Lightning Base Class 38 | * 39 | * @author Pierluigi Pesenti (blog.oaxoa.com) 40 | * @contributor Andras Csizmadia (www.vpmedia.eu) 41 | * @contributor IonSwitz (www.github.com/IonSwitz) 42 | * 43 | */ 44 | public class LightningBase extends Sprite { 45 | 46 | //---------------------------------- 47 | // Public Properties 48 | //---------------------------------- 49 | 50 | /** TBD */ 51 | public var startX:Number; 52 | 53 | /** TBD */ 54 | public var startY:Number; 55 | 56 | /** TBD */ 57 | public var endX:Number; 58 | 59 | /** TBD */ 60 | public var endY:Number; 61 | 62 | /** TBD */ 63 | public var thickness:Number; 64 | 65 | /** TBD */ 66 | public var childrenLifeSpanMin:Number; 67 | 68 | /** TBD */ 69 | public var childrenLifeSpanMax:Number; 70 | 71 | /** TBD */ 72 | public var childAngle:Number; 73 | 74 | /** TBD */ 75 | public var maxLength:Number; 76 | 77 | /** TBD */ 78 | public var maxLengthVary:Number; 79 | 80 | /** TBD */ 81 | public var startStep:uint; 82 | 83 | /** TBD */ 84 | public var endStep:uint; 85 | 86 | /** TBD */ 87 | public var alphaFadeType:String; 88 | 89 | /** TBD */ 90 | public var thicknessFadeType:String; 91 | 92 | /** TBD */ 93 | public var childrenDetachedEnd:Boolean; 94 | 95 | //---------------------------------- 96 | // Static Properties 97 | //---------------------------------- 98 | 99 | /** @private */ 100 | private static const SMOOTH_COLOR:uint = 0x808080; 101 | 102 | /** @private */ 103 | private static const WHITE_COLOR:uint = 0xFFFFFF; 104 | 105 | /** @private */ 106 | private static var ID:uint = 0; 107 | 108 | //---------------------------------- 109 | // Internal Properties 110 | //---------------------------------- 111 | 112 | /** Internal identifier */ 113 | internal var id:uint = ID++; 114 | 115 | /** Generation level */ 116 | internal var generation:uint; 117 | 118 | /** Life time */ 119 | internal var lifeSpan:Number; 120 | 121 | /** Position, used to alpha calc. */ 122 | internal var position:Number; 123 | 124 | /** Abs. position, used to alpha calc. */ 125 | internal var absolutePosition:Number; 126 | 127 | /** Children smoothing display object helper */ 128 | internal var childrenSmooth:flash.display.Sprite; 129 | 130 | /** Reference to the parent Lightning. */ 131 | internal var parentInstance:LightningBase; 132 | 133 | //---------------------------------- 134 | // Getter/Setter Properties 135 | //---------------------------------- 136 | 137 | /** @private */ 138 | private var _steps:uint; 139 | 140 | /** @private */ 141 | private var _smoothPercentage:uint; 142 | 143 | /** @private */ 144 | private var _childrenSmoothPercentage:uint; 145 | 146 | /** @private */ 147 | private var _childrenAngleVariation:Number; 148 | 149 | /** @private */ 150 | private var _childrenProbability:Number; 151 | 152 | /** @private */ 153 | private var _childrenProbabilityDecay:Number; 154 | 155 | /** @private */ 156 | private var _childrenMaxGenerations:uint; 157 | 158 | /** @private */ 159 | private var _childrenMaxCount:uint; 160 | 161 | /** @private */ 162 | private var _childrenMaxCountDecay:Number; 163 | 164 | /** @private */ 165 | private var _childrenLengthDecay:Number; 166 | 167 | /** @private */ 168 | private var _wavelength:Number; 169 | 170 | /** @private */ 171 | private var _amplitude:Number; 172 | 173 | /** @private */ 174 | private var _speed:Number; 175 | 176 | //---------------------------------- 177 | // Private Properties 178 | //---------------------------------- 179 | 180 | /** @private */ 181 | // protected var _canvas:Shape; 182 | 183 | 184 | /** @private */ 185 | private var _childHolder:Sprite; 186 | 187 | /** @private */ 188 | private var _smooth:flash.display.Sprite; 189 | 190 | /** @private */ 191 | private var _smoothMatrix:Matrix; 192 | 193 | /** @private */ 194 | private var _drawMatrix:Matrix; 195 | 196 | /** @private */ 197 | private var _sBitmapData:BitmapData; 198 | 199 | /** @private */ 200 | private var _bBitmapData:BitmapData; 201 | 202 | /** @private */ 203 | private var _lifeTimer:Timer; 204 | 205 | /** @private */ 206 | private var _sOffsets:Array; 207 | 208 | /** @private */ 209 | private var _bOffsets:Array; 210 | 211 | /** @private */ 212 | private var _seed1:uint; 213 | 214 | /** @private */ 215 | private var _seed2:uint; 216 | 217 | /** @private */ 218 | private var _color:uint; 219 | 220 | /** @private */ 221 | private var _len:Number; 222 | 223 | /** @private */ 224 | private var _multi2:Number; 225 | 226 | /** @private */ 227 | private var _dx:Number; 228 | 229 | /** @private */ 230 | private var _dy:Number; 231 | 232 | //---------------------------------- 233 | // Local Properties 234 | //---------------------------------- 235 | 236 | /** @private */ 237 | private var _sOffset:Number; 238 | 239 | /** @private */ 240 | private var _sOffsetX:Number; 241 | 242 | /** @private */ 243 | private var _sOffsetY:Number; 244 | 245 | /** @private */ 246 | private var _bOffset:Number; 247 | 248 | /** @private */ 249 | private var _bOffsetX:Number; 250 | 251 | /** @private */ 252 | private var _bOffsetY:Number; 253 | 254 | /** @private */ 255 | private var _angle:Number; 256 | 257 | /** @private */ 258 | private var _tx:Number; 259 | 260 | /** @private */ 261 | private var _ty:Number; 262 | 263 | //---------------------------------- 264 | // Constructor 265 | //---------------------------------- 266 | 267 | /** 268 | * Constructor 269 | * 270 | * @param color The lightning color 271 | * @param thickness The lightning thickness 272 | * @param generation The lightning sub-generation 273 | */ 274 | public function LightningBase(color:uint = 0xFFFFFF, thickness:Number = 2, generation:uint = 0, isPooled:Boolean = false) { 275 | if (!isPooled) 276 | preInitialize(color, thickness, generation); 277 | } 278 | 279 | //---------------------------------- 280 | // Private Methods 281 | //---------------------------------- 282 | 283 | /** 284 | * @private 285 | */ 286 | internal function preInitialize(color:uint, thickness:Number, generation:uint):void { 287 | setupDefaults(); 288 | _color = color; 289 | this.thickness = thickness; 290 | this.generation = generation; 291 | if (this.generation == 0) 292 | initialize(); 293 | addEventListener(Event.REMOVED_FROM_STAGE, onRemoved); 294 | } 295 | 296 | /** 297 | * @private 298 | */ 299 | internal function setupDefaults():void { 300 | // display list 301 | touchable = false; 302 | /* if (!_canvas) { 303 | _canvas = new Shape(); 304 | addChild(_canvas); 305 | }*/ 306 | if (!_childHolder) { 307 | _childHolder = new Sprite(); 308 | addChild(_childHolder); 309 | } 310 | // public 311 | startX = 0; 312 | startY = 0; 313 | endX = 0; 314 | endY = 0; 315 | thickness = 2; 316 | childrenLifeSpanMin = 0; 317 | childrenLifeSpanMax = 0; 318 | childAngle = 0; 319 | maxLength = 0; 320 | maxLengthVary = 0; 321 | startStep = 0; 322 | endStep = 0; 323 | alphaFadeType = LightningFadeType.GENERATION; 324 | thicknessFadeType = LightningFadeType.NONE; 325 | childrenDetachedEnd = false; 326 | // setter 327 | _smoothPercentage = 50; 328 | _childrenSmoothPercentage = 0; 329 | _childrenAngleVariation = 60; 330 | _childrenProbability = 0.025; 331 | _childrenProbabilityDecay = .5; 332 | _childrenMaxGenerations = 1; 333 | _childrenMaxCount = 4; 334 | _childrenMaxCountDecay = .5; 335 | _childrenLengthDecay = .5; 336 | _wavelength = .3; 337 | _amplitude = .5; 338 | _speed = 1; 339 | // private 340 | _multi2 = .03; 341 | _sOffsets = [new Point(0, 0), new Point(0, 0)]; 342 | _bOffsets = [new Point(0, 0), new Point(0, 0)]; 343 | _seed1 = Math.random() * 100; 344 | _seed2 = Math.random() * 100; 345 | // internal 346 | lifeSpan = 0; 347 | position = 0; 348 | absolutePosition = 1; 349 | } 350 | 351 | /** 352 | * @private 353 | */ 354 | internal function initialize():void { 355 | //trace(this, "initialize"); 356 | // start life timer if needed 357 | if (lifeSpan > 0) { 358 | // TODO: only create once, but not every pool time, also it should start after added to stage?! 359 | _lifeTimer = new Timer(lifeSpan * 1000, 1); 360 | //_lifeTimer.delay = lifeSpan * 1000; 361 | //_lifeTimer.repeatCount = 1; 362 | _lifeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onLifeSpanEnd, false, 0, true); 363 | _lifeTimer.start(); 364 | } 365 | // setup steps (important to call with setter) 366 | steps = 100; 367 | // setup smoothing 368 | if (generation == 0) { 369 | if (!_smoothMatrix) 370 | _smoothMatrix = new Matrix(); 371 | _smooth = new flash.display.Sprite(); 372 | childrenSmooth = new flash.display.Sprite(); 373 | smoothPercentage = 50; 374 | childrenSmoothPercentage = 50; 375 | } else { 376 | _smooth = childrenSmooth = parentInstance.childrenSmooth; 377 | } 378 | } 379 | 380 | //---------------------------------- 381 | // Event Handlers 382 | //---------------------------------- 383 | 384 | /** 385 | * @private 386 | */ 387 | private function onRemoved(event:Event):void { 388 | dispose(); 389 | } 390 | 391 | /** 392 | * @private 393 | */ 394 | private function onLifeSpanEnd(event:TimerEvent):void { 395 | //trace(this, "onLifeSpanEnd"); 396 | if (this.parent) 397 | this.parent.removeChild(this); 398 | else 399 | dispose(); 400 | } 401 | 402 | //---------------------------------- 403 | // API 404 | //---------------------------------- 405 | 406 | /** 407 | * Disposes object and it's children. 408 | */ 409 | override public function dispose():void { 410 | super.dispose(); 411 | //trace(this, "dispose"); 412 | // remove listener(s) 413 | removeEventListener(Event.REMOVED_FROM_STAGE, onRemoved); 414 | // remove timer 415 | if (_lifeTimer) { 416 | _lifeTimer.removeEventListener(TimerEvent.TIMER, onLifeSpanEnd); 417 | _lifeTimer.stop(); 418 | } 419 | // remove children 420 | disposeAllChildren(); 421 | // reset some more variables before putting back to pool 422 | _lifeTimer = null; 423 | parentInstance = null; 424 | // pool back 425 | LightningPool.putLightning(this); 426 | } 427 | 428 | /** 429 | * Removes all child Lightning objects. 430 | */ 431 | public function disposeAllChildren():void { 432 | _childHolder.removeChildren(); 433 | } 434 | 435 | /** 436 | * Removes child Lightning objects over limit. 437 | */ 438 | public function validateChildren():void { 439 | if (_childHolder.numChildren && _childHolder.numChildren > _childrenMaxCount) { 440 | trace(this, "validateChildren", _childHolder.numChildren, _childrenMaxCount, _childHolder.numChildren); 441 | while (_childHolder.numChildren > _childrenMaxCount) { 442 | _childHolder.removeChildAt(_childHolder.numChildren - 1); 443 | } 444 | } 445 | } 446 | 447 | /** 448 | * Generates child Lightnings 449 | * 450 | * @param n TBD 451 | * @param recursive TBD 452 | */ 453 | public function generateChild(n:uint = 1, recursive:Boolean = false):void { 454 | if (generation < _childrenMaxGenerations && _childHolder.numChildren < _childrenMaxCount) { 455 | var targetChildSteps:uint = _steps * _childrenLengthDecay; 456 | if (targetChildSteps >= 2) { 457 | for (var i:uint = 0; i < n; i++) { 458 | var startStep:uint = Math.random() * _steps; 459 | var endStep:uint = Math.random() * _steps; 460 | while (endStep == startStep) 461 | endStep = Math.random() * _steps; 462 | // calc. child angle 463 | var childAngle:Number = Math.random() * _childrenAngleVariation - _childrenAngleVariation / 2; 464 | // create child Lightning 465 | //var child:Lightning = new Lightning(_color, thickness, generation + 1); 466 | var child:LightningBase = LightningPool.getLightning(); 467 | child.preInitialize(_color, thickness, generation + 1); 468 | child.parentInstance = this; 469 | child.lifeSpan = Math.random() * (childrenLifeSpanMax - childrenLifeSpanMin) + childrenLifeSpanMin; 470 | child.position = 1 - startStep / _steps; 471 | child.absolutePosition = absolutePosition * child.position; 472 | child.alphaFadeType = alphaFadeType; 473 | child.thicknessFadeType = thicknessFadeType; 474 | if (alphaFadeType == LightningFadeType.GENERATION) 475 | child.alpha = 1 - (1 / (_childrenMaxGenerations + 1)) * child.generation; 476 | if (thicknessFadeType == LightningFadeType.GENERATION) 477 | child.thickness = thickness - (thickness / (_childrenMaxGenerations + 1)) * child.generation; 478 | child.childrenMaxGenerations = _childrenMaxGenerations; 479 | child.childrenMaxCount = _childrenMaxCount * (1 - _childrenMaxCountDecay); 480 | child.childrenProbability = _childrenProbability * (1 - _childrenProbabilityDecay); 481 | child.childrenProbabilityDecay = _childrenProbabilityDecay; 482 | child.childrenLengthDecay = _childrenLengthDecay; 483 | child.childrenDetachedEnd = childrenDetachedEnd; 484 | child.wavelength = _wavelength; 485 | child.amplitude = _amplitude; 486 | child.speed = _speed; 487 | // call initialize later for children 488 | child.initialize(); 489 | // save some start vars. (this has been refactored from object) 490 | child.endStep = endStep; 491 | child.startStep = startStep; 492 | child.childAngle = childAngle; 493 | // setup display steps 494 | child.steps = _steps * (1 - _childrenLengthDecay); 495 | // add to display list 496 | _childHolder.addChild(child); 497 | // generate childs 498 | if (recursive) 499 | child.generateChild(n, true); 500 | } 501 | } 502 | } 503 | } 504 | 505 | /** 506 | * TBD 507 | */ 508 | public function updateBase(stroke:Stroke):void { 509 | // start update process 510 | _dx = endX - startX; 511 | _dy = endY - startY; 512 | _len = Math.sqrt(_dx * _dx + _dy * _dy); 513 | _sOffsets[0].x += (_steps / 100) * _speed; 514 | _sOffsets[0].y += (_steps / 100) * _speed; 515 | _sBitmapData.perlinNoise(_steps / 20, _steps / 20, 1, _seed1, false, true, 7, true, _sOffsets); 516 | var calculatedWavelength:Number = _steps * _wavelength; 517 | var calculatedSpeed:Number = (calculatedWavelength * .1) * _speed; 518 | _bOffsets[0].x -= calculatedSpeed; 519 | _bOffsets[0].y += calculatedSpeed; 520 | _bBitmapData.perlinNoise(calculatedWavelength, calculatedWavelength, 1, _seed2, false, true, 7, true, _bOffsets); 521 | if (_smoothPercentage > 0) { 522 | if (!_drawMatrix) 523 | _drawMatrix = new Matrix(); 524 | _drawMatrix.identity(); 525 | _drawMatrix.scale(_steps / _smooth.width, 1); 526 | _bBitmapData.draw(_smooth, _drawMatrix); 527 | } 528 | // get visibility from parent or by chance 529 | if (parentInstance) { 530 | visible = parent.visible; 531 | } else if (maxLength == 0) { 532 | visible = true; 533 | } else { 534 | var isVisibleProbability:Number; 535 | if (_len <= maxLength) 536 | isVisibleProbability = 1; 537 | else if (_len > maxLength + maxLengthVary) 538 | isVisibleProbability = 0; 539 | else 540 | isVisibleProbability = 1 - (_len - maxLength) / maxLengthVary; 541 | visible = Math.random() < isVisibleProbability ? true : false; 542 | } 543 | // generate children by chance 544 | const generateChildRandom:Number = Math.random(); 545 | if (generateChildRandom < _childrenProbability) 546 | generateChild(); 547 | // render only if visible 548 | if (visible) 549 | renderLightning(stroke); 550 | // update children 551 | const n:uint = _childHolder.numChildren; 552 | for (var i:uint = 0; i < n; i++) { 553 | Lightning(_childHolder.getChildAt(i)).updateBase(stroke); 554 | } 555 | } 556 | 557 | /** 558 | * TBD 559 | */ 560 | public function renderLightning(stroke:Stroke):void { 561 | 562 | // calculate angle 563 | _angle = Math.atan2(endY - startY, endX - startX); 564 | // iterate 565 | 566 | for (var i:uint = 0; i < _steps; i++) { 567 | // get current position 568 | const currentPosition:Number = 1 / _steps * (_steps - i) 569 | // calculate alpha and thickness 570 | var relAlpha:Number = 1; 571 | var relThickness:Number = thickness; 572 | if (alphaFadeType == LightningFadeType.TIP_TO_END) { 573 | relAlpha = absolutePosition * currentPosition; 574 | } 575 | if (thicknessFadeType == LightningFadeType.TIP_TO_END) { 576 | relThickness = thickness * (absolutePosition * currentPosition); 577 | } 578 | // draw lines with smoothing 579 | _sOffset = (_sBitmapData.getPixel(i, 0) - SMOOTH_COLOR) / WHITE_COLOR * _len * _multi2; 580 | _sOffsetX = Math.sin(_angle) * _sOffset; 581 | _sOffsetY = Math.cos(_angle) * _sOffset; 582 | _bOffset = (_bBitmapData.getPixel(i, 0) - SMOOTH_COLOR) / WHITE_COLOR * _len * _amplitude; 583 | _bOffsetX = Math.sin(_angle) * _bOffset; 584 | _bOffsetY = Math.cos(_angle) * _bOffset; 585 | _tx = startX + _dx / (_steps - 1) * i + _sOffsetX + _bOffsetX; 586 | _ty = startY + _dy / (_steps - 1) * i - _sOffsetY - _bOffsetY; 587 | if (i == 0) { 588 | stroke.addDegenerates(_tx, _ty); 589 | } 590 | stroke.addVertex(_tx, _ty, relThickness, _color, relAlpha, _color, relAlpha); 591 | 592 | // iterate and draw sub-lines 593 | const n:uint = _childHolder.numChildren; 594 | for (var j:uint = 0; j < n; j++) { 595 | var cL:Lightning = Lightning(_childHolder.getChildAt(j)); 596 | if (cL.startStep == i) { 597 | cL.startX = _tx; 598 | cL.startY = _ty; 599 | } 600 | if (cL.childrenDetachedEnd) { 601 | var arad:Number = _angle + cL.childAngle / 180 * Math.PI; 602 | var childLength:Number = _len * _childrenLengthDecay; 603 | cL.endX = cL.startX + Math.cos(arad) * childLength; 604 | cL.endY = cL.startY + Math.sin(arad) * childLength; 605 | } 606 | else { 607 | if (cL.endStep == i) { 608 | cL.endX = _tx; 609 | cL.endY = _ty; 610 | } 611 | } 612 | } 613 | } 614 | } 615 | 616 | /** 617 | * @private 618 | */ 619 | public function toString():String { 620 | return "[Lightning" 621 | + " id=" + id 622 | + " generation=" + generation 623 | + " numChildren=" + _childHolder.numChildren 624 | + " startToEndXY=" + int(startX) + "," + int(startY) + "|" + int(endX) + "," + int(endY) 625 | + "]"; 626 | } 627 | 628 | //---------------------------------- 629 | // Getters/Setters 630 | //---------------------------------- 631 | 632 | /** 633 | * Getter/Setter for the 'steps' property 634 | */ 635 | public function set steps(value:uint):void { 636 | value = constrain(value, 2, 8192); 637 | _steps = value; 638 | _sBitmapData = new BitmapData(_steps, 1, false); 639 | _bBitmapData = new BitmapData(_steps, 1, false); 640 | if (generation == 0) 641 | this.smoothPercentage = _smoothPercentage; 642 | } 643 | 644 | /** 645 | * @private 646 | */ 647 | public function get steps():uint { 648 | return _steps; 649 | } 650 | 651 | /** 652 | * Getter/Setter for the 'smoothPercentage' property 653 | */ 654 | public function set smoothPercentage(value:Number):void { 655 | if (_smooth) { 656 | _smoothPercentage = value; 657 | _smoothMatrix.identity(); 658 | _smoothMatrix.createGradientBox(_steps, 1); 659 | const ratioOffset:uint = _smoothPercentage / 100 * 128; 660 | _smooth.graphics.clear(); 661 | _smooth.graphics.beginGradientFill(GradientType.LINEAR, [SMOOTH_COLOR, SMOOTH_COLOR, SMOOTH_COLOR, SMOOTH_COLOR], [1, 0, 0, 1], [0, ratioOffset, 255 - ratioOffset, 255], _smoothMatrix); 662 | _smooth.graphics.drawRect(0, 0, _steps, 1); 663 | _smooth.graphics.endFill(); 664 | } 665 | } 666 | 667 | /** 668 | * @private 669 | */ 670 | public function get smoothPercentage():Number { 671 | return _smoothPercentage; 672 | } 673 | 674 | /** 675 | * Getter/Setter for the 'childrenSmoothPercentage' property 676 | */ 677 | public function set childrenSmoothPercentage(value:Number):void { 678 | _childrenSmoothPercentage = value; 679 | _smoothMatrix.identity(); 680 | _smoothMatrix.createGradientBox(_steps, 1); 681 | const ratioOffset:uint = _childrenSmoothPercentage / 100 * 128; 682 | childrenSmooth.graphics.clear(); 683 | childrenSmooth.graphics.beginGradientFill(GradientType.LINEAR, [SMOOTH_COLOR, SMOOTH_COLOR, SMOOTH_COLOR, SMOOTH_COLOR], [1, 0, 0, 1], [0, ratioOffset, 255 - ratioOffset, 255], _smoothMatrix); 684 | childrenSmooth.graphics.drawRect(0, 0, _steps, 1); 685 | childrenSmooth.graphics.endFill(); 686 | } 687 | 688 | /** 689 | * @private 690 | */ 691 | public function get childrenSmoothPercentage():Number { 692 | return _childrenSmoothPercentage; 693 | } 694 | 695 | /** 696 | * Getter/Setter for the 'color' property 697 | */ 698 | public function set color(value:uint):void { 699 | _color = value; 700 | const n:uint = _childHolder.numChildren; 701 | for (var i:uint = 0; i < n; i++) { 702 | Lightning(_childHolder.getChildAt(i)).color = value; 703 | } 704 | } 705 | 706 | /** 707 | * @private 708 | */ 709 | public function get color():uint { 710 | return _color; 711 | } 712 | 713 | /** 714 | * Getter/Setter for the 'childrenProbability' property 715 | */ 716 | public function set childrenProbability(value:Number):void { 717 | value = constrain(value); 718 | _childrenProbability = value; 719 | } 720 | 721 | /** 722 | * @private 723 | */ 724 | public function get childrenProbability():Number { 725 | return _childrenProbability; 726 | } 727 | 728 | /** 729 | * Getter/Setter for the 'childrenProbabilityDecay' property 730 | */ 731 | public function set childrenProbabilityDecay(value:Number):void { 732 | value = constrain(value); 733 | _childrenProbabilityDecay = value; 734 | } 735 | 736 | /** 737 | * @private 738 | */ 739 | public function get childrenProbabilityDecay():Number { 740 | return _childrenProbabilityDecay; 741 | } 742 | 743 | /** 744 | * Getter/Setter for the 'childrenLengthDecay' property 745 | */ 746 | public function set childrenLengthDecay(value:Number):void { 747 | value = constrain(value); 748 | _childrenLengthDecay = value; 749 | } 750 | 751 | /** 752 | * @private 753 | */ 754 | public function get childrenLengthDecay():Number { 755 | return _childrenLengthDecay; 756 | } 757 | 758 | /** 759 | * Getter/Setter for the 'childrenMaxGenerations' property 760 | */ 761 | public function set childrenMaxGenerations(value:uint):void { 762 | _childrenMaxGenerations = value; 763 | validateChildren(); 764 | } 765 | 766 | /** 767 | * @private 768 | */ 769 | public function get childrenMaxGenerations():uint { 770 | return _childrenMaxGenerations; 771 | } 772 | 773 | /** 774 | * Getter/Setter for the 'childrenMaxCount' property 775 | */ 776 | public function set childrenMaxCount(value:uint):void { 777 | _childrenMaxCount = value; 778 | validateChildren(); 779 | } 780 | 781 | /** 782 | * @private 783 | */ 784 | public function get childrenMaxCount():uint { 785 | return _childrenMaxCount; 786 | } 787 | 788 | /** 789 | * Getter/Setter for the 'childrenMaxCountDecay' property 790 | */ 791 | public function set childrenMaxCountDecay(value:Number):void { 792 | value = constrain(value); 793 | _childrenMaxCountDecay = value; 794 | } 795 | 796 | /** 797 | * @private 798 | */ 799 | public function get childrenMaxCountDecay():Number { 800 | return _childrenMaxCountDecay; 801 | } 802 | 803 | /** 804 | * Getter/Setter for the 'childrenAngleVariation' property 805 | */ 806 | public function set childrenAngleVariation(value:Number):void { 807 | _childrenAngleVariation = value; 808 | const n:uint = _childHolder.numChildren; 809 | for (var i:uint = 0; i < n; i++) { 810 | Lightning(_childHolder.getChildAt(i)).childAngle = Math.random() * value - value / 2; 811 | Lightning(_childHolder.getChildAt(i)).childrenAngleVariation = value; 812 | } 813 | } 814 | 815 | /** 816 | * @private 817 | */ 818 | public function get childrenAngleVariation():Number { 819 | return _childrenAngleVariation; 820 | } 821 | 822 | /** 823 | * Getter/Setter for the 'wavelength' property 824 | */ 825 | public function set wavelength(value:Number):void { 826 | _wavelength = value; 827 | const n:uint = _childHolder.numChildren; 828 | for (var i:uint = 0; i < n; i++) { 829 | Lightning(_childHolder.getChildAt(i)).wavelength = value; 830 | } 831 | } 832 | 833 | /** 834 | * @private 835 | */ 836 | public function get wavelength():Number { 837 | return _wavelength; 838 | } 839 | 840 | /** 841 | * Getter/Setter for the 'amplitude' property 842 | */ 843 | public function set amplitude(value:Number):void { 844 | _amplitude = value; 845 | const n:uint = _childHolder.numChildren; 846 | for (var i:uint = 0; i < n; i++) { 847 | Lightning(_childHolder.getChildAt(i)).amplitude = value; 848 | } 849 | } 850 | 851 | /** 852 | * @private 853 | */ 854 | public function get amplitude():Number { 855 | return _amplitude; 856 | } 857 | 858 | /** 859 | * Getter/Setter for the 'speed' property 860 | */ 861 | public function set speed(value:Number):void { 862 | _speed = value; 863 | const n:uint = _childHolder.numChildren; 864 | for (var i:uint = 0; i < n; i++) { 865 | Lightning(_childHolder.getChildAt(i)).speed = value; 866 | } 867 | } 868 | 869 | /** 870 | * @private 871 | */ 872 | public function get speed():Number { 873 | return _speed; 874 | } 875 | 876 | //---------------------------------- 877 | // Getters only (For debugging) 878 | //---------------------------------- 879 | 880 | /** 881 | * BitmapData used to generate noise with optional smoothing. 882 | */ 883 | public function get bBitmapData():BitmapData { 884 | return _bBitmapData; 885 | } 886 | 887 | /** 888 | * BitmapData used to generate noise. 889 | */ 890 | public function get sBitmapData():BitmapData { 891 | return _sBitmapData; 892 | } 893 | 894 | //---------------------------------- 895 | // Static Helper Methods 896 | //---------------------------------- 897 | 898 | /** 899 | * @private 900 | */ 901 | private static function constrain(num:Number, min:Number = 0, max:Number = 1):Number { 902 | if (num < min) return min; 903 | if (num > max) return max; 904 | return num; 905 | } 906 | } 907 | } 908 | 909 | -------------------------------------------------------------------------------- /src/main/actionscript/starling/extensions/lightning/LightningFadeType.as: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package starling.extensions.lightning { 25 | /** 26 | * Lightning Fade Type Enums 27 | * 28 | * @author Pierluigi Pesenti (blog.oaxoa.com) 29 | * @contributor Andras Csizmadia (www.vpmedia.eu) 30 | * @contributor IonSwitz (www.github.com/IonSwitz) 31 | * 32 | */ 33 | public final class LightningFadeType { 34 | 35 | /** 36 | * TBD 37 | */ 38 | public static const NONE:String = "none"; 39 | 40 | /** 41 | * TBD 42 | */ 43 | public static const GENERATION:String = "generation"; 44 | 45 | /** 46 | * TBD 47 | */ 48 | public static const TIP_TO_END:String = "tip"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/actionscript/starling/extensions/lightning/LightningPool.as: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package starling.extensions.lightning { 25 | /** 26 | * Lightning Object Pool 27 | * 28 | * @author Pierluigi Pesenti (blog.oaxoa.com) 29 | * @contributor Andras Csizmadia (www.vpmedia.eu) 30 | * @contributor IonSwitz (www.github.com/IonSwitz) 31 | * 32 | */ 33 | public final class LightningPool { 34 | 35 | /** 36 | * @private 37 | */ 38 | private static var MAX_VALUE:uint; 39 | 40 | /** 41 | * @private 42 | */ 43 | private static var GROWTH_VALUE:uint; 44 | 45 | /** 46 | * @private 47 | */ 48 | private static var COUNTER:uint; 49 | 50 | /** 51 | * @private 52 | */ 53 | private static var POOL:Vector.; 54 | 55 | /** 56 | * @private 57 | */ 58 | private static var CURRENT_ITEM:LightningBase; 59 | 60 | /** 61 | * @private 62 | */ 63 | private static const INITIALIZED:Boolean = initialize(32, 4); 64 | 65 | /** 66 | * @private 67 | */ 68 | private static function initialize(maxPoolSize:uint, growthValue:uint):Boolean { 69 | trace("LightningPool::initialize: " + arguments); 70 | MAX_VALUE = maxPoolSize; 71 | GROWTH_VALUE = growthValue; 72 | COUNTER = maxPoolSize; 73 | POOL = new Vector.(MAX_VALUE); 74 | // Pre-create objects 75 | var i:uint = maxPoolSize; 76 | while (--i > -1) 77 | POOL[i] = new Lightning(0, 0, 0, true); 78 | // Flag it 79 | return true; 80 | } 81 | 82 | /** 83 | * Get Lightning from pool 84 | */ 85 | public static function getLightning():LightningBase { 86 | // return top element if existing 87 | if (COUNTER > 0) 88 | return CURRENT_ITEM = POOL[--COUNTER]; 89 | // Pre-create objects 90 | var i:uint = GROWTH_VALUE; 91 | while (--i > -1) 92 | POOL.unshift(new Lightning(0, 0, 0, true)); 93 | COUNTER = GROWTH_VALUE; 94 | // Create another one as result 95 | return getLightning(); 96 | 97 | } 98 | 99 | /** 100 | * Put Lightning to pool 101 | */ 102 | public static function putLightning(disposedLightning:LightningBase):void { 103 | //trace("LightningPool::putLightning: " + disposedLightning); 104 | POOL[COUNTER++] = disposedLightning; 105 | } 106 | 107 | /** 108 | * Get pool size 109 | */ 110 | public static function getSize():uint { 111 | return COUNTER 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/actionscript/starling/extensions/lightning/LightningType.as: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2008 Pierluigi Pesenti (blog.oaxoa.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | package starling.extensions.lightning { 25 | /** 26 | * Lightning Preset Helper 27 | * 28 | * @author Pierluigi Pesenti (blog.oaxoa.com) 29 | * @contributor Andras Csizmadia (www.vpmedia.eu) 30 | * @contributor IonSwitz (www.github.com/IonSwitz) 31 | * 32 | */ 33 | public final class LightningType { 34 | 35 | /** 36 | * TBD 37 | */ 38 | public static const DISCHARGE:String = "discharge"; 39 | 40 | /** 41 | * TBD 42 | */ 43 | public static const LIGHTNING:String = "lightning"; 44 | 45 | /** 46 | * TBD 47 | */ 48 | public static const SHOCK:String = "shock"; 49 | 50 | /** 51 | * TBD 52 | */ 53 | public static function setType(lightning:Lightning, type:String):void { 54 | switch (type) { 55 | case DISCHARGE : 56 | lightning.childrenLifeSpanMin = 1; 57 | lightning.childrenLifeSpanMax = 3; 58 | lightning.childrenProbability = 1; // [0,1] 59 | lightning.childrenMaxGenerations = 3; 60 | lightning.childrenMaxCount = 4; 61 | lightning.childrenAngleVariation = 110; 62 | lightning.thickness = 2; 63 | lightning.steps = 100; 64 | lightning.smoothPercentage = 50; // [0,100] 65 | lightning.wavelength = .3; 66 | lightning.amplitude = .5; 67 | lightning.speed = .7; 68 | lightning.maxLength = 0; 69 | lightning.maxLengthVary = 0; 70 | lightning.childrenDetachedEnd = false; // true = lightning ; false = discharge 71 | lightning.alphaFadeType = LightningFadeType.GENERATION; 72 | lightning.thicknessFadeType = LightningFadeType.NONE; 73 | break; 74 | case LIGHTNING : 75 | lightning.childrenLifeSpanMin = .1; 76 | lightning.childrenLifeSpanMax = 2; 77 | lightning.childrenProbability = 1; 78 | lightning.childrenMaxGenerations = 3; 79 | lightning.childrenMaxCount = 4; 80 | lightning.childrenAngleVariation = 130; 81 | lightning.thickness = 3; 82 | lightning.steps = 100; 83 | lightning.smoothPercentage = 50; 84 | lightning.wavelength = .3; 85 | lightning.amplitude = .5; 86 | lightning.speed = 1; 87 | lightning.maxLength = 0; 88 | lightning.maxLengthVary = 0; 89 | lightning.childrenDetachedEnd = true; 90 | lightning.alphaFadeType = LightningFadeType.TIP_TO_END; 91 | lightning.thicknessFadeType = LightningFadeType.GENERATION; 92 | break; 93 | case SHOCK : 94 | lightning.childrenLifeSpanMin = .1; 95 | lightning.childrenLifeSpanMax = 2; 96 | lightning.childrenProbability = 1; 97 | lightning.childrenMaxGenerations = 4; 98 | lightning.childrenMaxCount = 6; 99 | lightning.childrenAngleVariation = 10; 100 | lightning.thickness = 5; 101 | lightning.thickness = 3; 102 | lightning.steps = 100; 103 | lightning.smoothPercentage = 50; 104 | lightning.wavelength = .3; 105 | lightning.amplitude = .5; 106 | lightning.speed = 1; 107 | lightning.maxLength = 0; 108 | lightning.maxLengthVary = 0; 109 | lightning.childrenDetachedEnd = true; 110 | lightning.alphaFadeType = LightningFadeType.TIP_TO_END; 111 | lightning.thicknessFadeType = LightningFadeType.GENERATION; 112 | break; 113 | } 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /src/main/libs/Starling-Extension-Graphics.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vpmedia/starling-extension-lightning/f79a71e69c63e637b9889df6d649161d1d5b41e2/src/main/libs/Starling-Extension-Graphics.swc -------------------------------------------------------------------------------- /src/main/libs/starling.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vpmedia/starling-extension-lightning/f79a71e69c63e637b9889df6d649161d1d5b41e2/src/main/libs/starling.swc -------------------------------------------------------------------------------- /src/main/resources/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vpmedia/starling-extension-lightning/f79a71e69c63e637b9889df6d649161d1d5b41e2/src/main/resources/empty.txt --------------------------------------------------------------------------------