From 8be9f08b8d1db93d5d7e17a4348a7d3cb2fe6c95 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 6 Jun 2012 20:28:17 +1000 Subject: Update Affector folder of examples to guidelines Change-Id: I1fa0e8424f94cf954098b7734ba25feab0790828 Reviewed-by: Bea Lam --- examples/particles/affectors/affectors.pro | 10 + examples/particles/affectors/affectors.qml | 149 ++++++++++++++ examples/particles/affectors/affectors.qmlproject | 16 ++ examples/particles/affectors/age.qml | 97 ---------- examples/particles/affectors/attractor.qml | 213 -------------------- examples/particles/affectors/content/age.qml | 99 ++++++++++ examples/particles/affectors/content/attractor.qml | 199 +++++++++++++++++++ .../particles/affectors/content/customaffector.qml | 176 +++++++++++++++++ examples/particles/affectors/content/friction.qml | 112 +++++++++++ examples/particles/affectors/content/gravity.qml | 105 ++++++++++ examples/particles/affectors/content/groupgoal.qml | 203 +++++++++++++++++++ examples/particles/affectors/content/move.qml | 147 ++++++++++++++ .../particles/affectors/content/spritegoal.qml | 214 +++++++++++++++++++++ .../particles/affectors/content/turbulence.qml | 138 +++++++++++++ examples/particles/affectors/content/wander.qml | 97 ++++++++++ examples/particles/affectors/customaffector.qml | 173 ----------------- examples/particles/affectors/friction.qml | 109 ----------- examples/particles/affectors/gravity.qml | 103 ---------- examples/particles/affectors/groupgoal.qml | 193 ------------------- examples/particles/affectors/main.cpp | 41 ++++ examples/particles/affectors/move.qml | 141 -------------- examples/particles/affectors/spritegoal.qml | 212 -------------------- examples/particles/affectors/turbulence.qml | 135 ------------- examples/particles/affectors/wander.qml | 95 --------- 24 files changed, 1706 insertions(+), 1471 deletions(-) create mode 100644 examples/particles/affectors/affectors.pro create mode 100644 examples/particles/affectors/affectors.qml create mode 100644 examples/particles/affectors/affectors.qmlproject delete mode 100644 examples/particles/affectors/age.qml delete mode 100644 examples/particles/affectors/attractor.qml create mode 100644 examples/particles/affectors/content/age.qml create mode 100644 examples/particles/affectors/content/attractor.qml create mode 100644 examples/particles/affectors/content/customaffector.qml create mode 100644 examples/particles/affectors/content/friction.qml create mode 100644 examples/particles/affectors/content/gravity.qml create mode 100644 examples/particles/affectors/content/groupgoal.qml create mode 100644 examples/particles/affectors/content/move.qml create mode 100644 examples/particles/affectors/content/spritegoal.qml create mode 100644 examples/particles/affectors/content/turbulence.qml create mode 100644 examples/particles/affectors/content/wander.qml delete mode 100644 examples/particles/affectors/customaffector.qml delete mode 100644 examples/particles/affectors/friction.qml delete mode 100644 examples/particles/affectors/gravity.qml delete mode 100644 examples/particles/affectors/groupgoal.qml create mode 100644 examples/particles/affectors/main.cpp delete mode 100644 examples/particles/affectors/move.qml delete mode 100644 examples/particles/affectors/spritegoal.qml delete mode 100644 examples/particles/affectors/turbulence.qml delete mode 100644 examples/particles/affectors/wander.qml (limited to 'examples/particles') diff --git a/examples/particles/affectors/affectors.pro b/examples/particles/affectors/affectors.pro new file mode 100644 index 0000000000..52eb0ddb55 --- /dev/null +++ b/examples/particles/affectors/affectors.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/particles/affectors +qml.files = affectors.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/particles/affectors +INSTALLS += target qml + diff --git a/examples/particles/affectors/affectors.qml b/examples/particles/affectors/affectors.qml new file mode 100644 index 0000000000..08f1dfe1a0 --- /dev/null +++ b/examples/particles/affectors/affectors.qml @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "../../shared" as Examples + +/*! + \title QtQuick.Particles Examples - Affectors + \example particles/affectors + \brief This is a collection of examples using Affectors in the QML particle system. + \image qml-affectors-example.png + + This is a collection of small QML examples relating to using Affectors in the particle system. + Each example is a small QML file emphasizing a particular element or feature. + + Age demonstrates using an Age affector to prematurely end the lives of particles. + \snippet examples/particles/affectors/content/age.qml 0 + + As you move the affector around the screen, the particles inside it + (which haven't already been affected) jump to a period near the end + of their life. This gives them a short period to finish fading out, + but changing lifeLeft to 0 (the default), would cause them to reach + the end of their life instantly. + + Attractor demonstrates using an Attractor affector to simulate a black hole + \snippet examples/particles/affectors/content/attractor.qml 0 + + All particles in the scene, including the rocket ship's exhaust and pellets, are pulled + towards the black hole. This effect is stronger closer to the black hole, so the + asteroids near the top of the screen are barely affected at all, while the ones + towards the middle sometimes curve drastically. To complete the effect, an Age + affector covers the black hole to destroy particles which come in contact with it. + + Custom Affector manipulates the properties of the particles directly in javascript. + One Affector is used to make the leaves rock back and forth as they fall, looking more + leaf-like than just spinning in circles: + \snippet examples/particles/affectors/content/customaffector.qml 0 + Another is used to provide a slightly varying friction to the leaves as they 'land', + to look more natural: + \snippet examples/particles/affectors/content/customaffector.qml 1 + + Friction is similar to the falling leaves in the custom affector, except that it uses a + flat friction the whole way down instead of custom affectors. + \snippet examples/particles/affectors/content/friction.qml 0 + + Gravity is a convenience affector for applying a constant acceleration to particles inside it + \snippet examples/particles/affectors/content/gravity.qml 0 + + GroupGoal sets up two particle groups for flaming and non-flaming balls, and gives you various + ways to transition between them. + \snippet examples/particles/affectors/content/groupgoal.qml unlit + The non-flaming balls have a one in a hundred chance of lighting on their own each second, but they also + have a GroupGoal set on the whole group. This affector affects all particles of the unlit group, when colliding + with particles in the lit group, and cause them to move to the lighting group. + \snippet examples/particles/affectors/content/groupgoal.qml lighting + lighting is an intermediate group so that the glow builds up and the transition is less jarring. So it automatically + moves into the lit group after 100ms. + \snippet examples/particles/affectors/content/groupgoal.qml lit + The lit group also has TrailEmitters on it for additional fire and smoke, but does not transition anywhere. + There are two more GroupGoal elements that allow particles in the unlit group to transition to the lighting group + (and then to the lit group). + \snippet examples/particles/affectors/content/groupgoal.qml groupgoal-pilot + The first is just an area bound to the location of an image of a pilot flame. When unlit balls pass through the flame, + they go straight to lit because the pilot flame is so hot. + \snippet examples/particles/affectors/content/groupgoal.qml groupgoal-ma + The second is bound to the location of the last pointer interaction, so that touching or clicking on unlit balls (which + is hard due to their constant movement) causes them to move to the lighting group. + + Move shows some simple effects you can get by altering trajectory midway. + The red particles have an affector that affects their position, jumping them forwards by 120px. + \snippet examples/particles/affectors/content/move.qml A + The green particles have an affector that affects their velocity, but with some angle variation. By adding some random direction + velocity to their existing forwards velocity, they begin to spray off in a cone. + \snippet examples/particles/affectors/content/move.qml B + The blue particles have an affector that affects their acceleration, and because it sets relative to false this resets the acceleration instead of + adding to it. Once the blue particles reach the affector, their horizontal velocity stops increasing as their vertical velocity decreases. + \snippet examples/particles/affectors/content/move.qml C + + SpriteGoal has an affector which interacts with the sprite engine of particles, if they are being drawn as sprites by ImageParticle. + \snippet examples/particles/affectors/content/spritegoal.qml 0 + The SpriteGoal follows the image of the rocket ship on screen, and when it interacts with particles drawn by ImageParticle as sprites, + it instructs them to move immediately to the "explode" state, which in this case is the animation of the asteroid breaking into many pieces. + + Turbulence has a flame with smoke, and both sets of particles being affected by a Turbulence affector. This gives a faint wind effect. + \snippet examples/particles/affectors/content/turbulence.qml 0 + To make the wind change direction, subsitute a black and white noise image in the noiseSource parameter (it currently uses a default noise source). + + Wander uses a Wander affector to add some horizontal drift to snowflakes as they fall down. + \snippet examples/particles/affectors/content/wander.qml 0 + There are different movements given by applying the Wander to different attributes of the trajectory, so the example makes it easy to play around and see the difference. +*/ + +Item { + height: 480 + width: 320 + Examples.LauncherList { + id: ll + anchors.fill: parent + Component.onCompleted: { + addExample("Age", "Kills off particles that enter the affector", Qt.resolvedUrl("content/age.qml")); + addExample("Attractor", "Simulates a small black hole", Qt.resolvedUrl("content/attractor.qml")); + addExample("Custom Affector", "Custom falling leaves", Qt.resolvedUrl("content/customaffector.qml")); + addExample("Friction", "Leaves that slow down as they fall", Qt.resolvedUrl("content/friction.qml")); + addExample("Gravity", "Leaves that fall towards the earth as you move it", Qt.resolvedUrl("content/gravity.qml")); + addExample("GroupGoal", "Balls that can be set on fire various ways", Qt.resolvedUrl("content/groupgoal.qml")); + addExample("Move", "Some effects you can get by altering trajectory midway", Qt.resolvedUrl("content/move.qml")); + addExample("SpriteGoal", "A ship that makes asteroids explode", Qt.resolvedUrl("content/spritegoal.qml")); + addExample("Turbulence", "A candle with faint wind", Qt.resolvedUrl("content/turbulence.qml")); + addExample("Wander", "Drifting snow flakes", Qt.resolvedUrl("content/wander.qml")); + } + } +} diff --git a/examples/particles/affectors/affectors.qmlproject b/examples/particles/affectors/affectors.qmlproject new file mode 100644 index 0000000000..2bf3387155 --- /dev/null +++ b/examples/particles/affectors/affectors.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.1 + +Project { + mainFile: "affectors.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +} diff --git a/examples/particles/affectors/age.qml b/examples/particles/affectors/age.qml deleted file mode 100644 index ea1b30275e..0000000000 --- a/examples/particles/affectors/age.qml +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - id: root - width: 360 - height: 600 - color: "white" - - ParticleSystem { id: particles } - - ImageParticle { - system: particles - sprites: Sprite { - name: "snow" - source: "../images/snowflake.png" - frameCount: 51 - frameDuration: 40 - frameDurationVariation: 8 - } - } - - Emitter { - system: particles - emitRate: 20 - lifeSpan: 8000 - speed: PointDirection { y:80; yVariation: 40; } - acceleration: PointDirection { y: 4 } - size: 36 - endSize: 12 - sizeVariation: 8 - width: parent.width - height: 100 - } - - MouseArea { - id: ma - anchors.fill: parent - hoverEnabled: true - } - - Rectangle { - color: "#803333AA" - border.color: "black" - x: ma.mouseX - 36 - y: ma.mouseY - 36 - width: 72 - height: 72 - Age { - anchors.fill: parent - system: particles - once: true - lifeLeft: 1200 - advancePosition: false - } - } -} diff --git a/examples/particles/affectors/attractor.qml b/examples/particles/affectors/attractor.qml deleted file mode 100644 index 0d50937fe7..0000000000 --- a/examples/particles/affectors/attractor.qml +++ /dev/null @@ -1,213 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - id: root - width: 360 - height: 540 - color: "black" - property bool spacePressed: false - focus: true - Image { - source: "../images/finalfrontier.png" - anchors.centerIn:parent - } - Keys.onPressed: { - if (event.key == Qt.Key_Space) { - spacePressed = true; - event.accepted = true; - } - } - Keys.onReleased: { - if (event.key == Qt.Key_Space) { - spacePressed = false; - event.accepted = true; - } - } - - Emitter { - group: "stars" - system: particles - emitRate: 40 - lifeSpan: 4000 - enabled: true - size: 30 - sizeVariation: 10 - speed: PointDirection { x: 220; xVariation: 40 } - height: parent.height - } - Emitter { - group: "roids" - system: particles - emitRate: 10 - lifeSpan: 4000 - enabled: true - size: 30 - sizeVariation: 10 - speed: PointDirection { x: 220; xVariation: 40 } - height: parent.height - } - ParticleSystem { - id: particles - anchors.fill: parent - } - ImageParticle { - id: stars - groups: ["stars"] - system: particles - source: "../images/star.png" - color: "white" - colorVariation: 0.1 - alpha: 0 - } - ImageParticle { - id: roids - groups: ["roids"] - system: particles - sprites: Sprite { - id: spinState - name: "spinning" - source: "../images/meteor.png" - frameCount: 35 - frameDuration: 60 - } - } - ImageParticle { - id: shot - groups: ["shot"] - system: particles - source: "../images/star.png" - - color: "#0FF06600" - colorVariation: 0.3 - } - ImageParticle { - id: engine - groups: ["engine"] - system: particles - source: "../images/particle4.png" - - color: "orange" - SequentialAnimation on color { - loops: Animation.Infinite - ColorAnimation { - from: "red" - to: "cyan" - duration: 1000 - } - ColorAnimation { - from: "cyan" - to: "red" - duration: 1000 - } - } - - colorVariation: 0.2 - } - Attractor { - id: gs; pointX: root.width/2; pointY: root.height/2; strength: 4000000; - system: particles - affectedParameter: Attractor.Acceleration - proportionalToDistance: Attractor.InverseQuadratic - } - Age { - system: particles - x: gs.pointX - 8; - y: gs.pointY - 8; - width: 16 - height: 16 - } - Rectangle { - color: "black" - width: 8 - height: 8 - radius: 4 - x: gs.pointX - 4 - y: gs.pointY - 4 - } - - Image { - source:"../images/rocket2.png" - id: ship - width: 45 - height: 22 - MouseArea { - id: ma - anchors.fill: parent; - drag.axis: Drag.XandYAxis - drag.target: ship - } - } - Emitter { - group: "engine" - system: particles - emitRate: 200 - lifeSpan: 1000 - size: 10 - endSize: 4 - sizeVariation: 4 - speed: PointDirection { x: -128; xVariation: 32 } - height: ship.height - y: ship.y - x: ship.x - width: 20 - } - Emitter { - group: "shot" - system: particles - emitRate: 32 - lifeSpan: 2000 - enabled: spacePressed - size: 40 - speed: PointDirection { x: 256; } - x: ship.x + ship.width - y: ship.y + ship.height/2 - } - - Text { - color: "white" - anchors.bottom: parent.bottom - text:"Drag the ship, Spacebar to fire." - } -} - diff --git a/examples/particles/affectors/content/age.qml b/examples/particles/affectors/content/age.qml new file mode 100644 index 0000000000..ba52ce25ec --- /dev/null +++ b/examples/particles/affectors/content/age.qml @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + id: root + width: 360 + height: 600 + color: "white" + + ParticleSystem { id: particles } + + ImageParticle { + system: particles + sprites: Sprite { + name: "snow" + source: "../../images/snowflake.png" + frameCount: 51 + frameDuration: 40 + frameDurationVariation: 8 + } + } + + Emitter { + system: particles + emitRate: 20 + lifeSpan: 8000 + speed: PointDirection { y:80; yVariation: 40; } + acceleration: PointDirection { y: 4 } + size: 36 + endSize: 12 + sizeVariation: 8 + width: parent.width + height: 100 + } + + MouseArea { + id: ma + anchors.fill: parent + hoverEnabled: true + } + + Rectangle { + color: "#803333AA" + border.color: "black" + x: ma.mouseX - 36 + y: ma.mouseY - 36 + width: 72 + height: 72 + //! [0] + Age { + anchors.fill: parent + system: particles + once: true + lifeLeft: 1200 + advancePosition: false + } + //! [0] + } +} diff --git a/examples/particles/affectors/content/attractor.qml b/examples/particles/affectors/content/attractor.qml new file mode 100644 index 0000000000..16a553faeb --- /dev/null +++ b/examples/particles/affectors/content/attractor.qml @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + id: root + width: 360 + height: 540 + color: "black" + Image { + source: "../../images/finalfrontier.png" + anchors.centerIn:parent + } + Emitter { + group: "stars" + system: particles + emitRate: 40 + lifeSpan: 4000 + enabled: true + size: 30 + sizeVariation: 10 + speed: PointDirection { x: 220; xVariation: 40 } + height: parent.height + } + Emitter { + group: "roids" + system: particles + emitRate: 10 + lifeSpan: 4000 + enabled: true + size: 30 + sizeVariation: 10 + speed: PointDirection { x: 220; xVariation: 40 } + height: parent.height + } + ParticleSystem { + id: particles + anchors.fill: parent + } + ImageParticle { + id: stars + groups: ["stars"] + system: particles + source: "../../images/star.png" + color: "white" + colorVariation: 0.1 + alpha: 0 + } + ImageParticle { + id: roids + groups: ["roids"] + system: particles + sprites: Sprite { + id: spinState + name: "spinning" + source: "../../images/meteor.png" + frameCount: 35 + frameDuration: 60 + } + } + ImageParticle { + id: shot + groups: ["shot"] + system: particles + source: "../../images/star.png" + + color: "#0FF06600" + colorVariation: 0.3 + } + ImageParticle { + id: engine + groups: ["engine"] + system: particles + source: "../../images/particle4.png" + + color: "orange" + SequentialAnimation on color { + loops: Animation.Infinite + ColorAnimation { + from: "red" + to: "cyan" + duration: 1000 + } + ColorAnimation { + from: "cyan" + to: "red" + duration: 1000 + } + } + + colorVariation: 0.2 + } + //! [0] + Attractor { + id: gs; pointX: root.width/2; pointY: root.height/2; strength: 4000000; + system: particles + affectedParameter: Attractor.Acceleration + proportionalToDistance: Attractor.InverseQuadratic + } + //! [0] + Age { + system: particles + x: gs.pointX - 8; + y: gs.pointY - 8; + width: 16 + height: 16 + } + Rectangle { + color: "black" + width: 8 + height: 8 + radius: 4 + x: gs.pointX - 4 + y: gs.pointY - 4 + } + + Image { + source:"../../images/rocket2.png" + id: ship + width: 45 + height: 22 + //Automatic movement + SequentialAnimation on x { + loops: -1 + NumberAnimation{to: root.width-45; easing.type: Easing.InOutQuad; duration: 2000} + NumberAnimation{to: 0; easing.type: Easing.OutInQuad; duration: 6000} + } + SequentialAnimation on y { + loops: -1 + NumberAnimation{to: root.height-22; easing.type: Easing.OutInQuad; duration: 6000} + NumberAnimation{to: 0; easing.type: Easing.InOutQuad; duration: 2000} + } + } + Emitter { + group: "engine" + system: particles + emitRate: 200 + lifeSpan: 1000 + size: 10 + endSize: 4 + sizeVariation: 4 + speed: PointDirection { x: -128; xVariation: 32 } + height: ship.height + y: ship.y + x: ship.x + width: 20 + } + Emitter { + group: "shot" + system: particles + emitRate: 32 + lifeSpan: 1000 + enabled: true + size: 40 + speed: PointDirection { x: 256; } + x: ship.x + ship.width + y: ship.y + ship.height/2 + } +} + diff --git a/examples/particles/affectors/content/customaffector.qml b/examples/particles/affectors/content/customaffector.qml new file mode 100644 index 0000000000..2abb72dc16 --- /dev/null +++ b/examples/particles/affectors/content/customaffector.qml @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Item { + width: 360 + height: 600 + + Image { + source: "../../images/backgroundLeaves.jpg" + anchors.fill: parent + } + ParticleSystem { + id: sys + } + Emitter { + system: sys + width: parent.width + emitRate: 4 + lifeSpan: 14000 + size: 80 + speed: PointDirection { y: 60 } + } + Wander { + system: sys + anchors.fill: parent + anchors.bottomMargin: 100 + xVariance: 60 + pace: 60 + } + + //! [0] + Affector { + system: sys + property real coefficient: 0.1 + property real speed: 1.5 + width: parent.width + height: parent.height - 100 + onAffectParticles: { + /* //Linear movement + if (particle.r == 0) { + particle.r = Math.random() > 0.5 ? -1 : 1; + }else if (particle.r == 1) { + particle.rotation += speed * dt; + if(particle.rotation >= maxAngle) + particle.r = -1; + }else if (particle.r == -1) { + particle.rotation -= speed * dt; + if(particle.rotation <= -1 * maxAngle) + particle.r = 1; + } + */ + //Wobbly movement + for (var i=0; i 0.5 ? -1 : 1; - }else if (particle.r == 1) { - particle.rotation += speed * dt; - if(particle.rotation >= maxAngle) - particle.r = -1; - }else if (particle.r == -1) { - particle.rotation -= speed * dt; - if(particle.rotation <= -1 * maxAngle) - particle.r = 1; - } - */ - //Wobbly movement - for (var i=0; i