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