equal
deleted
inserted
replaced
|
1 import Qt 4.7 |
|
2 |
|
3 Rectangle { |
|
4 color: "#ffffff" |
|
5 width: 320; height: 240 |
|
6 Rectangle { |
|
7 id: rect |
|
8 color: "#00ff00" |
|
9 y: 200; width: 60; height: 20 |
|
10 SequentialAnimation on y { |
|
11 loops: Animation.Infinite |
|
12 NumberAnimation { |
|
13 to: 20; duration: 500 |
|
14 easing.type: "InOutQuad" |
|
15 } |
|
16 NumberAnimation { |
|
17 to: 200; duration: 2000 |
|
18 easing.type: "OutBounce" |
|
19 } |
|
20 PauseAnimation { duration: 1000 } |
|
21 } |
|
22 } |
|
23 |
|
24 // Velocity |
|
25 Rectangle { |
|
26 color: "#ff0000" |
|
27 x: rect.width; width: rect.width; height: 20 |
|
28 y: 200 |
|
29 SpringFollow on y { to: rect.y; velocity: 200 } |
|
30 } |
|
31 |
|
32 // Spring |
|
33 Rectangle { |
|
34 color: "#ff0000" |
|
35 x: rect.width * 2; width: rect.width/2; height: 20 |
|
36 y: 200 |
|
37 SpringFollow on y { to: rect.y; spring: 1.0; damping: 0.2 } |
|
38 } |
|
39 Rectangle { |
|
40 color: "#880000" |
|
41 x: rect.width * 2.5; width: rect.width/2; height: 20 |
|
42 y: 200 |
|
43 SpringFollow on y { to: rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object |
|
44 } |
|
45 |
|
46 // Follow mouse |
|
47 MouseArea { |
|
48 id: mouseRegion |
|
49 anchors.fill: parent |
|
50 Rectangle { |
|
51 id: ball |
|
52 width: 20; height: 20 |
|
53 radius: 10 |
|
54 color: "#0000ff" |
|
55 SpringFollow on x { id: f1; to: mouseRegion.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } |
|
56 SpringFollow on y { id: f2; to: mouseRegion.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } |
|
57 states: [ |
|
58 State { |
|
59 name: "following" |
|
60 when: !f1.inSync || !f2.inSync |
|
61 PropertyChanges { target: ball; color: "#ff0000" } |
|
62 } |
|
63 ] |
|
64 transitions: [ |
|
65 Transition { |
|
66 ColorAnimation { duration: 200 } |
|
67 } |
|
68 ] |
|
69 } |
|
70 } |
|
71 } |