diff options
author | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2012-11-29 16:02:34 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-10 18:16:48 +0100 |
commit | a6065d60f158ffad7a94877883af69731da94295 (patch) | |
tree | 5657fd490fd8a3f9794a8c9bcc9f85cf24a095c1 /examples/quick/particles/affectors | |
parent | c18e04b2e61f174a4883f6884cf9a0712c5725e3 (diff) |
centralize and fixup example sources install targets
follow respective change in qtbase
Change-Id: I27502eb7ebea973e19ec5f7c3ec0e2338556f6e0
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Diffstat (limited to 'examples/quick/particles/affectors')
17 files changed, 1787 insertions, 0 deletions
diff --git a/examples/quick/particles/affectors/affectors.pro b/examples/quick/particles/affectors/affectors.pro new file mode 100644 index 0000000000..9d7c3de059 --- /dev/null +++ b/examples/quick/particles/affectors/affectors.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/affectors +qml.files = affectors.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/affectors +INSTALLS += target qml diff --git a/examples/quick/particles/affectors/affectors.qml b/examples/quick/particles/affectors/affectors.qml new file mode 100644 index 0000000000..f8e132c2c0 --- /dev/null +++ b/examples/quick/particles/affectors/affectors.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 + +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/quick/particles/affectors/affectors.qmlproject b/examples/quick/particles/affectors/affectors.qmlproject new file mode 100644 index 0000000000..2bf3387155 --- /dev/null +++ b/examples/quick/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/quick/particles/affectors/content/GreyButton.qml b/examples/quick/particles/affectors/content/GreyButton.qml new file mode 100644 index 0000000000..e3d3daa470 --- /dev/null +++ b/examples/quick/particles/affectors/content/GreyButton.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 + +Item { + id: container + + property string text: "Button" + property string subText: "" + signal clicked + + width: buttonLabel.width + 20; height: col.height + 12 + + MouseArea { + id: mouseArea; + anchors.fill: parent; + onClicked: container.clicked(); + onPressed: background.color = Qt.darker("lightgrey"); + onReleased: background.color="lightgrey"; + } + + Rectangle { + id: background + anchors.fill: parent + color: "lightgrey" + radius: 4 + border.width: 1 + border.color: Qt.darker(color) + } + + Column { + spacing: 2 + id: col + x: 10 + y: 6 + Text { + id: buttonLabel; text: container.text; color: "black"; font.pixelSize: 24 + } + Text { + id: buttonLabel2; text: container.subText; color: "black"; font.pixelSize: 12 + } + } +} diff --git a/examples/quick/particles/affectors/content/age.qml b/examples/quick/particles/affectors/content/age.qml new file mode 100644 index 0000000000..9b8d28dc7e --- /dev/null +++ b/examples/quick/particles/affectors/content/age.qml @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 + velocity: 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/quick/particles/affectors/content/attractor.qml b/examples/quick/particles/affectors/content/attractor.qml new file mode 100644 index 0000000000..5617f6eb86 --- /dev/null +++ b/examples/quick/particles/affectors/content/attractor.qml @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 + } + ParticleSystem { + id: particles + anchors.fill: parent + + Emitter { + group: "stars" + emitRate: 40 + lifeSpan: 4000 + enabled: true + size: 30 + sizeVariation: 10 + velocity: PointDirection { x: 220; xVariation: 40 } + height: parent.height + } + Emitter { + group: "roids" + emitRate: 10 + lifeSpan: 4000 + enabled: true + size: 30 + sizeVariation: 10 + velocity: PointDirection { x: 220; xVariation: 40 } + height: parent.height + } + ImageParticle { + id: stars + groups: ["stars"] + source: "../../images/star.png" + color: "white" + colorVariation: 0.1 + alpha: 0 + } + ImageParticle { + id: roids + groups: ["roids"] + sprites: Sprite { + id: spinState + name: "spinning" + source: "../../images/meteor.png" + frameCount: 35 + frameDuration: 60 + } + } + ImageParticle { + id: shot + groups: ["shot"] + source: "../../images/star.png" + + color: "#0FF06600" + colorVariation: 0.3 + } + ImageParticle { + id: engine + groups: ["engine"] + 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; + affectedParameter: Attractor.Acceleration + proportionalToDistance: Attractor.InverseQuadratic + } + //! [0] + Age { + 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" + emitRate: 200 + lifeSpan: 1000 + size: 10 + endSize: 4 + sizeVariation: 4 + velocity: PointDirection { x: -128; xVariation: 32 } + height: ship.height + y: ship.y + x: ship.x + width: 20 + } + Emitter { + group: "shot" + emitRate: 32 + lifeSpan: 1000 + enabled: true + size: 40 + velocity: PointDirection { x: 256; } + x: ship.x + ship.width + y: ship.y + ship.height/2 + } + } +} + diff --git a/examples/quick/particles/affectors/content/customaffector.qml b/examples/quick/particles/affectors/content/customaffector.qml new file mode 100644 index 0000000000..157bf6afc1 --- /dev/null +++ b/examples/quick/particles/affectors/content/customaffector.qml @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 { + anchors.fill: parent + Emitter { + width: parent.width + emitRate: 4 + lifeSpan: 14000 + size: 80 + velocity: PointDirection { y: 60 } + } + Wander { + anchors.fill: parent + anchors.bottomMargin: 100 + xVariance: 60 + pace: 60 + } + + //! [0] + Affector { + property real coefficient: 0.1 + property real velocity: 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 += velocity * dt; + if (particle.rotation >= maxAngle) + particle.r = -1; + } else if (particle.r == -1) { + particle.rotation -= velocity * dt; + if (particle.rotation <= -1 * maxAngle) + particle.r = 1; + } + */ + //Wobbly movement + for (var i=0; i<particles.length; i++) { + var particle = particles[i]; + if (particle.r == 0.0) { + particle.r = Math.random() + 0.01; + } + particle.rotation += velocity * particle.r * dt; + particle.r -= particle.rotation * coefficient; + if (particle.r == 0.0) + particle.r -= particle.rotation * 0.000001; + particle.update = 1; + } + } + } + //! [0] + + //! [1] + Affector {//Custom Friction, adds some 'randomness' + x: -60 + width: parent.width + 120 + height: 100 + anchors.bottom: parent.bottom + onAffectParticles: { + for (var i=0; i<particles.length; i++) { + var particle = particles[i]; + var pseudoRand = (Math.floor(particle.t*1327) % 10) + 1; + var yslow = dt * pseudoRand * 0.5 + 1; + var xslow = dt * pseudoRand * 0.05 + 1; + if (particle.vy < 1) + particle.vy = 0; + else + particle.vy = (particle.vy / yslow); + if (particle.vx < 1) + particle.vx = 0; + else + particle.vx = (particle.vx / xslow); + particle.update = true; + } + } + } + //! [1] + + ImageParticle { + anchors.fill: parent + id: particles + sprites: [Sprite { + source: "../../images/realLeaf1.png" + frameCount: 1 + frameDuration: 1 + to: {"a":1, "b":1, "c":1, "d":1} + }, Sprite { + name: "a" + source: "../../images/realLeaf1.png" + frameCount: 1 + frameDuration: 10000 + }, + Sprite { + name: "b" + source: "../../images/realLeaf2.png" + frameCount: 1 + frameDuration: 10000 + }, + Sprite { + name: "c" + source: "../../images/realLeaf3.png" + frameCount: 1 + frameDuration: 10000 + }, + Sprite { + name: "d" + source: "../../images/realLeaf4.png" + frameCount: 1 + frameDuration: 10000 + } + ] + + z:4 + } + } +} diff --git a/examples/quick/particles/affectors/content/friction.qml b/examples/quick/particles/affectors/content/friction.qml new file mode 100644 index 0000000000..aaf5917ee7 --- /dev/null +++ b/examples/quick/particles/affectors/content/friction.qml @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 { + anchors.fill: parent + Emitter { + width: parent.width + emitRate: 4 + lifeSpan: 14000 + size: 80 + velocity: PointDirection { y: 160; yVariation: 80; xVariation: 20 } + } + + ImageParticle { + anchors.fill: parent + id: particles + sprites: [Sprite { + source: "../../images/realLeaf1.png" + frameCount: 1 + frameDuration: 1 + to: {"a":1, "b":1, "c":1, "d":1} + }, Sprite { + name: "a" + source: "../../images/realLeaf1.png" + frameCount: 1 + frameDuration: 10000 + }, + Sprite { + name: "b" + source: "../../images/realLeaf2.png" + frameCount: 1 + frameDuration: 10000 + }, + Sprite { + name: "c" + source: "../../images/realLeaf3.png" + frameCount: 1 + frameDuration: 10000 + }, + Sprite { + name: "d" + source: "../../images/realLeaf4.png" + frameCount: 1 + frameDuration: 10000 + } + ] + + width: 100 + height: 100 + x: 20 + y: 20 + z:4 + } + + //! [0] + Friction { + anchors.fill: parent + anchors.margins: -40 + factor: 0.4 + } + //! [0] + } +} diff --git a/examples/quick/particles/affectors/content/gravity.qml b/examples/quick/particles/affectors/content/gravity.qml new file mode 100644 index 0000000000..123657f56a --- /dev/null +++ b/examples/quick/particles/affectors/content/gravity.qml @@ -0,0 +1,105 @@ +/**************************************************************************** +* +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 { + id: window + width: 320; height: 480 + Rectangle { + id: sky + anchors.fill: parent + gradient: Gradient { + GradientStop { + position: 0.0 + color: "DeepSkyBlue" + } + GradientStop { + position: 1.0 + color: "SkyBlue" + } + } + } + + Rectangle { + id: ground + width: parent.height * 2 + height: parent.height + y: parent.height/2 + x: parent.width/2 - parent.height + transformOrigin: Item.Top + rotation: 0 + gradient: Gradient { + GradientStop { position: 0.0; color: "ForestGreen"; } + GradientStop { position: 1.0; color: "DarkGreen"; } + } + } + + MouseArea { + anchors.fill: parent + onPositionChanged: { + var rot = Math.atan2(mouseY - window.height/2,mouseX - window.width/2) * 180/Math.PI; + ground.rotation = rot; + } + } + + ParticleSystem { id: sys } + //! [0] + Gravity { + system: sys + magnitude: 32 + angle: ground.rotation + 90 + } + //! [0] + Emitter { + system: sys + anchors.centerIn: parent + emitRate: 1 + lifeSpan: 10000 + size: 64 + } + ImageParticle { + anchors.fill: parent + system: sys + source: "../../images/realLeaf1.png" + } + +} diff --git a/examples/quick/particles/affectors/content/groupgoal.qml b/examples/quick/particles/affectors/content/groupgoal.qml new file mode 100644 index 0000000000..e36a52526f --- /dev/null +++ b/examples/quick/particles/affectors/content/groupgoal.qml @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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: "black" + + property int score: 0 + Text { + color: "white" + anchors.right: parent.right + text: score + } + + ParticleSystem { + id: particles + anchors.fill: parent + // ![unlit] + ParticleGroup { + name: "unlit" + duration: 1000 + to: {"lighting":1, "unlit":99} + ImageParticle { + source: "../../images/particleA.png" + colorVariation: 0.1 + color: "#2060160f" + } + GroupGoal { + whenCollidingWith: ["lit"] + goalState: "lighting" + jump: true + } + } + // ![unlit] + // ![lighting] + ParticleGroup { + name: "lighting" + duration: 100 + to: {"lit":1} + } + // ![lighting] + // ![lit] + ParticleGroup { + name: "lit" + duration: 10000 + onEntered: score++; + TrailEmitter { + id: fireballFlame + group: "flame" + + emitRatePerParticle: 48 + lifeSpan: 200 + emitWidth: 8 + emitHeight: 8 + + size: 24 + sizeVariation: 8 + endSize: 4 + } + + TrailEmitter { + id: fireballSmoke + group: "smoke" + // ![lit] + + emitRatePerParticle: 120 + lifeSpan: 2000 + emitWidth: 16 + emitHeight: 16 + + velocity: PointDirection {yVariation: 16; xVariation: 16} + acceleration: PointDirection {y: -16} + + size: 24 + sizeVariation: 8 + endSize: 8 + } + } + + ImageParticle { + id: smoke + anchors.fill: parent + groups: ["smoke"] + source: "../../images/particle.png" + colorVariation: 0 + color: "#00111111" + } + ImageParticle { + id: pilot + anchors.fill: parent + groups: ["pilot"] + source: "../../images/particle.png" + redVariation: 0.01 + blueVariation: 0.4 + color: "#0010004f" + } + ImageParticle { + id: flame + anchors.fill: parent + groups: ["flame", "lit", "lighting"] + source: "../../images/particleA.png" + colorVariation: 0.1 + color: "#00ff400f" + } + + Emitter { + height: parent.height/2 + emitRate: 4 + lifeSpan: 4000//TODO: Infinite & kill zone + size: 24 + sizeVariation: 4 + velocity: PointDirection {x:120; xVariation: 80; yVariation: 50} + acceleration: PointDirection {y:120} + group: "unlit" + } + + Emitter { + id: flamer + x: 100 + y: 300 + group: "pilot" + emitRate: 80 + lifeSpan: 600 + size: 24 + sizeVariation: 2 + endSize: 0 + velocity: PointDirection { y:-100; yVariation: 4; xVariation: 4 } + // ![groupgoal-pilot] + GroupGoal { + groups: ["unlit"] + goalState: "lit" + jump: true + system: particles + x: -15 + y: -55 + height: 75 + width: 30 + shape: MaskShape {source: "../../images/matchmask.png"} + } + // ![groupgoal-pilot] + } + // ![groupgoal-ma] + //Click to enflame + GroupGoal { + groups: ["unlit"] + goalState: "lighting" + jump: true + enabled: ma.pressed + width: 18 + height: 18 + x: ma.mouseX - width/2 + y: ma.mouseY - height/2 + } + // ![groupgoal-ma] + MouseArea { + id: ma + anchors.fill: parent + } + } +} diff --git a/examples/quick/particles/affectors/content/move.qml b/examples/quick/particles/affectors/content/move.qml new file mode 100644 index 0000000000..7bee550e13 --- /dev/null +++ b/examples/quick/particles/affectors/content/move.qml @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 { + width: 360 + height: 540 + color: "black" + ParticleSystem { + anchors.fill: parent + ImageParticle { + groups: ["A"] + anchors.fill: parent + source: "../../images/star.png" + color:"#FF1010" + redVariation: 0.8 + } + + Emitter { + group: "A" + emitRate: 100 + lifeSpan: 2800 + size: 32 + sizeVariation: 8 + velocity: PointDirection{ x: 66; xVariation: 20 } + width: 80 + height: 80 + } + + //! [A] + Affector { + groups: ["A"] + x: 120 + width: 80 + height: 80 + once: true + position: PointDirection { x: 120; } + } + //! [A] + + ImageParticle { + groups: ["B"] + anchors.fill: parent + source: "../../images/star.png" + color:"#10FF10" + greenVariation: 0.8 + } + + Emitter { + group: "B" + emitRate: 100 + lifeSpan: 2800 + size: 32 + sizeVariation: 8 + velocity: PointDirection{ x: 240; xVariation: 60 } + y: 260 + width: 10 + height: 10 + } + + //! [B] + Affector { + groups: ["B"] + x: 120 + y: 240 + width: 80 + height: 80 + once: true + velocity: AngleDirection { angleVariation:360; magnitude: 72 } + } + //! [B] + + ImageParticle { + groups: ["C"] + anchors.fill: parent + source: "../../images/star.png" + color:"#1010FF" + blueVariation: 0.8 + } + + Emitter { + group: "C" + y: 400 + emitRate: 100 + lifeSpan: 2800 + size: 32 + sizeVariation: 8 + velocity: PointDirection{ x: 80; xVariation: 10 } + acceleration: PointDirection { y: 10; x: 20; } + width: 80 + height: 80 + } + + //! [C] + Affector { + groups: ["C"] + x: 120 + y: 400 + width: 80 + height: 120 + once: true + relative: false + acceleration: PointDirection { y: -80; } + } + //! [C] + + } +} diff --git a/examples/quick/particles/affectors/content/spritegoal.qml b/examples/quick/particles/affectors/content/spritegoal.qml new file mode 100644 index 0000000000..28ba4ecbfc --- /dev/null +++ b/examples/quick/particles/affectors/content/spritegoal.qml @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 { + id: root + width: 360 + height: 540 + MouseArea { + id: ma + anchors.fill: parent + } + + ParticleSystem { id: sys } + Image { + source: "../../images/finalfrontier.png" + transformOrigin: Item.Center + anchors.centerIn: parent + NumberAnimation on rotation { + from: 0 + to: 360 + duration: 200000 + loops: Animation.Infinite + } + + } + ImageParticle { + system: sys + groups: ["starfield"] + source: "../../images/star.png" + colorVariation: 0.3 + color: "white" + } + Emitter { + id: starField + system: sys + group: "starfield" + + emitRate: 80 + lifeSpan: 2500 + + anchors.centerIn: parent + + //acceleration: AngledDirection {angleVariation: 360; magnitude: 200}//Is this a better effect, more consistent velocity? + acceleration: PointDirection { xVariation: 200; yVariation: 200; } + + size: 0 + endSize: 80 + sizeVariation: 10 + } + Emitter { + system: sys + group: "meteor" + emitRate: 12 + lifeSpan: 5000 + acceleration: PointDirection { xVariation: 80; yVariation: 80; } + size: 15 + endSize: 300 + anchors.centerIn: parent + } + ImageParticle { + system: sys + groups: ["meteor"] + sprites:[Sprite { + id: spinState + name: "spinning" + source: "../../images/meteor.png" + frameCount: 35 + frameDuration: 40 + randomStart: true + to: {"explode":0, "spinning":1} + },Sprite { + name: "explode" + source: "../../images/_explo.png" + frameCount: 22 + frameDuration: 40 + to: {"nullFrame":1} + },Sprite {//Not sure if this is needed, but seemed easiest + name: "nullFrame" + source: "../../images/nullRock.png" + frameCount: 1 + frameDuration: 1000 + } + ] + } + //! [0] + SpriteGoal { + groups: ["meteor"] + system: sys + goalState: "explode" + jump: true + anchors.fill: rocketShip + width: 60 + height: 60 + } + //! [0] + Image { + id: rocketShip + source: "../../images/rocket.png" + anchors.centerIn: holder + rotation: (circle.percent+0.25) * 360 + z: 2 + } + Item { + id: holder + x: circle.x - Math.sin(circle.percent * 6.28316530714)*200 + y: circle.y + Math.cos(circle.percent * 6.28316530714)*200 + z: 1 + } + + Item { + id: circle + x: root.width / 1.2 + y: root.height / 1.7 + property real percent: 0 + + SequentialAnimation on percent { + id: circleAnim1 + loops: Animation.Infinite + running: true + NumberAnimation { + duration: 4000 + from: 1 + to: 0 + } + + } + } + + ImageParticle { + z:0 + system: sys + groups: ["exhaust"] + 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 + } + + Emitter { + id: trailsNormal2 + system: sys + group: "exhaust" + + emitRate: 300 + lifeSpan: 500 + + y: holder.y + x: holder.x + + velocity: PointDirection { xVariation: 40; yVariation: 40; } + velocityFromMovement: 16 + + acceleration: PointDirection { xVariation: 10; yVariation: 10; } + + size: 4 + sizeVariation: 4 + } +} diff --git a/examples/quick/particles/affectors/content/turbulence.qml b/examples/quick/particles/affectors/content/turbulence.qml new file mode 100644 index 0000000000..b80aa7ee1c --- /dev/null +++ b/examples/quick/particles/affectors/content/turbulence.qml @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 { + width: 320 + height: 480 + color: "#222222" + id: root + Image { + source: "../../images/candle.png" + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottomMargin: -60 + anchors.horizontalCenterOffset: 2 + } + ParticleSystem { + anchors.fill: parent + MouseArea { + anchors.fill: parent + onClicked: turb.enabled = !turb.enabled + } + + //! [0] + Turbulence { + id: turb + enabled: true + height: (parent.height / 2) - 4 + width: parent.width + x: parent. width / 4 + anchors.fill: parent + strength: 32 + NumberAnimation on strength{from: 16; to: 64; easing.type: Easing.InOutBounce; duration: 1800; loops: -1} + } + //! [0] + + ImageParticle { + groups: ["smoke"] + source: "../../images/particle.png" + color: "#11111111" + colorVariation: 0 + } + ImageParticle { + groups: ["flame"] + source: "../../images/particle.png" + color: "#11ff400f" + colorVariation: 0.1 + } + Emitter { + anchors.centerIn: parent + group: "flame" + + emitRate: 120 + lifeSpan: 1200 + size: 20 + endSize: 10 + sizeVariation: 10 + acceleration: PointDirection { y: -40 } + velocity: AngleDirection { angle: 270; magnitude: 20; angleVariation: 22; magnitudeVariation: 5 } + } + TrailEmitter { + id: smoke1 + width: root.width + height: root.height/2 + group: "smoke" + follow: "flame" + + emitRatePerParticle: 1 + lifeSpan: 2400 + lifeSpanVariation: 400 + size: 16 + endSize: 8 + sizeVariation: 8 + acceleration: PointDirection { y: -40 } + velocity: AngleDirection { angle: 270; magnitude: 40; angleVariation: 22; magnitudeVariation: 5 } + } + TrailEmitter { + id: smoke2 + width: root.width + height: root.height/2 - 20 + group: "smoke" + follow: "flame" + + emitRatePerParticle: 4 + lifeSpan: 2400 + size: 36 + endSize: 24 + sizeVariation: 12 + acceleration: PointDirection { y: -40 } + velocity: AngleDirection { angle: 270; magnitude: 40; angleVariation: 22; magnitudeVariation: 5 } + } + } +} diff --git a/examples/quick/particles/affectors/content/wander.qml b/examples/quick/particles/affectors/content/wander.qml new file mode 100644 index 0000000000..f8ac7bae40 --- /dev/null +++ b/examples/quick/particles/affectors/content/wander.qml @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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 +import "../../../shared" as UI //Has a shared UI element + +Rectangle { + width: 360 + height: 540 + ParticleSystem { id: particles } + ImageParticle { + system: particles + sprites: Sprite { + name: "snow" + source: "../../images/snowflake.png" + frameCount: 51 + frameDuration: 40 + frameDurationVariation: 8 + } + } + + //! [0] + Wander { + id: wanderer + system: particles + anchors.fill: parent + xVariance: 360/(wanderer.affectedParameter+1); + pace: 100*(wanderer.affectedParameter+1); + } + //! [0] + + Emitter { + system: particles + emitRate: 20 + lifeSpan: 7000 + velocity: PointDirection { y:80; yVariation: 40; } + acceleration: PointDirection { y: 4 } + size: 20 + sizeVariation: 10 + width: parent.width + height: 100 + } + Row { + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + spacing: 4 + GreyButton { + text:"dx/dt" + onClicked: wanderer.affectedParameter = Wander.Position; + } + GreyButton { + text:"dv/dt" + onClicked: wanderer.affectedParameter = Wander.Velocity; + } + GreyButton { + text:"da/dt" + onClicked: wanderer.affectedParameter = Wander.Acceleration; + } + } +} diff --git a/examples/quick/particles/affectors/doc/images/qml-affectors-example.png b/examples/quick/particles/affectors/doc/images/qml-affectors-example.png Binary files differnew file mode 100644 index 0000000000..748afa65e5 --- /dev/null +++ b/examples/quick/particles/affectors/doc/images/qml-affectors-example.png diff --git a/examples/quick/particles/affectors/doc/src/affectors.qdoc b/examples/quick/particles/affectors/doc/src/affectors.qdoc new file mode 100644 index 0000000000..c0759f5fe3 --- /dev/null +++ b/examples/quick/particles/affectors/doc/src/affectors.qdoc @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \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 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 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 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 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 particles/affectors/content/friction.qml 0 + + Gravity is a convenience affector for applying a constant acceleration to particles inside it + \snippet 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 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 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 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 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 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 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 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 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 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 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 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. +*/ + diff --git a/examples/quick/particles/affectors/main.cpp b/examples/quick/particles/affectors/main.cpp new file mode 100644 index 0000000000..358fcb4d8d --- /dev/null +++ b/examples/quick/particles/affectors/main.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia Plc 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$ +** +****************************************************************************/ +#include "../../shared/shared.h" +DECLARATIVE_EXAMPLE_MAIN(affectors) |