Particle example restyling
[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     ParticleSystem {
54         id: particles
55         anchors.fill: parent
56
57         Emitter {
58             group: "stars"
59             emitRate: 40
60             lifeSpan: 4000
61             enabled: true
62             size: 30
63             sizeVariation: 10
64             velocity: PointDirection { x: 220; xVariation: 40 }
65             height: parent.height
66         }
67         Emitter {
68             group: "roids"
69             emitRate: 10
70             lifeSpan: 4000
71             enabled: true
72             size: 30
73             sizeVariation: 10
74             velocity: PointDirection { x: 220; xVariation: 40 }
75             height: parent.height
76         }
77         ImageParticle {
78             id: stars
79             groups: ["stars"]
80             source: "../../images/star.png"
81             color: "white"
82             colorVariation: 0.1
83             alpha: 0
84         }
85         ImageParticle {
86             id: roids
87             groups: ["roids"]
88             sprites: Sprite {
89                 id: spinState
90                 name: "spinning"
91                 source: "../../images/meteor.png"
92                 frameCount: 35
93                 frameDuration: 60
94             }
95         }
96         ImageParticle {
97             id: shot
98             groups: ["shot"]
99             source: "../../images/star.png"
100
101             color: "#0FF06600"
102             colorVariation: 0.3
103         }
104         ImageParticle {
105             id: engine
106             groups: ["engine"]
107             source: "../../images/particle4.png"
108
109             color: "orange"
110             SequentialAnimation on color {
111                 loops: Animation.Infinite
112                 ColorAnimation {
113                     from: "red"
114                     to: "cyan"
115                     duration: 1000
116                 }
117                 ColorAnimation {
118                     from: "cyan"
119                     to: "red"
120                     duration: 1000
121                 }
122             }
123
124             colorVariation: 0.2
125         }
126         //! [0]
127         Attractor {
128             id: gs; pointX: root.width/2; pointY: root.height/2; strength: 4000000;
129             affectedParameter: Attractor.Acceleration
130             proportionalToDistance: Attractor.InverseQuadratic
131         }
132         //! [0]
133         Age {
134             x: gs.pointX - 8;
135             y: gs.pointY - 8;
136             width: 16
137             height: 16
138         }
139         Rectangle {
140             color: "black"
141             width: 8
142             height: 8
143             radius: 4
144             x: gs.pointX - 4
145             y: gs.pointY - 4
146         }
147
148         Image {
149             source:"../../images/rocket2.png"
150             id: ship
151             width: 45
152             height: 22
153             //Automatic movement
154             SequentialAnimation on x {
155                 loops: -1
156                 NumberAnimation{to: root.width-45; easing.type: Easing.InOutQuad; duration: 2000}
157                 NumberAnimation{to: 0; easing.type: Easing.OutInQuad; duration: 6000}
158             }
159             SequentialAnimation on y {
160                 loops: -1
161                 NumberAnimation{to: root.height-22; easing.type: Easing.OutInQuad; duration: 6000}
162                 NumberAnimation{to: 0; easing.type: Easing.InOutQuad; duration: 2000}
163             }
164         }
165         Emitter {
166             group: "engine"
167             emitRate: 200
168             lifeSpan: 1000
169             size: 10
170             endSize: 4
171             sizeVariation: 4
172             velocity: PointDirection { x: -128; xVariation: 32 }
173             height: ship.height
174             y: ship.y
175             x: ship.x
176             width: 20
177         }
178         Emitter {
179             group: "shot"
180             emitRate: 32
181             lifeSpan: 1000
182             enabled: true
183             size: 40
184             velocity: PointDirection { x: 256; }
185             x: ship.x + ship.width
186             y: ship.y + ship.height/2
187         }
188     }
189 }
190