Lomiri
Loading...
Searching...
No Matches
BezierCurve.qml
1/*
2 * Copyright (C) 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.12
18import Lomiri.Components 1.3
19import QtQuick.Window 2.2
20import 'cubic-bezier.js' as Bezier
21import 'KeySpline.js' as KeySpline
22
23Item {
24 id: root
25
26 property var controlPoint1: {'x':0, 'y':0}
27 property var controlPoint2: {'x':0, 'y':0}
28 property var controlPoint3: {'x':0.58, 'y':1}
29 property var controlPoint4: {'x':1, 'y':1}
30
31 function getValues(t) {
32 if (t<0) t=0
33 else if (t>1)t=1
34
35 return Bezier.getBezier(t, controlPoint1, controlPoint2, controlPoint3, controlPoint4)
36 }
37
38 function getYFromX(x) {
39 var spline = new KeySpline.keySpline(controlPoint2.x, controlPoint2.y, controlPoint3.x, controlPoint3.y)
40 if (x<0) x=0
41 else if (x>1)x=1
42
43 return spline.get(x)
44 }
45}