贝塞尔曲线

时间:2020-10-15 07:59:25
【文件属性】:

文件名称:贝塞尔曲线

文件大小:26.29MB

文件格式:RAR

更新时间:2020-10-15 07:59:25

贝塞尔曲线

从2阶到7阶的贝赛尔曲线 private static final int MAX_COUNT = 7; // 贝塞尔曲线最大阶数 private static final int REGION_WIDTH = 30; // 合法区域宽度 private static final int FINGER_RECT_SIZE = 60; // 矩形尺寸 private static final int BEZIER_WIDTH = 10; // 贝塞尔曲线线宽 private static final int TANGENT_WIDTH = 6; // 切线线宽 private static final int CONTROL_WIDTH = 12; // 控制点连线线宽 private static final int CONTROL_RADIUS = 12; // 控制点半径 private static final int TEXT_SIZE = 40; // 文字画笔尺寸 private static final int TEXT_HEIGHT = 60; // 文本高度 private static final int RATE = 10; // 移动速率 private static final int HANDLER_WHAT = 100; private static final int FRAME = 1000; // 1000帧 private static final String[] TANGENT_COLORS = {"#7fff00", "#7a67ee", "#ee82ee", "#ffd700", "#1c86ee", "#8b8b00"}; // 切线颜色 private static final int STATE_READY = 0x0001; private static final int STATE_RUNNING = 0x0002; private static final int STATE_STOP = 0x0004; private static final int STATE_TOUCH = 0x0010; private Path mBezierPath = null; // 贝塞尔曲线路径 private Paint mBezierPaint = null; // 贝塞尔曲线画笔 private Paint mMovingPaint = null; // 移动点画笔 private Paint mControlPaint = null; // 控制点画笔 private Paint mTangentPaint = null; // 切线画笔 private Paint mLinePaint = null; // 固定线画笔 private Paint mTextPointPaint = null; // 点画笔 private Paint mTextPaint = null; // 文字画笔 private ArrayList mBezierPoints = null; // 贝塞尔曲线点集 private PointF mBezierPoint = null; // 贝塞尔曲线移动点 private ArrayList mControlPoints = null; // 控制点集 private ArrayList>> mTangentPoints; // 切线点集 private ArrayList> mInstantTangentPoints; private int mR = 0; // 移动速率 private int mRate = RATE; // 速率 private int mState; // 状态 private boolean mLoop = false; // 设置是否循环 private boolean mTangent = true; // 设置是否显示切线 private int mWidth = 0, mHeight = 0; // 画布宽高 private PointF mCurPoint; // 当前移动的控制点 private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == HANDLER_WHAT) { mR += mRate; if (mR >= mBezierPoints.size()) { removeMessages(HANDLER_WHAT); mR = 0; mState &= ~STATE_RUNNING; mState &= ~STATE_STOP; mState |= STATE_READY | STATE_TOUCH; if (mLoop) { start(); } return; } if (mR != mBezierPoints.size() - 1 && mR + mRate >= mBezierPoints.size()) { mR = mBezierPoints.size() - 1; } // Bezier点 mBezierPoint = new PointF(mBezierPoints.get(mR).x, mBezierPoints.get(mR).y); // 切线点 if (mTangent) { int size = mTangentPoints.size(); ArrayList instantpoints; mInstantTangentPoints = new ArrayList<>(); for (int i = 0; i < size; i++) { int len = mTangentPoints.get(i).size(); instantpoints = new ArrayList<>(); for (int j = 0; j < len; j++) { float x = mTangentPoints.get(i).get(j).get(mR).x; float y = mTangentPoints.get(i).get(j).get(mR).y; instantpoints.add(new PointF(x, y)); } mInstantTangentPoints.add(instantpoints); } } if (mR == mBezierPoints.size() - 1) { mState |= STATE_STOP; } invalidate(); } } };


网友评论