├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── Bezier
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── h1.png
│ │ │ │ ├── h2.png
│ │ │ │ └── h3.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_show_bezier1.xml
│ │ │ │ ├── activity_show_bezier3.xml
│ │ │ │ ├── activity_show_bezier4.xml
│ │ │ │ ├── activity_show_bezier5.xml
│ │ │ │ ├── activity_show_bezier2.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── chan
│ │ │ │ └── bezier
│ │ │ │ ├── activity
│ │ │ │ ├── ShowBezier1Activity.java
│ │ │ │ ├── ShowBezier3Activity.java
│ │ │ │ ├── ShowBezier4Activity.java
│ │ │ │ ├── ShowBezier5Activity.java
│ │ │ │ └── ShowBezier2Activity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── bezier_views
│ │ │ │ ├── BezierView_Quad.java
│ │ │ │ ├── BezierView_Cubic.java
│ │ │ │ ├── BezierView_Heart.java
│ │ │ │ ├── BezierView_FallInLove.java
│ │ │ │ └── BezierView_ElasticBall.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── chan
│ │ │ └── bezier
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── chan
│ │ └── bezier
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── screenshots
├── a.gif
├── b.gif
├── c.gif
├── d.gif
└── e.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | BezierDemo
--------------------------------------------------------------------------------
/Bezier/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'Bezier'
2 |
--------------------------------------------------------------------------------
/screenshots/a.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/screenshots/a.gif
--------------------------------------------------------------------------------
/screenshots/b.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/screenshots/b.gif
--------------------------------------------------------------------------------
/screenshots/c.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/screenshots/c.gif
--------------------------------------------------------------------------------
/screenshots/d.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/screenshots/d.gif
--------------------------------------------------------------------------------
/screenshots/e.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/screenshots/e.gif
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.8_Bezier
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Bezier/src/main/res/drawable/h1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/Bezier/src/main/res/drawable/h1.png
--------------------------------------------------------------------------------
/Bezier/src/main/res/drawable/h2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/Bezier/src/main/res/drawable/h2.png
--------------------------------------------------------------------------------
/Bezier/src/main/res/drawable/h3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/Bezier/src/main/res/drawable/h3.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/Bezier/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Bezier/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/Bezier/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Bezier/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/Bezier/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Bezier/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/Bezier/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Bezier/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ImWaitingForU/BezierDemo/HEAD/Bezier/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/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.10-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Bezier/src/test/java/com/chan/bezier/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect () throws Exception {
13 | assertEquals (4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/Bezier/src/androidTest/java/com/chan/bezier/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest () {
11 | super (Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/Bezier/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/activity/ShowBezier1Activity.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.activity;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | import com.chan.bezier.R;
7 |
8 | public class ShowBezier1Activity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate (Bundle savedInstanceState) {
12 | super.onCreate (savedInstanceState);
13 | setContentView (R.layout.activity_show_bezier1);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/activity/ShowBezier3Activity.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.activity;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | import com.chan.bezier.R;
7 |
8 | public class ShowBezier3Activity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate (Bundle savedInstanceState) {
12 | super.onCreate (savedInstanceState);
13 | setContentView (R.layout.activity_show_bezier3);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BezierDemo
2 | 贝塞尔曲线的小例子
3 |
4 |
5 | 初识贝塞尔曲线:
6 |
7 | > http://blog.csdn.net/rosechan/article/details/51458317
8 |
9 | 绘制有弹性的小球
10 | > http://www.jianshu.com/p/791d3a791ec2
11 |
12 | 属性动画简单使用之实现爱的贝塞尔曲线浪漫告白效果
13 | >http://www.2cto.com/kf/201603/496163.html
14 |
15 | 效果:
16 | ---
17 |
18 | 1-二阶贝塞尔曲线
19 |
20 | 
21 |
22 | 2-三阶贝塞尔曲线
23 |
24 | 
25 |
26 | 3-由圆变成心形
27 |
28 | 
29 |
30 | 4-有弹性的圆
31 |
32 | 
33 |
34 | 5-上升的爱心
35 |
36 | 
37 |
--------------------------------------------------------------------------------
/Bezier/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.chan.bezier"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
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(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | }
27 |
--------------------------------------------------------------------------------
/Bezier/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 E:\sdk\android_sdk_24.4.1/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/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/layout/activity_show_bezier1.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/layout/activity_show_bezier3.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/activity/ShowBezier4Activity.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import com.chan.bezier.R;
9 | import com.chan.bezier.bezier_views.BezierView_ElasticBall;
10 |
11 | public class ShowBezier4Activity extends AppCompatActivity {
12 |
13 | private Button go;
14 | private BezierView_ElasticBall mElasticBall;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_show_bezier4);
20 | go = (Button) findViewById(R.id.go);
21 | mElasticBall = (BezierView_ElasticBall) findViewById(R.id.elasticBall);
22 | go.setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View v) {
25 | mElasticBall.startAnimation ();
26 | }
27 | });
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/layout/activity_show_bezier4.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
19 |
20 |
24 |
25 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/layout/activity_show_bezier5.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
18 |
19 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/activity/ShowBezier5Activity.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import com.chan.bezier.R;
9 | import com.chan.bezier.bezier_views.BezierView_FallInLove;
10 |
11 | public class ShowBezier5Activity extends AppCompatActivity {
12 |
13 | private Button btn_fallInLove;
14 | private BezierView_FallInLove fallInLove;
15 |
16 | @Override
17 | protected void onCreate (Bundle savedInstanceState) {
18 | super.onCreate (savedInstanceState);
19 | setContentView (R.layout.activity_show_bezier5);
20 |
21 | fallInLove = (BezierView_FallInLove) findViewById (R.id.fallInLove);
22 |
23 | btn_fallInLove = (Button) findViewById (R.id.btn_fallInLove);
24 | btn_fallInLove.setOnClickListener (new View.OnClickListener () {
25 | @Override
26 | public void onClick (View v) {
27 | fallInLove.addHeart (ShowBezier5Activity.this);
28 | }
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Bezier/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/activity/ShowBezier2Activity.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.activity;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.widget.RadioGroup;
6 |
7 | import com.chan.bezier.bezier_views.BezierView_Cubic;
8 | import com.chan.bezier.R;
9 |
10 | public class ShowBezier2Activity extends AppCompatActivity {
11 |
12 | private RadioGroup rg;
13 | private BezierView_Cubic mBezierView_cubic;
14 |
15 | @Override
16 | protected void onCreate (Bundle savedInstanceState) {
17 | super.onCreate (savedInstanceState);
18 | setContentView (R.layout.activity_show_bezier2);
19 |
20 | mBezierView_cubic = (BezierView_Cubic) findViewById (R.id.bezierview_cubic);
21 | rg = (RadioGroup) findViewById (R.id.rg);
22 |
23 | rg.setOnCheckedChangeListener (new RadioGroup.OnCheckedChangeListener () {
24 | @Override
25 | public void onCheckedChanged (RadioGroup group, int checkedId) {
26 | if (checkedId==R.id.rb1){
27 | mBezierView_cubic.setMode (1);
28 | }else if (checkedId==R.id.rb2){
29 | mBezierView_cubic.setMode (2);
30 | }
31 | }
32 | });
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/layout/activity_show_bezier2.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
25 |
26 |
32 |
33 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/Bezier/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.chan.bezier.activity.ShowBezier1Activity;
10 | import com.chan.bezier.activity.ShowBezier2Activity;
11 | import com.chan.bezier.activity.ShowBezier3Activity;
12 | import com.chan.bezier.activity.ShowBezier4Activity;
13 | import com.chan.bezier.activity.ShowBezier5Activity;
14 |
15 | public class MainActivity extends AppCompatActivity
16 | implements
17 | View.OnClickListener {
18 |
19 | private Button btn1;
20 | private Button btn2;
21 | private Button btn3;
22 | private Button btn4;
23 | private Button btn5;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 |
30 | btn1 = (Button) findViewById(R.id.btn1);
31 | btn2 = (Button) findViewById(R.id.btn2);
32 | btn3 = (Button) findViewById(R.id.btn3);
33 | btn4 = (Button) findViewById(R.id.btn4);
34 | btn5 = (Button) findViewById(R.id.btn5);
35 |
36 | btn1.setOnClickListener(this);
37 | btn2.setOnClickListener(this);
38 | btn3.setOnClickListener(this);
39 | btn4.setOnClickListener(this);
40 | btn5.setOnClickListener(this);
41 | }
42 |
43 | @Override
44 | public void onClick(View v) {
45 | switch (v.getId()) {
46 | case R.id.btn1 :
47 | startActivity(new Intent(MainActivity.this,
48 | ShowBezier1Activity.class));
49 |
50 | break;
51 | case R.id.btn2 :
52 | startActivity(new Intent(MainActivity.this,
53 | ShowBezier2Activity.class));
54 | break;
55 | case R.id.btn3 :
56 | startActivity(new Intent(MainActivity.this,
57 | ShowBezier3Activity.class));
58 | break;
59 | case R.id.btn4 :
60 | startActivity(new Intent(MainActivity.this,
61 | ShowBezier4Activity.class));
62 | break;
63 | case R.id.btn5 :
64 | startActivity(new Intent(MainActivity.this,
65 | ShowBezier5Activity.class));
66 | break;
67 |
68 | default :
69 | break;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/bezier_views/BezierView_Quad.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.bezier_views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.graphics.PointF;
9 | import android.util.AttributeSet;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 |
13 | /**
14 | * Created by Chan on 2016/5/19.
15 | *
16 | * 二阶贝塞尔曲线的理解练习,根据触摸的位置更新控制点
17 | */
18 | public class BezierView_Quad extends View {
19 |
20 | private Paint mPaint;
21 |
22 | private int centerX, centerY; // 视图的中心点
23 |
24 | private PointF start; // 起始点
25 | private PointF end; // 结束点
26 | private PointF control; // 控制点
27 |
28 | public BezierView_Quad (Context context) {
29 | super(context);
30 |
31 | }
32 |
33 | public BezierView_Quad (Context context, AttributeSet attrs) {
34 | super (context, attrs);
35 |
36 | mPaint = new Paint();
37 | mPaint.setColor(Color.BLUE);
38 | mPaint.setStrokeWidth(5f);
39 | mPaint.setAntiAlias(true);
40 | mPaint.setStyle(Paint.Style.STROKE);
41 | mPaint.setTextSize(60);
42 |
43 | start = new PointF(0, 0);
44 | end = new PointF(0, 0);
45 | control = new PointF(0, 0);
46 | }
47 |
48 | @Override
49 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
50 | super.onSizeChanged(w, h, oldw, oldh);
51 |
52 | centerX = w / 2;
53 | centerY = h / 2;
54 |
55 | // 初始化数据点和控制点的位置
56 | start.x = centerX - 200;
57 | start.y = centerY;
58 |
59 | end.x = centerX + 200;
60 | end.y = centerY;
61 |
62 | control.x = centerX;
63 | control.y = centerY - 100;
64 |
65 | }
66 |
67 | @Override
68 | protected void onDraw(Canvas canvas) {
69 | super.onDraw(canvas);
70 | // 绘制数据点和控制点
71 | mPaint.setColor(Color.RED);
72 | mPaint.setStrokeWidth(20);
73 | canvas.drawPoint(start.x, start.y, mPaint);
74 | canvas.drawPoint(end.x, end.y, mPaint);
75 | mPaint.setColor(Color.BLUE);
76 | canvas.drawPoint(control.x, control.y, mPaint);
77 |
78 | //绘制辅助线
79 | mPaint.setColor (Color.BLACK);
80 | mPaint.setStrokeWidth (5);
81 | canvas.drawLine (start.x,start.y,control.x,control.y,mPaint);
82 | canvas.drawLine (control.x,control.y,end.x,end.y,mPaint);
83 |
84 | //绘制贝塞尔曲线
85 | mPaint.setColor (Color.GREEN);
86 | mPaint.setStrokeWidth (4);
87 |
88 | Path path = new Path ();
89 | path.moveTo (start.x,start.y);
90 | path.quadTo (control.x,control.y,end.x,end.y);
91 |
92 | canvas.drawPath (path,mPaint);
93 | }
94 |
95 | @Override
96 | public boolean onTouchEvent(MotionEvent event) {
97 | control.x = event.getX();
98 | control.y = event.getY();
99 | invalidate();
100 | return true;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/bezier_views/BezierView_Cubic.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.bezier_views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.graphics.PointF;
9 | import android.util.AttributeSet;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 |
13 | /**
14 | * Created by Chan on 2016/5/19.
15 | *
16 | * 三阶贝塞尔曲线演示
17 | */
18 | public class BezierView_Cubic extends View {
19 |
20 | private Paint mPaint;
21 |
22 | private int centerX, centerY; // 视图的中心点
23 |
24 | private PointF start; // 起始点
25 | private PointF end; // 结束点
26 | private PointF control1; // 控制点1
27 | private PointF control2; // 控制点2
28 |
29 | private int mode = 1;// 通过mode判断当前控制哪一个控制点
30 |
31 | public void setMode(int newMode){
32 | this.mode = newMode;
33 | }
34 |
35 | public BezierView_Cubic(Context context) {
36 | super(context);
37 | }
38 |
39 | public BezierView_Cubic(Context context, AttributeSet attrs) {
40 | super(context, attrs);
41 |
42 | mPaint = new Paint();
43 | mPaint.setAntiAlias(true);
44 | mPaint.setStyle(Paint.Style.STROKE);
45 | mPaint.setTextSize(60);
46 |
47 | start = new PointF(0, 0);
48 | end = new PointF(0, 0);
49 | control1 = new PointF(0, 0);
50 | control2 = new PointF(0, 0);
51 | }
52 |
53 | @Override
54 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
55 | super.onSizeChanged(w, h, oldw, oldh);
56 |
57 | centerX = w / 2;
58 | centerY = h / 2;
59 |
60 | // 初始化数据点和控制点的位置
61 | start.x = centerX - 200;
62 | start.y = centerY;
63 |
64 | end.x = centerX + 200;
65 | end.y = centerY;
66 |
67 | control1.x = centerX;
68 | control1.y = centerY - 100;
69 |
70 | control2.x = centerX;
71 | control2.y = centerY + 100;
72 | }
73 |
74 | @Override
75 | protected void onDraw(Canvas canvas) {
76 | super.onDraw(canvas);
77 | // 绘制数据点和控制点
78 | mPaint.setColor(Color.RED);
79 | mPaint.setStrokeWidth(20);
80 | canvas.drawPoint(start.x, start.y, mPaint);
81 | canvas.drawPoint(end.x, end.y, mPaint);
82 | mPaint.setColor(Color.BLUE);
83 | canvas.drawPoint(control1.x, control1.y, mPaint);
84 | canvas.drawPoint(control2.x, control2.y, mPaint);
85 |
86 | // 绘制辅助线
87 | mPaint.setColor(Color.BLACK);
88 | mPaint.setStrokeWidth(5);
89 | canvas.drawLine(start.x, start.y, control1.x, control1.y, mPaint);
90 | canvas.drawLine(control1.x, control1.y, control2.x, control2.y, mPaint);
91 | canvas.drawLine(control2.x, control2.y, end.x, end.y, mPaint);
92 |
93 | // 绘制贝塞尔曲线
94 | mPaint.setColor(Color.GREEN);
95 | mPaint.setStrokeWidth(4);
96 |
97 | Path path = new Path();
98 | path.moveTo(start.x, start.y);
99 | path.cubicTo(control1.x, control1.y, control2.x, control2.y, end.x,
100 | end.y);
101 |
102 | canvas.drawPath(path, mPaint);
103 | }
104 |
105 | @Override
106 | public boolean onTouchEvent(MotionEvent event) {
107 | if (mode == 1) {
108 | control1.x = event.getX();
109 | control1.y = event.getY();
110 | } else if (mode == 2) {
111 | control2.x = event.getX();
112 | control2.y = event.getY();
113 | }
114 | invalidate();
115 | return true;
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/bezier_views/BezierView_Heart.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.bezier_views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.graphics.PointF;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | /**
13 | * Created by Chan on 2016/5/19.
14 | *
15 | * 由圆形绘制成心形
16 | */
17 | public class BezierView_Heart extends View {
18 | private static final float C = 0.551915024494f; // 一个常量,用来计算绘制圆形贝塞尔曲线控制点的位置
19 |
20 | private Paint mPaint;
21 | private int mCenterX, mCenterY;
22 |
23 | private PointF mCenter = new PointF(0, 0);
24 | private float mCircleRadius = 200; // 圆的半径
25 | private float mDifference = mCircleRadius*C; // 圆形的控制点与数据点的差值
26 |
27 | private float[] mData = new float[8]; // 顺时针记录绘制圆形的四个数据点
28 | private float[] mCtrl = new float[16]; // 顺时针记录绘制圆形的八个控制点
29 |
30 | private float mDuration = 1000; // 变化总时长
31 | private float mCurrent = 0; // 当前已进行时长
32 | private float mCount = 100; // 将时长总共划分多少份
33 | private float mPiece = mDuration/mCount; // 每一份的时长
34 |
35 |
36 | public BezierView_Heart(Context context) {
37 | this(context, null);
38 |
39 | }
40 |
41 | public BezierView_Heart(Context context, AttributeSet attrs) {
42 | super(context, attrs);
43 |
44 | mPaint = new Paint();
45 | mPaint.setColor(Color.BLACK);
46 | mPaint.setStrokeWidth(8);
47 | mPaint.setStyle(Paint.Style.STROKE);
48 | mPaint.setTextSize(60);
49 |
50 |
51 | // 初始化数据点
52 |
53 | mData[0] = 0;
54 | mData[1] = mCircleRadius;
55 |
56 | mData[2] = mCircleRadius;
57 | mData[3] = 0;
58 |
59 | mData[4] = 0;
60 | mData[5] = -mCircleRadius;
61 |
62 | mData[6] = -mCircleRadius;
63 | mData[7] = 0;
64 |
65 | // 初始化控制点
66 |
67 | mCtrl[0] = mData[0]+mDifference;
68 | mCtrl[1] = mData[1];
69 |
70 | mCtrl[2] = mData[2];
71 | mCtrl[3] = mData[3]+mDifference;
72 |
73 | mCtrl[4] = mData[2];
74 | mCtrl[5] = mData[3]-mDifference;
75 |
76 | mCtrl[6] = mData[4]+mDifference;
77 | mCtrl[7] = mData[5];
78 |
79 | mCtrl[8] = mData[4]-mDifference;
80 | mCtrl[9] = mData[5];
81 |
82 | mCtrl[10] = mData[6];
83 | mCtrl[11] = mData[7]-mDifference;
84 |
85 | mCtrl[12] = mData[6];
86 | mCtrl[13] = mData[7]+mDifference;
87 |
88 | mCtrl[14] = mData[0]-mDifference;
89 | mCtrl[15] = mData[1];
90 | }
91 |
92 |
93 | @Override
94 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
95 | super.onSizeChanged(w, h, oldw, oldh);
96 | mCenterX = w / 2;
97 | mCenterY = h / 2;
98 | }
99 |
100 |
101 | @Override
102 | protected void onDraw(Canvas canvas) {
103 | super.onDraw(canvas);
104 | drawCoordinateSystem(canvas); // 绘制坐标系
105 |
106 | canvas.translate(mCenterX, mCenterY); // 将坐标系移动到画布中央
107 | canvas.scale(1,-1); // 翻转Y轴
108 |
109 | drawAuxiliaryLine(canvas);
110 |
111 |
112 | // 绘制贝塞尔曲线
113 | mPaint.setColor(Color.RED);
114 | mPaint.setStrokeWidth(8);
115 |
116 | Path path = new Path();
117 | path.moveTo(mData[0],mData[1]);
118 |
119 | path.cubicTo(mCtrl[0], mCtrl[1], mCtrl[2], mCtrl[3], mData[2], mData[3]);
120 | path.cubicTo(mCtrl[4], mCtrl[5], mCtrl[6], mCtrl[7], mData[4], mData[5]);
121 | path.cubicTo(mCtrl[8], mCtrl[9], mCtrl[10], mCtrl[11], mData[6], mData[7]);
122 | path.cubicTo(mCtrl[12], mCtrl[13], mCtrl[14], mCtrl[15], mData[0], mData[1]);
123 |
124 | canvas.drawPath(path, mPaint);
125 |
126 | mCurrent += mPiece;
127 | if (mCurrent < mDuration){
128 |
129 | mData[1] -= 120/mCount;
130 | mCtrl[7] += 80/mCount;
131 | mCtrl[9] += 80/mCount;
132 |
133 | mCtrl[4] -= 20/mCount;
134 | mCtrl[10] += 20/mCount;
135 |
136 | postInvalidateDelayed((long) mPiece);
137 | }
138 | }
139 |
140 | // 绘制辅助线
141 | private void drawAuxiliaryLine(Canvas canvas) {
142 | // 绘制数据点和控制点
143 | mPaint.setColor(Color.GRAY);
144 | mPaint.setStrokeWidth(20);
145 |
146 | for (int i=0; i<8; i+=2){
147 | canvas.drawPoint(mData[i],mData[i+1], mPaint);
148 | }
149 |
150 | for (int i=0; i<16; i+=2){
151 | canvas.drawPoint(mCtrl[i], mCtrl[i+1], mPaint);
152 | }
153 |
154 |
155 | // 绘制辅助线
156 | mPaint.setStrokeWidth(4);
157 |
158 | for (int i=2, j=2; i<8; i+=2, j+=4){
159 | canvas.drawLine(mData[i],mData[i+1],mCtrl[j],mCtrl[j+1],mPaint);
160 | canvas.drawLine(mData[i],mData[i+1],mCtrl[j+2],mCtrl[j+3],mPaint);
161 | }
162 | canvas.drawLine(mData[0],mData[1],mCtrl[0],mCtrl[1],mPaint);
163 | canvas.drawLine(mData[0],mData[1],mCtrl[14],mCtrl[15],mPaint);
164 | }
165 |
166 | // 绘制坐标系
167 | private void drawCoordinateSystem(Canvas canvas) {
168 | canvas.save(); // 绘制做坐标系
169 |
170 | canvas.translate(mCenterX, mCenterY); // 将坐标系移动到画布中央
171 | canvas.scale(1,-1); // 翻转Y轴
172 |
173 | Paint fuzhuPaint = new Paint();
174 | fuzhuPaint.setColor(Color.RED);
175 | fuzhuPaint.setStrokeWidth(5);
176 | fuzhuPaint.setStyle(Paint.Style.STROKE);
177 |
178 | canvas.drawLine(0, -2000, 0, 2000, fuzhuPaint);
179 | canvas.drawLine(-2000, 0, 2000, 0, fuzhuPaint);
180 |
181 | canvas.restore();
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/bezier_views/BezierView_FallInLove.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.bezier_views;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.TypeEvaluator;
6 | import android.animation.ValueAnimator;
7 | import android.content.Context;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.graphics.PointF;
11 | import android.util.AttributeSet;
12 | import android.util.Log;
13 | import android.widget.ImageView;
14 | import android.widget.RelativeLayout;
15 |
16 | import com.chan.bezier.R;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Random;
21 |
22 | /**
23 | * Created by Chan on 2016/5/22.
24 | *
25 | * 使用贝塞尔曲线绘制上升的爱心
26 | */
27 | public class BezierView_FallInLove extends RelativeLayout {
28 |
29 | // 存放爱心的图片
30 | private List heartList;
31 |
32 | // 屏幕宽高
33 | private int mWidth;
34 | private int mHeight;
35 |
36 | private Random random = new Random();
37 |
38 | private LayoutParams params;
39 |
40 | private PointF start; // 起始点
41 | private PointF end; // 终止点
42 | private PointF control1;// 控制点1
43 | private PointF control2;// 控制点2
44 |
45 | private Paint paint;
46 |
47 | public BezierView_FallInLove(Context context) {
48 | super(context);
49 | init();
50 | setWillNotDraw(false);
51 | paint = new Paint();
52 | paint.setStyle(Paint.Style.STROKE);
53 | paint.setStrokeWidth(5);
54 | paint.setColor(Color.BLACK);
55 | paint.setAntiAlias(true);
56 | }
57 |
58 | public BezierView_FallInLove(Context context, AttributeSet attrs) {
59 | super(context, attrs);
60 | init();
61 | setWillNotDraw(false);
62 | paint = new Paint();
63 | paint.setStyle(Paint.Style.STROKE);
64 | paint.setStrokeWidth(5);
65 | paint.setColor(Color.BLACK);
66 | paint.setAntiAlias(true);
67 | }
68 |
69 | private void init() {
70 | start = new PointF();
71 | end = new PointF();
72 | control1 = new PointF();
73 | control2 = new PointF();
74 |
75 | // 初始化图片资源集合
76 | heartList = new ArrayList<>();
77 | heartList.add(R.drawable.h1);
78 | heartList.add(R.drawable.h2);
79 | heartList.add(R.drawable.h3);
80 |
81 | // 初始化布局参数
82 | params = new LayoutParams(LayoutParams.WRAP_CONTENT,
83 | LayoutParams.WRAP_CONTENT);
84 | params.addRule(ALIGN_PARENT_BOTTOM);
85 | params.addRule(CENTER_HORIZONTAL);
86 |
87 | }
88 |
89 | /**
90 | * 添加心
91 | */
92 | public void addHeart(Context context) {
93 | ImageView heart = new ImageView(context);
94 | heart.setImageResource(heartList.get(random.nextInt(3)));
95 | addView(heart, params);
96 | riseHeart(heart);
97 | }
98 |
99 | /**
100 | * 添加上升动画
101 | *
102 | * 动画包括: 透明度由1.0f-0f
103 | *
104 | * 沿着贝塞尔曲线移动
105 | */
106 | private void riseHeart(final ImageView imageView) {
107 |
108 | /* 前500ms让心形添加透明度动画,伸缩动画 */
109 | ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(imageView,
110 | "alpha", 0.3f, 1.0f);
111 | ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(imageView,
112 | "scaleX", 0.2f, 1.0f);
113 | ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(imageView,
114 | "scaleY", 0.2f, 1.0f);
115 | AnimatorSet mAnimatorSet = new AnimatorSet();
116 | mAnimatorSet.setDuration(500);
117 | mAnimatorSet
118 | .playTogether(alphaAnimator, scaleXAnimator, scaleYAnimator);
119 | mAnimatorSet.setTarget(imageView);
120 |
121 | BezierEvalutor evalutor = new BezierEvalutor(control1, control2);
122 | ValueAnimator valueAnimator = ValueAnimator.ofObject(evalutor, start,
123 | end);
124 | valueAnimator
125 | .addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
126 | @Override
127 | public void onAnimationUpdate(ValueAnimator animation) {
128 | // 获取从估值器中计算后的坐标
129 | PointF pointF = (PointF) animation.getAnimatedValue();
130 | imageView.setX(pointF.x);
131 | imageView.setY(pointF.y);
132 | // 设置图片的透明度,让图片由1渐变到0透明度,getFraction()相当于动画的进度
133 | imageView.setAlpha(1 - animation.getAnimatedFraction());
134 | }
135 | });
136 | valueAnimator.setTarget(imageView);
137 | valueAnimator.setDuration(3000);
138 | valueAnimator.start();
139 |
140 | AnimatorSet allAnimationSet = new AnimatorSet();
141 | // 先后执行两个动画
142 | allAnimationSet.setTarget(imageView);
143 | allAnimationSet.playSequentially(mAnimatorSet, valueAnimator);
144 | allAnimationSet.start();
145 | }
146 |
147 | @Override
148 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
149 | super.onSizeChanged(w, h, oldw, oldh);
150 |
151 | mWidth = getMeasuredWidth();
152 | mHeight = getMeasuredHeight();
153 |
154 | // 初始化各个点
155 | start.x = mWidth / 2;
156 | start.y = mHeight;
157 | end.x = mWidth / 2;
158 | end.y = 0;
159 | Log.d("tag", "onMeasure()=" + start.x + "--" + start.y);
160 | Log.d("tag", "onMeasure()=" + end.x + "--" + end.y);
161 |
162 | control1.x = random.nextInt(mWidth / 2);
163 | control1.y = random.nextInt(mHeight / 2) + mHeight / 2;
164 |
165 | control2.x = random.nextInt(mWidth / 2) + mWidth / 2;
166 | control2.y = random.nextInt(mHeight / 2);
167 | }
168 |
169 | /**
170 | * 自定义一个估值器实现起始点到终止点的过程中坐标的变化
171 | */
172 | public class BezierEvalutor implements TypeEvaluator {
173 |
174 | PointF control1Point;
175 | PointF control2Point;
176 |
177 | public BezierEvalutor(PointF control1Point, PointF control2Point) {
178 | super();
179 | this.control1Point = control1Point;
180 | this.control2Point = control2Point;
181 | }
182 |
183 | @Override
184 | public PointF evaluate(float t, PointF start, PointF end) {
185 | // 时间因子t: 0~1
186 | PointF point = new PointF();
187 | // 实现贝塞尔公式:
188 | point.x = start.x * (1 - t) * (1 - t) * (1 - t) + 3
189 | * control1Point.x * t * (1 - t) * (1 - t) + 3
190 | * control2Point.x * (1 - t) * t * t + end.x * t * t * t;// 实时计算最新的点X坐标
191 | point.y = start.y * (1 - t) * (1 - t) * (1 - t) + 3
192 | * control1Point.y * t * (1 - t) * (1 - t) + 3
193 | * control2Point.y * (1 - t) * t * t + end.y * t * t * t;// 实时计算最新的点Y坐标
194 | return point;// 实时返回最新计算出的点对象
195 | }
196 |
197 | }
198 |
199 | }
200 |
--------------------------------------------------------------------------------
/Bezier/src/main/java/com/chan/bezier/bezier_views/BezierView_ElasticBall.java:
--------------------------------------------------------------------------------
1 | package com.chan.bezier.bezier_views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Path;
7 | import android.graphics.PointF;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 | import android.view.animation.AccelerateDecelerateInterpolator;
11 | import android.view.animation.Animation;
12 | import android.view.animation.Transformation;
13 |
14 | public class BezierView_ElasticBall extends View {
15 |
16 | private Path mPath;
17 | private Paint mFillCirclePaint;
18 |
19 | private int width;
20 | private int height;
21 | private int centerX;
22 | private int centerY;
23 |
24 | private float maxLength;
25 | private float mInterpolatedTime;
26 | private float stretchDistance;
27 | private float moveDistance;
28 | private float cDistance;
29 | private float radius;
30 | private float c;
31 | private float blackMagic = 0.551915024494f;
32 | private VPoint p2,p4;
33 | private HPoint p1,p3;
34 |
35 |
36 | public BezierView_ElasticBall(Context context) {
37 | this(context, null, 0);
38 | }
39 |
40 | public BezierView_ElasticBall(Context context, AttributeSet attrs) {
41 | this(context, attrs, 0);
42 | }
43 |
44 | public BezierView_ElasticBall(Context context, AttributeSet attrs, int defStyleAttr) {
45 | super(context, attrs, defStyleAttr);
46 | init();
47 | }
48 |
49 | private void init() {
50 | mFillCirclePaint = new Paint();
51 | mFillCirclePaint.setColor(0xFFfe626d);
52 | mFillCirclePaint.setStyle(Paint.Style.FILL);
53 | mFillCirclePaint.setStrokeWidth(1);
54 | mFillCirclePaint.setAntiAlias(true);
55 | mPath = new Path();
56 | p2 = new VPoint();
57 | p4 = new VPoint();
58 |
59 | p1 = new HPoint();
60 | p3 = new HPoint();
61 | }
62 |
63 | @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
64 | super.onLayout(changed, left, top, right, bottom);
65 | width = getWidth();
66 | height = getHeight();
67 | centerX = width / 2;
68 | centerY = height / 2;
69 | radius = 50;
70 | c = radius*blackMagic;
71 | stretchDistance = radius;
72 | moveDistance = radius*(3/5f);
73 | cDistance = c*0.45f;
74 | maxLength = width - radius -radius;
75 | }
76 |
77 | @Override protected void onDraw(Canvas canvas) {
78 | super.onDraw(canvas);
79 | mPath.reset();
80 | canvas.translate(radius, radius);
81 |
82 | if(mInterpolatedTime>=0&&mInterpolatedTime<=0.2){
83 | model1(mInterpolatedTime);
84 | }else if(mInterpolatedTime>0.2&&mInterpolatedTime<=0.5){
85 | model2(mInterpolatedTime);
86 | }else if(mInterpolatedTime>0.5&&mInterpolatedTime<=0.8){
87 | model3(mInterpolatedTime);
88 | }else if(mInterpolatedTime>0.8&&mInterpolatedTime<=0.9){
89 | model4(mInterpolatedTime);
90 | }else if(mInterpolatedTime>0.9&&mInterpolatedTime<=1){
91 | model5(mInterpolatedTime);
92 | }
93 |
94 | float offset = maxLength*(mInterpolatedTime-0.2f);
95 | offset = offset>0?offset:0;
96 | p1.adjustAllX(offset);
97 | p2.adjustAllX(offset);
98 | p3.adjustAllX(offset);
99 | p4.adjustAllX(offset);
100 |
101 | mPath.moveTo(p1.x,p1.y);
102 | mPath.cubicTo(p1.right.x, p1.right.y, p2.bottom.x, p2.bottom.y, p2.x,p2.y);
103 | mPath.cubicTo(p2.top.x, p2.top.y, p3.right.x, p3.right.y, p3.x,p3.y);
104 | mPath.cubicTo(p3.left.x, p3.left.y, p4.top.x, p4.top.y, p4.x,p4.y);
105 | mPath.cubicTo(p4.bottom.x,p4.bottom.y,p1.left.x,p1.left.y,p1.x,p1.y);
106 |
107 | canvas.drawPath(mPath,mFillCirclePaint);
108 |
109 | }
110 |
111 | private void model0(){
112 | p1.setY(radius);
113 | p3.setY(-radius);
114 | p3.x = p1.x = 0;
115 | p3.left.x = p1.left.x = -c;
116 | p3.right.x = p1.right.x = c;
117 |
118 | p2.setX(radius);
119 | p4.setX(-radius);
120 | p2.y = p4.y = 0;
121 | p2.top.y = p4.top.y = -c;
122 | p2.bottom.y = p4.bottom.y = c;
123 | }
124 |
125 | private void model1(float time){//0~0.2
126 | model0();
127 |
128 | p2.setX(radius+stretchDistance*time*5);
129 | }
130 |
131 | private void model2(float time){//0.2~0.5
132 | model1(0.2f);
133 | time = (time - 0.2f) * (10f / 3);
134 | p1.adjustAllX(stretchDistance/2 * time );
135 | p3.adjustAllX(stretchDistance/2 * time );
136 | p2.adjustY(cDistance * time);
137 | p4.adjustY(cDistance * time);
138 | }
139 |
140 | private void model3(float time){//0.5~0.8
141 | model2(0.5f);
142 | time = (time - 0.5f) * (10f / 3);
143 | p1.adjustAllX(stretchDistance / 2 * time);
144 | p3.adjustAllX(stretchDistance / 2 * time);
145 | p2.adjustY(-cDistance * time);
146 | p4.adjustY(-cDistance * time);
147 |
148 | p4.adjustAllX(stretchDistance / 2 * time);
149 |
150 | }
151 |
152 | private void model4(float time){//0.8~0.9
153 | model3(0.8f);
154 | time = (time - 0.8f) * 10;
155 | p4.adjustAllX(stretchDistance / 2 * time);
156 | }
157 |
158 | private void model5(float time){
159 | model4(0.9f);
160 | time = time - 0.9f;
161 | p4.adjustAllX((float) (Math.sin(Math.PI*time*10f)*(2/10f*radius)));
162 | }
163 |
164 | class VPoint{
165 | public float x;
166 | public float y;
167 | public PointF top = new PointF();
168 | public PointF bottom = new PointF();
169 |
170 | public void setX(float x){
171 | this.x = x;
172 | top.x = x;
173 | bottom.x = x;
174 | }
175 |
176 | public void adjustY(float offset){
177 | top.y -= offset;
178 | bottom.y += offset;
179 | }
180 |
181 | public void adjustAllX(float offset){
182 | this.x+= offset;
183 | top.x+= offset;
184 | bottom.x+=offset;
185 | }
186 | }
187 |
188 | class HPoint{
189 | public float x;
190 | public float y;
191 | public PointF left = new PointF();
192 | public PointF right = new PointF();
193 |
194 | public void setY(float y){
195 | this.y = y;
196 | left.y = y;
197 | right.y = y;
198 | }
199 |
200 | public void adjustAllX(float offset){
201 | this.x +=offset;
202 | left.x +=offset;
203 | right.x +=offset;
204 | }
205 | }
206 |
207 | private class MoveAnimation extends Animation {
208 |
209 | @Override
210 | protected void applyTransformation(float interpolatedTime, Transformation t) {
211 | super.applyTransformation(interpolatedTime, t);
212 | mInterpolatedTime = interpolatedTime;
213 | invalidate();
214 | }
215 | }
216 |
217 | public void startAnimation() {
218 | mPath.reset();
219 | mInterpolatedTime = 0;
220 | MoveAnimation move = new MoveAnimation();
221 | move.setDuration(1000);
222 | move.setInterpolator(new AccelerateDecelerateInterpolator());
223 | startAnimation(move);
224 | }
225 | }
--------------------------------------------------------------------------------