├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── drawable │ │ │ │ ├── background.jpg │ │ │ │ ├── rain_texture.png │ │ │ │ └── particle_texture.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ └── raw │ │ │ │ ├── rain.plist │ │ │ │ ├── snow.plist │ │ │ │ └── test.plist │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── yang │ │ │ └── firework │ │ │ └── sample │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── yang │ │ │ └── firework │ │ │ └── sample │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── yang │ │ └── firework │ │ └── sample │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── firework ├── .gitignore ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ └── attrs.xml │ │ │ └── raw │ │ │ │ ├── simpe_fragment_shader.glsl │ │ │ │ ├── simple_vertex_shader.glsl │ │ │ │ ├── particle_frag.glsl │ │ │ │ └── particle_vert.glsl │ │ └── java │ │ │ └── com │ │ │ └── yang │ │ │ └── firework │ │ │ ├── ModeB.java │ │ │ ├── ModeA.java │ │ │ ├── BlendFunc.java │ │ │ ├── Color4F.java │ │ │ ├── Particle.java │ │ │ ├── Constants.java │ │ │ ├── Vec2.java │ │ │ ├── utils │ │ │ ├── RawResourceReader.java │ │ │ ├── TextureHelper.java │ │ │ └── ESShader.java │ │ │ ├── TextureLayer.java │ │ │ ├── FireworkView.java │ │ │ ├── ParticleLayer.java │ │ │ └── ParticleSystem.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── yang │ │ │ └── firework │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── yang │ │ └── firework │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── art └── demo.gif ├── .idea ├── copyright │ └── profiles_settings.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /firework/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':firework' 2 | -------------------------------------------------------------------------------- /art/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/art/demo.gif -------------------------------------------------------------------------------- /firework/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | firework 3 | 4 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /firework/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | firework 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/app/src/main/res/drawable/background.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/rain_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/app/src/main/res/drawable/rain_texture.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/particle_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/app/src/main/res/drawable/particle_texture.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqf19930712/firework/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # firework 2 | 3 | ![demo](https://github.com/yqf19930712/firework/blob/master/art/demo.gif) 4 | 5 | opengl es实现粒子效果,可加载particle designer导出的plist文件 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.iml 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /firework/src/main/res/raw/simpe_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform sampler2D u_texture; 4 | varying vec2 v_texCoord; 5 | 6 | void main() { 7 | 8 | gl_FragColor = texture2D(u_texture,v_texCoord); 9 | 10 | } -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /firework/src/main/java/com/yang/firework/ModeB.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | /** 4 | * Created by qinfeng on 16/8/4. 5 | */ 6 | 7 | public class ModeB { 8 | float angle; 9 | float degreesPerSecond; 10 | float radius; 11 | float deltaRadius; 12 | } 13 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /firework/src/main/java/com/yang/firework/ModeA.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | /** 4 | * Created by qinfeng on 16/8/4. 5 | */ 6 | 7 | public class ModeA { 8 | Vec2 dir = new Vec2(0f,0f); 9 | float radialAccel; 10 | float tangentialAccel; 11 | } 12 | -------------------------------------------------------------------------------- /firework/src/main/res/raw/simple_vertex_shader.glsl: -------------------------------------------------------------------------------- 1 | 2 | precision mediump float; 3 | 4 | attribute vec2 a_position; 5 | attribute vec2 a_texCoord; 6 | 7 | varying vec2 v_texCoord; 8 | void main() { 9 | gl_Position = vec4(a_position,0.0,1.0); 10 | v_texCoord = a_texCoord; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /firework/src/main/res/raw/particle_frag.glsl: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform sampler2D u_texture; 4 | 5 | varying vec4 v_fragmentColor; 6 | varying vec2 v_texCoord; 7 | 8 | void main() 9 | { 10 | 11 | gl_FragColor = v_fragmentColor * texture2D(u_texture, v_texCoord) ; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /firework/src/main/java/com/yang/firework/BlendFunc.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | /** 4 | * Created by qinfeng on 16/8/4. 5 | */ 6 | 7 | class BlendFunc { 8 | int src; 9 | int dst; 10 | public BlendFunc(int src, int dst) { 11 | this.src = src; 12 | this.dst = dst; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /firework/src/main/res/raw/particle_vert.glsl: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform mat4 u_matrix; 4 | 5 | attribute vec2 a_position; 6 | attribute vec4 a_color; 7 | attribute vec2 a_texCoord; 8 | 9 | 10 | varying vec4 v_fragmentColor; 11 | varying vec2 v_texCoord; 12 | 13 | void main() 14 | { 15 | gl_Position = u_matrix * vec4(a_position,0.0,1.0); 16 | v_fragmentColor = a_color; 17 | v_texCoord = a_texCoord; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /firework/src/main/java/com/yang/firework/Color4F.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | /** 4 | * Created by qinfeng on 16/8/4. 5 | */ 6 | public class Color4F { 7 | float r; 8 | float g; 9 | float b; 10 | float a; 11 | 12 | public Color4F() { 13 | } 14 | 15 | public Color4F(float r, float g, float b, float a) { 16 | this.r = r; 17 | this.g = g; 18 | this.b = b; 19 | this.a = a; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /firework/src/test/java/com/yang/firework/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/test/java/com/yang/firework/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework.sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /firework/src/main/java/com/yang/firework/Particle.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | /** 4 | * Created by qinfeng on 16/8/4. 5 | */ 6 | 7 | public class Particle { 8 | Vec2 pos = new Vec2(0f,0f);; 9 | Vec2 startPos = new Vec2(0f,0f); 10 | Color4F color = new Color4F(0f,0f,0f,1f); 11 | Color4F deltaColor = new Color4F(0f,0f,0f,1f); 12 | float size; 13 | float deltaSize; 14 | float rotation; 15 | float deltaRotation; 16 | float timeToLive; 17 | int atlasIndex; 18 | // Mode A: gravity, direction, radial accel, tangential accel. 19 | ModeA modeA = new ModeA(); 20 | 21 | // Mode B: radius mode. 22 | ModeB modeB = new ModeB(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/cocos2dx/V3.5/adt-bundle/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /firework/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/cocos2dx/V3.5/adt-bundle/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /firework/src/androidTest/java/com/yang/firework/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.yang.firework.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/yang/firework/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework.sample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.yang.firework.sample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /firework/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | testCompile 'junit:junit:4.12' 30 | compile 'com.googlecode.plist:dd-plist:1.16' 31 | } 32 | -------------------------------------------------------------------------------- /firework/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.1" 6 | defaultConfig { 7 | applicationId "com.yang.firework.sample" 8 | minSdkVersion 15 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:24.2.1' 28 | testCompile 'junit:junit:4.12' 29 | compile project(':firework') 30 | } 31 | -------------------------------------------------------------------------------- /firework/src/main/java/com/yang/firework/Constants.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | /** 4 | * Created by qinfeng on 16/8/4. 5 | */ 6 | 7 | public class Constants { 8 | /* BlendingFactorDest */ 9 | public static final int GL_ZERO = 0; 10 | public static final int GL_ONE = 1; 11 | public static final int GL_SRC_COLOR = 0x0300; 12 | public static final int GL_ONE_MINUS_SRC_COLOR = 0x0301; 13 | public static final int GL_SRC_ALPHA = 0x0302; 14 | public static final int GL_ONE_MINUS_SRC_ALPHA = 0x0303; 15 | public static final int GL_DST_ALPHA = 0x0304; 16 | public static final int GL_ONE_MINUS_DST_ALPHA = 0x0305; 17 | 18 | /* BlendingFactorSrc */ 19 | /* GL_ZERO */ 20 | /* GL_ONE */ 21 | public static final int GL_DST_COLOR = 0x0306; 22 | public static final int GL_ONE_MINUS_DST_COLOR = 0x0307; 23 | public static final int GL_SRC_ALPHA_SATURATE = 0x0308; 24 | /* GL_SRC_ALPHA */ 25 | /* GL_ONE_MINUS_SRC_ALPHA */ 26 | /* GL_DST_ALPHA */ 27 | /* GL_ONE_MINUS_DST_ALPHA */ 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /firework/src/main/java/com/yang/firework/Vec2.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework; 2 | 3 | /** 4 | * Created by qinfeng on 16/8/4. 5 | */ 6 | 7 | public class Vec2 { 8 | public float x; 9 | public float y; 10 | 11 | public Vec2(float x, float y) { 12 | this.x = x; 13 | this.y = y; 14 | } 15 | 16 | public Vec2(Vec2 vec2) { 17 | this.x = vec2.x; 18 | this.y = vec2.y; 19 | } 20 | 21 | 22 | public Vec2 add(Vec2 vec2) { 23 | return new Vec2(x + vec2.x, y + vec2.y); 24 | } 25 | 26 | public float getAngle(){ 27 | return (float) Math.atan2(y,x); 28 | } 29 | 30 | public Vec2 subtract(Vec2 vec2) { 31 | return new Vec2(x - vec2.x, y - vec2.y); 32 | } 33 | 34 | public float length() { 35 | return (float) Math.sqrt(x * x + y * y); 36 | } 37 | 38 | 39 | public Vec2 scale(float f) { 40 | return new Vec2( 41 | x * f, 42 | y * f); 43 | } 44 | 45 | public Vec2 getNormalized() { 46 | return scale(1f / length()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /firework/src/main/java/com/yang/firework/utils/RawResourceReader.java: -------------------------------------------------------------------------------- 1 | package com.yang.firework.utils; 2 | 3 | import android.content.Context; 4 | 5 | import java.io.BufferedReader; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.InputStreamReader; 9 | 10 | public class RawResourceReader 11 | { 12 | public static String readTextFileFromRawResource(final Context context, 13 | final int resourceId) 14 | { 15 | final InputStream inputStream = context.getResources().openRawResource( 16 | resourceId); 17 | final InputStreamReader inputStreamReader = new InputStreamReader( 18 | inputStream); 19 | final BufferedReader bufferedReader = new BufferedReader( 20 | inputStreamReader); 21 | 22 | String nextLine; 23 | final StringBuilder body = new StringBuilder(); 24 | 25 | try 26 | { 27 | while ((nextLine = bufferedReader.readLine()) != null) 28 | { 29 | body.append(nextLine); 30 | body.append('\n'); 31 | } 32 | } 33 | catch (IOException e) 34 | { 35 | return null; 36 | } 37 | 38 | return body.toString(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | 16 | 17 | 18 | 23 | 24 |