16a553faebc444d20598bd909fe54aa6757b25f5
[profile/ivi/qtdeclarative.git] / examples / particles / affectors / content / attractor.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 2.0
42 import QtQuick.Particles 2.0
43
44 Rectangle {
45     id: root
46     width: 360
47     height: 540
48     color: "black"
49     Image {
50         source: "../../images/finalfrontier.png"
51         anchors.centerIn:parent
52     }
53     Emitter {
54         group: "stars"
55         system: particles
56         emitRate: 40
57         lifeSpan: 4000
58         enabled: true
59         size: 30
60         sizeVariation: 10
61         speed: PointDirection { x: 220; xVariation: 40 }
62         height: parent.height
63     }
64     Emitter {
65         group: "roids"
66         system: particles
67         emitRate: 10
68         lifeSpan: 4000
69         enabled: true
70         size: 30
71         sizeVariation: 10
72         speed: PointDirection { x: 220; xVariation: 40 }
73         height: parent.height
74     }
75     ParticleSystem {
76         id: particles
77         anchors.fill: parent
78     }
79     ImageParticle {
80         id: stars
81         groups: ["stars"]
82         system: particles
83         source: "../../images/star.png"
84         color: "white"
85         colorVariation: 0.1
86         alpha: 0
87     }
88     ImageParticle {
89         id: roids
90         groups: ["roids"]
91         system: particles
92         sprites: Sprite {
93             id: spinState
94             name: "spinning"
95             source: "../../images/meteor.png"
96             frameCount: 35
97             frameDuration: 60
98         }
99     }
100     ImageParticle {
101         id: shot
102         groups: ["shot"]
103         system: particles
104         source: "../../images/star.png"
105
106         color: "#0FF06600"
107         colorVariation: 0.3
108     }
109     ImageParticle {
110         id: engine
111         groups: ["engine"]
112         system: particles
113         source: "../../images/particle4.png"
114
115         color: "orange"
116         SequentialAnimation on color {
117             loops: Animation.Infinite
118             ColorAnimation {
119                 from: "red"
120                 to: "cyan"
121                 duration: 1000
122             }
123             ColorAnimation {
124                 from: "cyan"
125                 to: "red"
126                 duration: 1000
127             }
128         }
129
130         colorVariation: 0.2
131     }
132     //! [0]
133     Attractor {
134         id: gs; pointX: root.width/2; pointY: root.height/2; strength: 4000000;
135         system: particles
136         affectedParameter: Attractor.Acceleration
137         proportionalToDistance: Attractor.InverseQuadratic
138     }
139     //! [0]
140     Age {
141         system: particles
142         x: gs.pointX - 8;
143         y: gs.pointY - 8;
144         width: 16
145         height: 16
146     }
147     Rectangle {
148         color: "black"
149         width: 8
150         height: 8
151         radius: 4
152         x: gs.pointX - 4
153         y: gs.pointY - 4
154     }
155
156     Image {
157         source:"../../images/rocket2.png"
158         id: ship
159         width: 45
160         height: 22
161         //Automatic movement
162         SequentialAnimation on x {
163             loops: -1
164             NumberAnimation{to: root.width-45; easing.type: Easing.InOutQuad; duration: 2000}
165             NumberAnimation{to: 0; easing.type: Easing.OutInQuad; duration: 6000}
166         }
167         SequentialAnimation on y {
168             loops: -1
169             NumberAnimation{to: root.height-22; easing.type: Easing.OutInQuad; duration: 6000}
170             NumberAnimation{to: 0; easing.type: Easing.InOutQuad; duration: 2000}
171         }
172     }
173     Emitter {
174         group: "engine"
175         system: particles
176         emitRate: 200
177         lifeSpan: 1000
178         size: 10
179         endSize: 4
180         sizeVariation: 4
181         speed: PointDirection { x: -128; xVariation: 32 }
182         height: ship.height
183         y: ship.y
184         x: ship.x
185         width: 20
186     }
187     Emitter {
188         group: "shot"
189         system: particles
190         emitRate: 32
191         lifeSpan: 1000
192         enabled: true
193         size: 40
194         speed: PointDirection { x: 256; }
195         x: ship.x + ship.width
196         y: ship.y + ship.height/2
197     }
198 }
199