diff options
Diffstat (limited to 'examples/quick/particles')
106 files changed, 6083 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) diff --git a/examples/quick/particles/customparticle/content/blurparticles.qml b/examples/quick/particles/customparticle/content/blurparticles.qml new file mode 100644 index 0000000000..30197fe414 --- /dev/null +++ b/examples/quick/particles/customparticle/content/blurparticles.qml @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** 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 { + color: "white" + width: 240 + height: 360 + ParticleSystem { + id: sys + } + Emitter { + system:sys + height: parent.height + emitRate: 1 + lifeSpan: 12000 + velocity: PointDirection {x:20;} + size: 128 + } + ShaderEffectSource { + id: theSource + sourceItem: theItem + hideSource: true + } + Image { + id: theItem + source: "../../images/starfish_1.png" + } + + CustomParticle { + system: sys + //! [vertex] + vertexShader:" + uniform lowp float qt_Opacity; + varying lowp float fFade; + varying lowp float fBlur; + + void main() { + defaultMain(); + highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y; + highp float fadeIn = min(t * 10., 1.); + highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.)); + + fFade = fadeIn * fadeOut * qt_Opacity; + fBlur = max(0.2 * t, t * qt_ParticleR); + } + " + //! [vertex] + property variant source: theSource + property variant blurred: ShaderEffectSource { + sourceItem: ShaderEffect { + width: theItem.width + height: theItem.height + property variant delta: Qt.size(0.0, 1.0 / height) + property variant source: ShaderEffectSource { + sourceItem: ShaderEffect { + width: theItem.width + height: theItem.height + property variant delta: Qt.size(1.0 / width, 0.0) + property variant source: theSource + fragmentShader: " + uniform sampler2D source; + uniform lowp float qt_Opacity; + uniform highp vec2 delta; + varying highp vec2 qt_TexCoord0; + void main() { + gl_FragColor =(0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta) + + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta) + + 0.2466 * texture2D(source, qt_TexCoord0) + + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta) + + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta)) * qt_Opacity; + }" + } + } + fragmentShader: " + uniform sampler2D source; + uniform lowp float qt_Opacity; + uniform highp vec2 delta; + varying highp vec2 qt_TexCoord0; + void main() { + gl_FragColor =(0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta) + + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta) + + 0.2466 * texture2D(source, qt_TexCoord0) + + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta) + + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta)) * qt_Opacity; + }" + } + } + //! [fragment] + fragmentShader: " + uniform sampler2D source; + uniform sampler2D blurred; + varying highp vec2 qt_TexCoord0; + varying highp float fBlur; + varying highp float fFade; + void main() { + gl_FragColor = mix(texture2D(source, qt_TexCoord0), texture2D(blurred, qt_TexCoord0), min(1.0,fBlur*3.0)) * fFade; + }" + //! [fragment] + + } +} + diff --git a/examples/quick/particles/customparticle/content/fragmentshader.qml b/examples/quick/particles/customparticle/content/fragmentshader.qml new file mode 100644 index 0000000000..2cea780f33 --- /dev/null +++ b/examples/quick/particles/customparticle/content/fragmentshader.qml @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** 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 + +ParticleSystem { + id: root + width: 320 + height: 480 + Rectangle { + z: -1 + anchors.fill: parent + color: "black" + Text { + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: 14 + color: "white" + text: "It's all in the fragment shader." + } + } + + Emitter { + emitRate: 400 + lifeSpan: 8000 + size: 24 + sizeVariation: 16 + velocity: PointDirection {x: root.width/10; y: root.height/10;} + acceleration: PointDirection {x: -root.width/40; y: -root.height/40; xVariation: -root.width/20; yVariation: -root.width/20} + } + + CustomParticle { + vertexShader:" + uniform lowp float qt_Opacity; + varying lowp float fFade; + varying highp vec2 fPos; + + void main() { + qt_TexCoord0 = qt_ParticleTex; + highp float size = qt_ParticleData.z; + highp float endSize = qt_ParticleData.w; + + highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y; + + highp float currentSize = mix(size, endSize, t * t); + + if (t < 0. || t > 1.) + currentSize = 0.; + + highp vec2 pos = qt_ParticlePos + - currentSize / 2. + currentSize * qt_ParticleTex // adjust size + + qt_ParticleVec.xy * t * qt_ParticleData.y // apply velocity vector.. + + 0.5 * qt_ParticleVec.zw * pow(t * qt_ParticleData.y, 2.); + + gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1); + + highp float fadeIn = min(t * 20., 1.); + highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.)); + + fFade = fadeIn * fadeOut * qt_Opacity; + fPos = vec2(pos.x/320., pos.y/480.); + } + " + //! [0] + fragmentShader: " + varying highp vec2 fPos; + varying lowp float fFade; + varying highp vec2 qt_TexCoord0; + void main() {//*2 because this generates dark colors mostly + highp vec2 circlePos = qt_TexCoord0*2.0 - vec2(1.0,1.0); + highp float dist = length(circlePos); + highp float circleFactor = max(min(1.0 - dist, 1.0), 0.0); + gl_FragColor = vec4(fPos.x*2.0 - fPos.y, fPos.y*2.0 - fPos.x, fPos.x*fPos.y*2.0, 0.0) * circleFactor * fFade; + }" + //! [0] + + } +} diff --git a/examples/quick/particles/customparticle/content/imagecolors.qml b/examples/quick/particles/customparticle/content/imagecolors.qml new file mode 100644 index 0000000000..857375a05c --- /dev/null +++ b/examples/quick/particles/customparticle/content/imagecolors.qml @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** 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: 400 + height: 400 + Rectangle { + id: root + color: "white" + width: 310 + height: 300 + anchors.centerIn: parent + ParticleSystem { id: sys } + CustomParticle { + system: sys + property real maxWidth: root.width + property real maxHeight: root.height + ShaderEffectSource { + id: pictureSource + sourceItem: picture + hideSource: true + } + Image { + id: picture + source: "../../images/starfish_3.png" + } + ShaderEffectSource { + id: particleSource + sourceItem: particle + hideSource: true + } + Image { + id: particle + source: "../../images/particle4.png" + } + //! [vertex] + vertexShader:" + uniform highp float maxWidth; + uniform highp float maxHeight; + varying highp vec2 fTex2; + varying lowp float fFade; + uniform lowp float qt_Opacity; + + void main() { + + fTex2 = vec2(qt_ParticlePos.x, qt_ParticlePos.y); + //Uncomment this next line for each particle to use full texture, instead of the solid color at the center of the particle. + //fTex2 = fTex2 + ((- qt_ParticleData.z / 2. + qt_ParticleData.z) * qt_ParticleTex); //Adjusts size so it's like a chunk of image. + fTex2 = fTex2 / vec2(maxWidth, maxHeight); + highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y; + fFade = min(t*4., (1.-t*t)*.75) * qt_Opacity; + defaultMain(); + } + " + //! [vertex] + property variant particleTexture: particleSource + property variant pictureTexture: pictureSource + //! [fragment] + fragmentShader: " + uniform sampler2D particleTexture; + uniform sampler2D pictureTexture; + varying highp vec2 qt_TexCoord0; + varying highp vec2 fTex2; + varying lowp float fFade; + void main() { + gl_FragColor = texture2D(pictureTexture, fTex2) * texture2D(particleTexture, qt_TexCoord0).w * fFade; + }" + //! [fragment] + } + + Emitter { + id: emitter + system: sys + enabled: false + lifeSpan: 8000 + maximumEmitted: 4000 + anchors.fill: parent + size: 16 + acceleration: PointDirection { xVariation: 12; yVariation: 12 } + } + MouseArea { + anchors.fill: parent + onClicked: emitter.burst(4000); + } + } +} diff --git a/examples/quick/particles/customparticle/customparticle.pro b/examples/quick/particles/customparticle/customparticle.pro new file mode 100644 index 0000000000..77db1a6aab --- /dev/null +++ b/examples/quick/particles/customparticle/customparticle.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/customparticle +qml.files = customparticle.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/customparticle +INSTALLS += target qml diff --git a/examples/quick/particles/customparticle/customparticle.qml b/examples/quick/particles/customparticle/customparticle.qml new file mode 100644 index 0000000000..ee93648132 --- /dev/null +++ b/examples/quick/particles/customparticle/customparticle.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** 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("Blur Particles", "Particles that get blurred over time", Qt.resolvedUrl("content/blurparticles.qml")); + addExample("Fragment Shader", "Particles drawn with a custom fragment shader", Qt.resolvedUrl("content/fragmentshader.qml")); + addExample("Image Colors", "An image explodes into colored particles", Qt.resolvedUrl("content/imagecolors.qml")); + } + } +} diff --git a/examples/quick/particles/customparticle/customparticle.qmlproject b/examples/quick/particles/customparticle/customparticle.qmlproject new file mode 100644 index 0000000000..6ea1849e31 --- /dev/null +++ b/examples/quick/particles/customparticle/customparticle.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.1 + +Project { + mainFile: "customparticle.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +} diff --git a/examples/quick/particles/customparticle/doc/images/qml-customparticle-example.png b/examples/quick/particles/customparticle/doc/images/qml-customparticle-example.png Binary files differnew file mode 100644 index 0000000000..e23c6c8efc --- /dev/null +++ b/examples/quick/particles/customparticle/doc/images/qml-customparticle-example.png diff --git a/examples/quick/particles/customparticle/doc/src/customparticle.qdoc b/examples/quick/particles/customparticle/doc/src/customparticle.qdoc new file mode 100644 index 0000000000..39c3d7c101 --- /dev/null +++ b/examples/quick/particles/customparticle/doc/src/customparticle.qdoc @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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 - CustomParticle + \example particles/customparticle + \brief This is a collection of examples using CustomParticle in the QML particle system. + \image qml-customparticle-example.png + + This is a collection of small QML examples relating to using CustomParticle in the particle system. + Each example is a small QML file emphasizing a different way to use CustomParticle. + + Blur Particles adds a blur effect to the particles, which increases over the particle's life time. + It uses a custom vertex shader: + \snippet particles/customparticle/content/blurparticles.qml vertex + to propagate life time simulation to a custom fragement shader: + \snippet particles/customparticle/content/blurparticles.qml fragment + which has access to both the normal image sampler and a blurred sampler, the image plus a ShaderEffect. + + Fragment Shader just uses the particle system as a vertex delivery system. + \snippet particles/customparticle/content/fragmentshader.qml 0 + + Image Colors uses CustomParticle to assign colors to particles based on their location in a picture. + The vertex shader, + \snippet particles/customparticle/content/imagecolors.qml vertex + passes along the starting position for each vertex to the fragment shader, + \snippet particles/customparticle/content/imagecolors.qml fragment + which uses it to determine the color for that particle. + +*/ diff --git a/examples/quick/particles/customparticle/main.cpp b/examples/quick/particles/customparticle/main.cpp new file mode 100644 index 0000000000..ec5619c6f0 --- /dev/null +++ b/examples/quick/particles/customparticle/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(customparticle) diff --git a/examples/quick/particles/emitters/content/burstandpulse.qml b/examples/quick/particles/emitters/content/burstandpulse.qml new file mode 100644 index 0000000000..ae526aa5a3 --- /dev/null +++ b/examples/quick/particles/emitters/content/burstandpulse.qml @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** 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: "black" + property bool lastWasPulse: false + Timer { + interval: 3500 + triggeredOnStart: true + running: true + repeat: true + onTriggered: { + //! [0] + if (lastWasPulse) { + burstEmitter.burst(500); + lastWasPulse = false; + } else { + pulseEmitter.pulse(500); + lastWasPulse = true; + } + //! [0] + } + } + ParticleSystem { + id: particles + anchors.fill: parent + ImageParticle { + source: "../../images/star.png" + alpha: 0 + colorVariation: 0.6 + } + + Emitter { + id: burstEmitter + x: parent.width/2 + y: parent.height/3 + emitRate: 1000 + lifeSpan: 2000 + enabled: false + velocity: AngleDirection{magnitude: 64; angleVariation: 360} + size: 24 + sizeVariation: 8 + Text { + anchors.centerIn: parent + color: "white" + font.pixelSize: 18 + text: "Burst" + } + } + Emitter { + id: pulseEmitter + x: parent.width/2 + y: 2*parent.height/3 + emitRate: 1000 + lifeSpan: 2000 + enabled: false + velocity: AngleDirection{magnitude: 64; angleVariation: 360} + size: 24 + sizeVariation: 8 + Text { + anchors.centerIn: parent + color: "white" + font.pixelSize: 18 + text: "Pulse" + } + } + } +} diff --git a/examples/quick/particles/emitters/content/customemitter.qml b/examples/quick/particles/emitters/content/customemitter.qml new file mode 100644 index 0000000000..40b04a56d5 --- /dev/null +++ b/examples/quick/particles/emitters/content/customemitter.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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 + +ParticleSystem { + id: sys + width: 360 + height: 600 + running: true + Rectangle { + z: -1 + anchors.fill: parent + color: "black" + } + + property real petalLength: 180 + property real petalRotation: 0 + NumberAnimation on petalRotation { + from: 0; + to: 360; + loops: -1; + running: true + duration: 24000 + } + + function convert(a) {return a*(Math.PI/180);} + Emitter { + lifeSpan: 4000 + emitRate: 120 + size: 12 + anchors.centerIn: parent + //! [0] + onEmitParticles: { + for (var i=0; i<particles.length; i++) { + var particle = particles[i]; + particle.startSize = Math.max(02,Math.min(492,Math.tan(particle.t/2)*24)); + var theta = Math.floor(Math.random() * 6.0); + particle.red = theta == 0 || theta == 1 || theta == 2 ? 0.2 : 1; + particle.green = theta == 2 || theta == 3 || theta == 4 ? 0.2 : 1; + particle.blue = theta == 4 || theta == 5 || theta == 0 ? 0.2 : 1; + theta /= 6.0; + theta *= 2.0*Math.PI; + theta += sys.convert(sys.petalRotation);//Convert from degrees to radians + particle.initialVX = petalLength * Math.cos(theta); + particle.initialVY = petalLength * Math.sin(theta); + particle.initialAX = particle.initialVX * -0.5; + particle.initialAY = particle.initialVY * -0.5; + } + } + //! [0] + } + + ImageParticle { + source: "../../images/particle4.png" + alpha: 0.0 + } +} diff --git a/examples/quick/particles/emitters/content/emitmask.qml b/examples/quick/particles/emitters/content/emitmask.qml new file mode 100644 index 0000000000..0ecaa61670 --- /dev/null +++ b/examples/quick/particles/emitters/content/emitmask.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 { + color: "goldenrod" + width: 400 + height: 400 + ParticleSystem { + width: 300 + height: 300 + anchors.centerIn: parent + + ImageParticle { + source: "../../images/particle.png" + z: 2 + anchors.fill: parent + color: "#336666CC" + colorVariation: 0.0 + } + + Emitter { + anchors.fill: parent + emitRate: 6000 + lifeSpan: 720 + size: 10 + //! [0] + shape: MaskShape { + source: "../../images/starfish_mask.png" + } + //! [0] + } + + } +} diff --git a/examples/quick/particles/emitters/content/maximumemitted.qml b/examples/quick/particles/emitters/content/maximumemitted.qml new file mode 100644 index 0000000000..25c608882b --- /dev/null +++ b/examples/quick/particles/emitters/content/maximumemitted.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 { + color: "black" + width: 360 + height: 540 + ParticleSystem { + id: sys + anchors.fill: parent + onEmptyChanged: if (empty) sys.pause(); + + ImageParticle { + system: sys + id: cp + source: "../../images/particle.png" + colorVariation: 0.4 + color: "#000000FF" + } + + Emitter { + //burst on click + id: bursty + system: sys + enabled: ma.pressed + x: ma.mouseX + y: ma.mouseY + emitRate: 16000 + maximumEmitted: 4000 + acceleration: AngleDirection {angleVariation: 360; magnitude: 360; } + size: 8 + endSize: 16 + sizeVariation: 4 + } + + MouseArea { + anchors.fill: parent + onPressed: sys.resume() + id: ma + } + } +} diff --git a/examples/quick/particles/emitters/content/shapeanddirection.qml b/examples/quick/particles/emitters/content/shapeanddirection.qml new file mode 100644 index 0000000000..14307258ae --- /dev/null +++ b/examples/quick/particles/emitters/content/shapeanddirection.qml @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** 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 { + anchors.fill: parent + source: "../../images/portal_bg.png" + } + + ParticleSystem { + id: particles + anchors.fill: parent + + ImageParticle { + groups: ["center","edge"] + anchors.fill: parent + source: "../../images/particle.png" + colorVariation: 0.1 + color: "#009999FF" + } + + Emitter { + anchors.fill: parent + group: "center" + emitRate: 400 + lifeSpan: 2000 + size: 20 + sizeVariation: 2 + endSize: 0 + //! [0] + shape: EllipseShape {fill: false} + velocity: TargetDirection { + targetX: root.width/2 + targetY: root.height/2 + proportionalMagnitude: true + magnitude: 0.5 + } + //! [0] + } + + Emitter { + anchors.fill: parent + group: "edge" + startTime: 2000 + emitRate: 2000 + lifeSpan: 2000 + size: 28 + sizeVariation: 2 + endSize: 16 + shape: EllipseShape {fill: false} + velocity: TargetDirection { + targetX: root.width/2 + targetY: root.height/2 + proportionalMagnitude: true + magnitude: 0.1 + magnitudeVariation: 0.1 + } + acceleration: TargetDirection { + targetX: root.width/2 + targetY: root.height/2 + targetVariation: 200 + proportionalMagnitude: true + magnitude: 0.1 + magnitudeVariation: 0.1 + } + } + } +} diff --git a/examples/quick/particles/emitters/content/trailemitter.qml b/examples/quick/particles/emitters/content/trailemitter.qml new file mode 100644 index 0000000000..0fab2e73ea --- /dev/null +++ b/examples/quick/particles/emitters/content/trailemitter.qml @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** 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" + + ParticleSystem { + id: particles + anchors.fill: parent + + ImageParticle { + id: smoke + system: particles + anchors.fill: parent + groups: ["A", "B"] + source: "../../images/particle.png" + colorVariation: 0 + color: "#00111111" + } + ImageParticle { + id: flame + anchors.fill: parent + system: particles + groups: ["C", "D"] + source: "../../images/particle.png" + colorVariation: 0.1 + color: "#00ff400f" + } + + Emitter { + id: fire + system: particles + group: "C" + + y: parent.height + width: parent.width + + emitRate: 350 + lifeSpan: 3500 + + acceleration: PointDirection { y: -17; xVariation: 3 } + velocity: PointDirection {xVariation: 3} + + size: 24 + sizeVariation: 8 + endSize: 4 + } + + TrailEmitter { + id: fireSmoke + group: "B" + system: particles + follow: "C" + width: root.width + height: root.height - 68 + + emitRatePerParticle: 1 + lifeSpan: 2000 + + velocity: PointDirection {y:-17*6; yVariation: -17; xVariation: 3} + acceleration: PointDirection {xVariation: 3} + + size: 36 + sizeVariation: 8 + endSize: 16 + } + + TrailEmitter { + id: fireballFlame + anchors.fill: parent + system: particles + group: "D" + follow: "E" + + emitRatePerParticle: 120 + lifeSpan: 180 + emitWidth: TrailEmitter.ParticleSize + emitHeight: TrailEmitter.ParticleSize + emitShape: EllipseShape{} + + size: 16 + sizeVariation: 4 + endSize: 4 + } + + TrailEmitter { + id: fireballSmoke + anchors.fill: parent + system: particles + group: "A" + follow: "E" + + emitRatePerParticle: 128 + lifeSpan: 2400 + emitWidth: TrailEmitter.ParticleSize + emitHeight: TrailEmitter.ParticleSize + emitShape: EllipseShape{} + + velocity: PointDirection {yVariation: 16; xVariation: 16} + acceleration: PointDirection {y: -16} + + size: 24 + sizeVariation: 8 + endSize: 8 + } + + Emitter { + id: balls + system: particles + group: "E" + + y: parent.height + width: parent.width + + emitRate: 2 + lifeSpan: 7000 + + velocity: PointDirection {y:-17*4*2; xVariation: 6*6} + acceleration: PointDirection {y: 17*2; xVariation: 6*6} + + size: 8 + sizeVariation: 4 + } + + Turbulence { //A bit of turbulence makes the smoke look better + anchors.fill: parent + groups: ["A","B"] + strength: 32 + system: particles + } + } +} + diff --git a/examples/quick/particles/emitters/content/velocityfrommotion.qml b/examples/quick/particles/emitters/content/velocityfrommotion.qml new file mode 100644 index 0000000000..ce8bfe11cd --- /dev/null +++ b/examples/quick/particles/emitters/content/velocityfrommotion.qml @@ -0,0 +1,312 @@ +/**************************************************************************** +** +** 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 + + height: 540 + width: 360 + + gradient: Gradient { + GradientStop { position: 0; color: "#000020" } + GradientStop { position: 1; color: "#000000" } + } + + MouseArea { + id: mouseArea + anchors.fill: root + } + + ParticleSystem { id: sys1 } + ImageParticle { + system: sys1 + source: "../../images/particle.png" + color: "cyan" + alpha: 0 + SequentialAnimation on color { + loops: Animation.Infinite + ColorAnimation { + from: "cyan" + to: "magenta" + duration: 1000 + } + ColorAnimation { + from: "magenta" + to: "blue" + duration: 2000 + } + ColorAnimation { + from: "blue" + to: "violet" + duration: 2000 + } + ColorAnimation { + from: "violet" + to: "cyan" + duration: 2000 + } + } + colorVariation: 0.3 + } + //! [0] + Emitter { + id: trailsNormal + system: sys1 + + emitRate: 500 + lifeSpan: 2000 + + y: mouseArea.pressed ? mouseArea.mouseY : circle.cy + x: mouseArea.pressed ? mouseArea.mouseX : circle.cx + + velocity: PointDirection {xVariation: 4; yVariation: 4;} + acceleration: PointDirection {xVariation: 10; yVariation: 10;} + velocityFromMovement: 8 + + size: 8 + sizeVariation: 4 + } + //! [0] + ParticleSystem { id: sys2 } + ImageParticle { + color: "cyan" + system: sys2 + alpha: 0 + SequentialAnimation on color { + loops: Animation.Infinite + ColorAnimation { + from: "magenta" + to: "cyan" + duration: 1000 + } + ColorAnimation { + from: "cyan" + to: "magenta" + duration: 2000 + } + } + colorVariation: 0.5 + source: "../../images/star.png" + } + Emitter { + id: trailsStars + system: sys2 + + emitRate: 100 + lifeSpan: 2200 + + + y: mouseArea.pressed ? mouseArea.mouseY : circle.cy + x: mouseArea.pressed ? mouseArea.mouseX : circle.cx + + velocity: PointDirection {xVariation: 4; yVariation: 4;} + acceleration: PointDirection {xVariation: 10; yVariation: 10;} + velocityFromMovement: 8 + + size: 22 + sizeVariation: 4 + } + ParticleSystem { id: sys3; } + ImageParticle { + source: "../../images/particle.png" + system: sys3 + color: "orange" + alpha: 0 + SequentialAnimation on color { + loops: Animation.Infinite + ColorAnimation { + from: "red" + to: "green" + duration: 2000 + } + ColorAnimation { + from: "green" + to: "red" + duration: 2000 + } + } + + colorVariation: 0.2 + + } + Emitter { + id: trailsNormal2 + system: sys3 + + emitRate: 300 + lifeSpan: 2000 + + y: mouseArea.pressed ? mouseArea.mouseY : circle2.cy + x: mouseArea.pressed ? mouseArea.mouseX : circle2.cx + + velocityFromMovement: 16 + + velocity: PointDirection {xVariation: 4; yVariation: 4;} + acceleration: PointDirection {xVariation: 10; yVariation: 10;} + + size: 12 + sizeVariation: 4 + } + ParticleSystem { id: sys4; } + ImageParticle { + system: sys4 + source: "../../images/star.png" + color: "green" + alpha: 0 + SequentialAnimation on color { + loops: Animation.Infinite + ColorAnimation { + from: "green" + to: "red" + duration: 2000 + } + ColorAnimation { + from: "red" + to: "green" + duration: 2000 + } + } + + colorVariation: 0.5 + } + Emitter { + id: trailsStars2 + system: sys4 + + emitRate: 50 + lifeSpan: 2200 + + + y: mouseArea.pressed ? mouseArea.mouseY : circle2.cy + x: mouseArea.pressed ? mouseArea.mouseX : circle2.cx + + velocityFromMovement: 16 + velocity: PointDirection {xVariation: 2; yVariation: 2;} + acceleration: PointDirection {xVariation: 10; yVariation: 10;} + + size: 22 + sizeVariation: 4 + } + + + + color: "white" + + Item { + id: circle + //anchors.fill: parent + property real radius: 0 + property real dx: root.width / 2 + property real dy: root.height / 2 + property real cx: radius * Math.sin(percent*6.283185307179) + dx + property real cy: radius * Math.cos(percent*6.283185307179) + dy + property real percent: 0 + + SequentialAnimation on percent { + loops: Animation.Infinite + running: true + NumberAnimation { + duration: 1000 + from: 1 + to: 0 + loops: 8 + } + NumberAnimation { + duration: 1000 + from: 0 + to: 1 + loops: 8 + } + + } + + SequentialAnimation on radius { + loops: Animation.Infinite + running: true + NumberAnimation { + duration: 4000 + from: 0 + to: 100 + } + NumberAnimation { + duration: 4000 + from: 100 + to: 0 + } + } + } + + Item { + id: circle3 + property real radius: 100 + property real dx: root.width / 2 + property real dy: root.height / 2 + property real cx: radius * Math.sin(percent*6.283185307179) + dx + property real cy: radius * Math.cos(percent*6.283185307179) + dy + property real percent: 0 + + SequentialAnimation on percent { + loops: Animation.Infinite + running: true + NumberAnimation { from: 0.0; to: 1 ; duration: 10000; } + } + } + + Item { + id: circle2 + property real radius: 30 + property real dx: circle3.cx + property real dy: circle3.cy + property real cx: radius * Math.sin(percent*6.283185307179) + dx + property real cy: radius * Math.cos(percent*6.283185307179) + dy + property real percent: 0 + + SequentialAnimation on percent { + loops: Animation.Infinite + running: true + NumberAnimation { from: 0.0; to: 1 ; duration: 1000; } + } + } + +} diff --git a/examples/quick/particles/emitters/doc/images/qml-emitters-example.png b/examples/quick/particles/emitters/doc/images/qml-emitters-example.png Binary files differnew file mode 100644 index 0000000000..0025afd30c --- /dev/null +++ b/examples/quick/particles/emitters/doc/images/qml-emitters-example.png diff --git a/examples/quick/particles/emitters/doc/src/emitters.qdoc b/examples/quick/particles/emitters/doc/src/emitters.qdoc new file mode 100644 index 0000000000..37da46f2df --- /dev/null +++ b/examples/quick/particles/emitters/doc/src/emitters.qdoc @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 - Emitters + \example particles/emitters + \brief This is a collection of examples using Emitters in the QML particle system. + \image qml-emitters-example.png + + This is a collection of small QML examples relating to using Emitters in the particle system. + Each example is a small QML file emphasizing a particular element or feature. + + Velocity from motion gives the effect of strong particle motion through primarily moving the emitters: + \snippet particles/emitters/content/velocityfrommotion.qml 0 + + Burst and pulse calls the burst and pulse methods on two idential emitters. + \snippet particles/emitters/content/burstandpulse.qml 0 + Note how burst takes an argument of number of particles to emit, and pulse takes an argument of number of milliseconds to emit for. + This gives a slightly different behaviour, which is easy to see in this example. + + Custom Emitter connects to the emitParticles signal to set arbitrary values on particle data as they're emitted; + \snippet particles/emitters/content/customemitter.qml 0 + This is used to emit curving particles in six rotating spokes. + + Emit mask sets an image mask on the Emitter, to emit out of an arbitrary shape. + \snippet particles/emitters/content/emitmask.qml 0 + + Maximum emitted emits no more than a certain number of particles at a time. This example makes it easy to see what happens when the limit is reached. + + Shape and Direction emits particles out of an unfilled Ellipse shape, using a TargetDirection + \snippet particles/emitters/content/shapeanddirection.qml 0 + This sends the particles towards the center of the ellipse with proportional speed, keeping the ellipse outline as they move to the center. + + TrailEmitter uses that element to add smoke particles to trail the fire particles in the scene. + \snippet particles/emitters/content/customemitter.qml 0 + +*/ diff --git a/examples/quick/particles/emitters/emitters.pro b/examples/quick/particles/emitters/emitters.pro new file mode 100644 index 0000000000..ea2e0d15ba --- /dev/null +++ b/examples/quick/particles/emitters/emitters.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/emitters +qml.files = emitters.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/emitters +INSTALLS += target qml diff --git a/examples/quick/particles/emitters/emitters.qml b/examples/quick/particles/emitters/emitters.qml new file mode 100644 index 0000000000..060d01fe4c --- /dev/null +++ b/examples/quick/particles/emitters/emitters.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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("Velocity from Motion", "Particle motion just by moving emitters", Qt.resolvedUrl("content/velocityfrommotion.qml")); + addExample("Burst and Pulse", "Emit imperatively", Qt.resolvedUrl("content/burstandpulse.qml")); + addExample("Custom Emitter", "Custom starting state", Qt.resolvedUrl("content/customemitter.qml")); + addExample("Emit Mask", "Emit arbitrary shapes", Qt.resolvedUrl("content/emitmask.qml")); + addExample("Maximum Emitted", "Put a limit on emissions", Qt.resolvedUrl("content/maximumemitted.qml")); + addExample("Shape and Direction", "Creates a portal effect", Qt.resolvedUrl("content/shapeanddirection.qml")); + addExample("TrailEmitter", "Emit from other particles", Qt.resolvedUrl("content/trailemitter.qml")); + } + } +} diff --git a/examples/quick/particles/emitters/emitters.qmlproject b/examples/quick/particles/emitters/emitters.qmlproject new file mode 100644 index 0000000000..5379aac1dc --- /dev/null +++ b/examples/quick/particles/emitters/emitters.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.1 + +Project { + mainFile: "emitters.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +} diff --git a/examples/quick/particles/emitters/main.cpp b/examples/quick/particles/emitters/main.cpp new file mode 100644 index 0000000000..01aff50ea3 --- /dev/null +++ b/examples/quick/particles/emitters/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(emitters) diff --git a/examples/quick/particles/imageparticle/content/allatonce.qml b/examples/quick/particles/imageparticle/content/allatonce.qml new file mode 100644 index 0000000000..0e3e86c41f --- /dev/null +++ b/examples/quick/particles/imageparticle/content/allatonce.qml @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** 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 { + color: "white" + width: 640 + height: 480 + ParticleSystem { + id: sys + } + + ImageParticle { + // ![0] + sprites: [ + Sprite { + name: "bear" + source: "../../images/bear_tiles.png" + frameCount: 13 + frameDuration: 120 + } + ] + colorVariation: 0.5 + rotationVelocityVariation: 360 + colorTable: "../../images/colortable.png" + // ![0] + system: sys + } + + Friction { + factor: 0.1 + system: sys + } + + Emitter { + system: sys + anchors.centerIn: parent + id: particles + emitRate: 200 + lifeSpan: 6000 + velocity: AngleDirection {angleVariation: 360; magnitude: 80; magnitudeVariation: 40} + size: 60 + endSize: 120 + } + + Text { + x: 16 + y: 16 + text: "QML..." + style: Text.Outline; styleColor: "#AAAAAA" + font.pixelSize: 32 + } + Text { + anchors.bottom: parent.bottom + anchors.right: parent.right + anchors.margins: 16 + text: "... can you be trusted with the power?" + style: Text.Outline; styleColor: "#AAAAAA" + font.pixelSize: width > 400 ? 32 : 16 + } +} diff --git a/examples/quick/particles/imageparticle/content/colored.qml b/examples/quick/particles/imageparticle/content/colored.qml new file mode 100644 index 0000000000..9d72ca7412 --- /dev/null +++ b/examples/quick/particles/imageparticle/content/colored.qml @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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: ["stars"] + anchors.fill: parent + source: "../../images/star.png" + } + Emitter { + group: "stars" + emitRate: 800 + lifeSpan: 2400 + size: 24 + sizeVariation: 8 + anchors.fill: parent + } + + // ![0] + ImageParticle { + anchors.fill: parent + source: "../../images/star.png" + alpha: 0 + alphaVariation: 0.2 + colorVariation: 1.0 + } + // ![0] + + Emitter { + anchors.centerIn: parent + emitRate: 400 + lifeSpan: 2400 + size: 48 + sizeVariation: 8 + velocity: AngleDirection {angleVariation: 180; magnitude: 60} + } + + Turbulence { + anchors.fill: parent + strength: 2 + } + } +} diff --git a/examples/quick/particles/imageparticle/content/colortable.qml b/examples/quick/particles/imageparticle/content/colortable.qml new file mode 100644 index 0000000000..32fc30aa8d --- /dev/null +++ b/examples/quick/particles/imageparticle/content/colortable.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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.Particles 2.0 +import QtQuick 2.0 + +Rectangle { + id: root + width: 360 + height: 540 + color: "black" + + ParticleSystem { id: particles } + + ImageParticle { + system: particles + colorVariation: 0.5 + alpha: 0 + + //! [0] + source: "../../images/particle.png" + colorTable: "../../images/colortable.png" + sizeTable: "../../images/colortable.png" + //! [0] + } + + Emitter { + system: particles + emitRate: 500 + lifeSpan: 2000 + + y: root.height / 2 + Math.sin(t * 2) * root.height * 0.3 + x: root.width / 2 + Math.cos(t) * root.width * 0.3 + property real t; + + NumberAnimation on t { + from: 0; to: Math.PI * 2; duration: 10000; loops: Animation.Infinite + } + + velocityFromMovement: 20 + + velocity: PointDirection { xVariation: 5; yVariation: 5;} + acceleration: PointDirection { xVariation: 5; yVariation: 5;} + + size: 16 + //endSize: 8 + //sizeVariation: 8 + } +} diff --git a/examples/quick/particles/imageparticle/content/deformation.qml b/examples/quick/particles/imageparticle/content/deformation.qml new file mode 100644 index 0000000000..a7a3415165 --- /dev/null +++ b/examples/quick/particles/imageparticle/content/deformation.qml @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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 { + color: "goldenrod" + width: 400 + height: 400 + ParticleSystem {id:sys} + + //! [spin] + ImageParticle { + system: sys + groups: ["goingLeft", "goingRight"] + source: "../../images/starfish_4.png" + rotation: 90 + rotationVelocity: 90 + autoRotation: true + } + //! [spin] + //! [deform] + ImageParticle { + system: sys + groups: ["goingDown"] + source: "../../images/starfish_0.png" + rotation: 180 + yVector: PointDirection { y: 0.5; yVariation: 0.25; xVariation: 0.25; } + } + //! [deform] + + Timer { + running: true + repeat: false + interval: 100 + onTriggered: emitA.enabled = true; + } + Timer { + running: true + repeat: false + interval: 4200 + onTriggered: emitB.enabled = true; + } + Timer { + running: true + repeat: false + interval: 8400 + onTriggered: emitC.enabled = true; + } + + Emitter { + id: emitA + x: 0 + y: 120 + system: sys + enabled: false + group: "goingRight" + velocity: PointDirection { x: 100 } + lifeSpan: 4000 + emitRate: 1 + size: 128 + } + Emitter { + id: emitB + x: 400 + y: 240 + system: sys + enabled: false + group: "goingLeft" + velocity: PointDirection { x: -100 } + lifeSpan: 4000 + emitRate: 1 + size: 128 + } + Emitter { + id: emitC + x: 0 + y: 360 + system: sys + enabled: false + group: "goingDown" + velocity: PointDirection { x: 100 } + lifeSpan: 4000 + emitRate: 1 + size: 128 + } +} diff --git a/examples/quick/particles/imageparticle/content/rotation.qml b/examples/quick/particles/imageparticle/content/rotation.qml new file mode 100644 index 0000000000..2b1d828c7d --- /dev/null +++ b/examples/quick/particles/imageparticle/content/rotation.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 { + color: "goldenrod" + width: 2000 + height: 2000 + ParticleSystem {id: sys} + ImageParticle { + id: up + system: sys + source: "../../images/starfish_2.png" + autoRotation: true //leaving these two settings at default allows you to test going up performance levels + rotation: -90 + } + + Emitter { + anchors.centerIn: parent + system: sys + emitRate: 10 + size: 200 + lifeSpan: 10000 + velocity: AngleDirection {angleVariation: 360; magnitudeVariation: 100;} + } + + MouseArea { + anchors.fill: parent + onClicked: { + up.autoRotation = !up.autoRotation + up.rotation = up.autoRotation ? -90 : 0 + } + } +} diff --git a/examples/quick/particles/imageparticle/content/sharing.qml b/examples/quick/particles/imageparticle/content/sharing.qml new file mode 100644 index 0000000000..433ffe9524 --- /dev/null +++ b/examples/quick/particles/imageparticle/content/sharing.qml @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// This example shows how to create your own highlight delegate for a ListView +// that uses a SpringAnimation to provide custom movement when the +// highlight bar is moved between items. + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + property real delegateHeight: 65 + width: 200; height: 300 + gradient: Gradient { + GradientStop { position: 0.0; color: "#EEEEFF" } + GradientStop { position: 1.0; color: "lightblue" } + } + + // Define a delegate component. A component will be + // instantiated for each visible item in the list. + Component { + id: petDelegate + Item { + id: wrapper + width: 200; height: delegateHeight + z: 10 + Column { + Text {color: "white"; text: name; font.pixelSize: 18 } + Text {color: "white"; text: 'Type: ' + type; font.pixelSize: 14 } + Text {color: "white"; text: 'Age: ' + age; font.pixelSize: 14 } + } + MouseArea { anchors.fill: parent; onClicked: listView.currentIndex = index; } + // indent the item if it is the current item + states: State { + name: "Current" + when: wrapper.ListView.isCurrentItem + PropertyChanges { target: wrapper; x: 20 } + } + transitions: Transition { + NumberAnimation { properties: "x"; duration: 200 } + } + } + } + + // Define a highlight with customized movement between items. + Component { + id: highlightBar + Rectangle { + z: 0 + width: 200; height: delegateHeight + gradient: Gradient { + GradientStop { position: 0.0; color: "#99FF99" } + GradientStop { position: 1.0; color: "#88FF88" } + } + y: listView.currentItem.y; + Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } } + //! [1] + ImageParticle { + anchors.fill: parent + system: particles + source: "../../images/flower.png" + color: "red" + clip: true + alpha: 1.0 + } + //! [1] + } + } + + ListView { + id: listView + width: 200; height: parent.height + + model: petsModel + delegate: petDelegate + focus: true + + // Set the highlight delegate. Note we must also set highlightFollowsCurrentItem + // to false so the highlight delegate can control how the highlight is moved. + highlight: highlightBar + highlightFollowsCurrentItem: false + + ParticleSystem { id: particles } + Emitter { + system: particles + anchors.fill: parent + emitRate: 0 + lifeSpan: 10000 + size: 24 + sizeVariation: 8 + velocity: AngleDirection { angleVariation: 360; magnitude: 3 } + maximumEmitted: 10 + startTime: 5000 + Timer { running: true; interval: 10; onTriggered: parent.emitRate = 1; } + } + + //! [0] + ImageParticle { + anchors.fill: parent + system: particles + source: "../../images/flower.png" + alpha: 0.1 + color: "white" + rotationVariation: 180 + z: -1 + } + //! [0] + } + + ListModel { + id: petsModel + ListElement { + name: "Polly" + type: "Parrot" + age: 12 + size: "Small" + } + ListElement { + name: "Penny" + type: "Turtle" + age: 4 + size: "Small" + } + ListElement { + name: "Warren" + type: "Rabbit" + age: 2 + size: "Small" + } + ListElement { + name: "Spot" + type: "Dog" + age: 9 + size: "Medium" + } + ListElement { + name: "Schrödinger" + type: "Cat" + age: 2 + size: "Medium" + } + ListElement { + name: "Joey" + type: "Kangaroo" + age: 1 + size: "Medium" + } + ListElement { + name: "Kimba" + type: "Bunny" + age: 65 + size: "Large" + } + ListElement { + name: "Rover" + type: "Dog" + age: 5 + size: "Large" + } + ListElement { + name: "Tiny" + type: "Elephant" + age: 15 + size: "Large" + } + } + +} diff --git a/examples/quick/particles/imageparticle/content/sprites.qml b/examples/quick/particles/imageparticle/content/sprites.qml new file mode 100644 index 0000000000..0f74ab60f2 --- /dev/null +++ b/examples/quick/particles/imageparticle/content/sprites.qml @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** 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 { + color: "lightsteelblue" + width: 800 + height: 800 + id: root + + SpriteSequence { + sprites: Sprite { + name: "bear" + source: "../../images/bear_tiles.png" + frameCount: 13 + frameDuration: 120 + } + width: 250 + height: 250 + x: 20 + anchors.bottom: parent.bottom + anchors.bottomMargin: 20 + z:4 + } + + ParticleSystem { id: sys } + + ImageParticle { + anchors.fill: parent + id: particles + system: sys + sprites: [Sprite { + name: "happy" + source: "../../images/starfish_1.png" + frameCount: 1 + frameDuration: 260 + to: {"happy": 1, "silly": 1, "angry": 1} + }, Sprite { + name: "angry" + source: "../../images/starfish_0.png" + frameCount: 1 + frameDuration: 260 + to: {"happy": 1, "silly": 1, "angry": 1} + }, Sprite { + name: "silly" + source: "../../images/starfish_2.png" + frameCount: 1 + frameDuration: 260 + to: {"happy": 1, "silly": 1, "noticedbear": 0} + }, Sprite { + name: "noticedbear" + source: "../../images/starfish_3.png" + frameCount: 1 + frameDuration: 2600 + }] + } + + Emitter { + system: sys + emitRate: 2 + lifeSpan: 10000 + velocity: AngleDirection {angle: 90; magnitude: 60; angleVariation: 5} + acceleration: PointDirection { y: 10 } + size: 160 + sizeVariation: 40 + width: parent.width + height: 100 + } + + SpriteGoal { + system: sys + width: root.width; + height: root.height/2; + y: root.height/2; + goalState:"noticedbear" + } +} diff --git a/examples/quick/particles/imageparticle/doc/images/qml-imageparticle-example.png b/examples/quick/particles/imageparticle/doc/images/qml-imageparticle-example.png Binary files differnew file mode 100644 index 0000000000..9e44abe4fb --- /dev/null +++ b/examples/quick/particles/imageparticle/doc/images/qml-imageparticle-example.png diff --git a/examples/quick/particles/imageparticle/doc/src/imageparticle.qdoc b/examples/quick/particles/imageparticle/doc/src/imageparticle.qdoc new file mode 100644 index 0000000000..62c1a06839 --- /dev/null +++ b/examples/quick/particles/imageparticle/doc/src/imageparticle.qdoc @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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/imageparticle + \brief This is a collection of examples using Affectors in the QML particle system. + \image qml-imageparticle-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. + + All at once shows off several of the features of ImageParticle at the same time. + \snippet particles/imageparticle/content/allatonce.qml 0 + + Colored shows a simple ImageParticle with some color variation. + \snippet particles/imageparticle/content/colored.qml 0 + + Color Table sets the color over life on the particles to provide a fixed rainbow effect. + \snippet particles/imageparticle/content/colortable.qml 0 + + Deformation spins and squishes a starfish particle. + \snippet particles/imageparticle/content/deformation.qml spin + \snippet particles/imageparticle/content/deformation.qml deform + + Rotation demonstrates the autoRotate property, so that particles rotate in the direction that they travel. + + Sharing demonstrates what happens when multiple ImageParticles try to render the same particle. + The following ImageParticle renders the particles inside the ListView: + \snippet particles/imageparticle/content/sharing.qml 0 + The following ImageParticle is placed inside the list highlight, and renders the particles above the other ImageParticle. + \snippet particles/imageparticle/content/sharing.qml 1 + Note that because it sets the color and alpha in this ImageParticle, it renders the particles in a different color. + Since it doesn't specify anything about the rotation, it shares the rotation with the other ImageParticle so that the flowers are rotated the same way in both. + Note that you can undo rotation in another ImageParticle, you just need to explicity set rotationVariation to 0. + + Sprites demonstrates using an image particle to render animated sprites instead of static images for each particle. +*/ diff --git a/examples/quick/particles/imageparticle/imageparticle.pro b/examples/quick/particles/imageparticle/imageparticle.pro new file mode 100644 index 0000000000..94ed5fc7c3 --- /dev/null +++ b/examples/quick/particles/imageparticle/imageparticle.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/imageparticle +qml.files = imageparticle.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/imageparticle +INSTALLS += target qml diff --git a/examples/quick/particles/imageparticle/imageparticle.qml b/examples/quick/particles/imageparticle/imageparticle.qml new file mode 100644 index 0000000000..5f7ca38b13 --- /dev/null +++ b/examples/quick/particles/imageparticle/imageparticle.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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("All at once", "Uses all ImageParticle features", Qt.resolvedUrl("content/allatonce.qml")); + addExample("Colored", "Colorized image particles", Qt.resolvedUrl("content/colored.qml")); + addExample("Color Table", "Color-over-life rainbow particles", Qt.resolvedUrl("content/colortable.qml")); + addExample("Deformation", "Deformed particles", Qt.resolvedUrl("content/deformation.qml")); + addExample("Rotation", "Rotated particles", Qt.resolvedUrl("content/rotation.qml")); + addExample("Sharing", "Multiple ImageParticles on the same particles", Qt.resolvedUrl("content/sharing.qml")); + addExample("Sprites", "Particles rendered with sprites", Qt.resolvedUrl("content/sprites.qml")); + } + } +} diff --git a/examples/quick/particles/imageparticle/imageparticle.qmlproject b/examples/quick/particles/imageparticle/imageparticle.qmlproject new file mode 100644 index 0000000000..902cf6519a --- /dev/null +++ b/examples/quick/particles/imageparticle/imageparticle.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.1 + +Project { + mainFile: "imageparticle.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +} diff --git a/examples/quick/particles/imageparticle/main.cpp b/examples/quick/particles/imageparticle/main.cpp new file mode 100644 index 0000000000..081aec03d7 --- /dev/null +++ b/examples/quick/particles/imageparticle/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(imageparticle) diff --git a/examples/quick/particles/images/_explo.png b/examples/quick/particles/images/_explo.png Binary files differnew file mode 100644 index 0000000000..4297245d49 --- /dev/null +++ b/examples/quick/particles/images/_explo.png diff --git a/examples/quick/particles/images/backgroundLeaves.jpg b/examples/quick/particles/images/backgroundLeaves.jpg Binary files differnew file mode 100755 index 0000000000..08be16751d --- /dev/null +++ b/examples/quick/particles/images/backgroundLeaves.jpg diff --git a/examples/quick/particles/images/bear_tiles.png b/examples/quick/particles/images/bear_tiles.png Binary files differnew file mode 100644 index 0000000000..6bbb2a9b6d --- /dev/null +++ b/examples/quick/particles/images/bear_tiles.png diff --git a/examples/quick/particles/images/candle.png b/examples/quick/particles/images/candle.png Binary files differnew file mode 100644 index 0000000000..8fa3193719 --- /dev/null +++ b/examples/quick/particles/images/candle.png diff --git a/examples/quick/particles/images/colortable.png b/examples/quick/particles/images/colortable.png Binary files differnew file mode 100644 index 0000000000..a62ceeb4a0 --- /dev/null +++ b/examples/quick/particles/images/colortable.png diff --git a/examples/quick/particles/images/finalfrontier.png b/examples/quick/particles/images/finalfrontier.png Binary files differnew file mode 100644 index 0000000000..2ba1815230 --- /dev/null +++ b/examples/quick/particles/images/finalfrontier.png diff --git a/examples/quick/particles/images/flower.png b/examples/quick/particles/images/flower.png Binary files differnew file mode 100644 index 0000000000..b5c606210e --- /dev/null +++ b/examples/quick/particles/images/flower.png diff --git a/examples/quick/particles/images/matchmask.png b/examples/quick/particles/images/matchmask.png Binary files differnew file mode 100644 index 0000000000..e575875c55 --- /dev/null +++ b/examples/quick/particles/images/matchmask.png diff --git a/examples/quick/particles/images/meteor.png b/examples/quick/particles/images/meteor.png Binary files differnew file mode 100644 index 0000000000..e8c368aea7 --- /dev/null +++ b/examples/quick/particles/images/meteor.png diff --git a/examples/quick/particles/images/meteor_explo.png b/examples/quick/particles/images/meteor_explo.png Binary files differnew file mode 100644 index 0000000000..e659bfe2cf --- /dev/null +++ b/examples/quick/particles/images/meteor_explo.png diff --git a/examples/quick/particles/images/meteors.png b/examples/quick/particles/images/meteors.png Binary files differnew file mode 100644 index 0000000000..bada8a1407 --- /dev/null +++ b/examples/quick/particles/images/meteors.png diff --git a/examples/quick/particles/images/nullRock.png b/examples/quick/particles/images/nullRock.png Binary files differnew file mode 100644 index 0000000000..4076327a1a --- /dev/null +++ b/examples/quick/particles/images/nullRock.png diff --git a/examples/quick/particles/images/particle.png b/examples/quick/particles/images/particle.png Binary files differnew file mode 100644 index 0000000000..5c83896d22 --- /dev/null +++ b/examples/quick/particles/images/particle.png diff --git a/examples/quick/particles/images/particle2.png b/examples/quick/particles/images/particle2.png Binary files differnew file mode 100644 index 0000000000..36349c6c6e --- /dev/null +++ b/examples/quick/particles/images/particle2.png diff --git a/examples/quick/particles/images/particle3.png b/examples/quick/particles/images/particle3.png Binary files differnew file mode 100644 index 0000000000..905d8f37b8 --- /dev/null +++ b/examples/quick/particles/images/particle3.png diff --git a/examples/quick/particles/images/particle4.png b/examples/quick/particles/images/particle4.png Binary files differnew file mode 100644 index 0000000000..bc95b703c1 --- /dev/null +++ b/examples/quick/particles/images/particle4.png diff --git a/examples/quick/particles/images/particleA.png b/examples/quick/particles/images/particleA.png Binary files differnew file mode 100644 index 0000000000..c63acdee1f --- /dev/null +++ b/examples/quick/particles/images/particleA.png diff --git a/examples/quick/particles/images/portal_bg.png b/examples/quick/particles/images/portal_bg.png Binary files differnew file mode 100644 index 0000000000..3c59eeabb9 --- /dev/null +++ b/examples/quick/particles/images/portal_bg.png diff --git a/examples/quick/particles/images/realLeaf1.png b/examples/quick/particles/images/realLeaf1.png Binary files differnew file mode 100644 index 0000000000..6cabf29efd --- /dev/null +++ b/examples/quick/particles/images/realLeaf1.png diff --git a/examples/quick/particles/images/realLeaf2.png b/examples/quick/particles/images/realLeaf2.png Binary files differnew file mode 100644 index 0000000000..bfeca861d5 --- /dev/null +++ b/examples/quick/particles/images/realLeaf2.png diff --git a/examples/quick/particles/images/realLeaf3.png b/examples/quick/particles/images/realLeaf3.png Binary files differnew file mode 100644 index 0000000000..b1071e862b --- /dev/null +++ b/examples/quick/particles/images/realLeaf3.png diff --git a/examples/quick/particles/images/realLeaf4.png b/examples/quick/particles/images/realLeaf4.png Binary files differnew file mode 100644 index 0000000000..d61d53d10e --- /dev/null +++ b/examples/quick/particles/images/realLeaf4.png diff --git a/examples/quick/particles/images/rocket.png b/examples/quick/particles/images/rocket.png Binary files differnew file mode 100644 index 0000000000..a171610b03 --- /dev/null +++ b/examples/quick/particles/images/rocket.png diff --git a/examples/quick/particles/images/rocket2.png b/examples/quick/particles/images/rocket2.png Binary files differnew file mode 100644 index 0000000000..7110f8fdc6 --- /dev/null +++ b/examples/quick/particles/images/rocket2.png diff --git a/examples/quick/particles/images/sizeInOut.png b/examples/quick/particles/images/sizeInOut.png Binary files differnew file mode 100644 index 0000000000..0a306ea21a --- /dev/null +++ b/examples/quick/particles/images/sizeInOut.png diff --git a/examples/quick/particles/images/snowflake.png b/examples/quick/particles/images/snowflake.png Binary files differnew file mode 100644 index 0000000000..490887a82f --- /dev/null +++ b/examples/quick/particles/images/snowflake.png diff --git a/examples/quick/particles/images/sparkleSize.png b/examples/quick/particles/images/sparkleSize.png Binary files differnew file mode 100644 index 0000000000..752056541b --- /dev/null +++ b/examples/quick/particles/images/sparkleSize.png diff --git a/examples/quick/particles/images/star.png b/examples/quick/particles/images/star.png Binary files differnew file mode 100644 index 0000000000..0d592cfa87 --- /dev/null +++ b/examples/quick/particles/images/star.png diff --git a/examples/quick/particles/images/starfish_0.png b/examples/quick/particles/images/starfish_0.png Binary files differnew file mode 100644 index 0000000000..8747f0236e --- /dev/null +++ b/examples/quick/particles/images/starfish_0.png diff --git a/examples/quick/particles/images/starfish_1.png b/examples/quick/particles/images/starfish_1.png Binary files differnew file mode 100644 index 0000000000..1f3f159d5e --- /dev/null +++ b/examples/quick/particles/images/starfish_1.png diff --git a/examples/quick/particles/images/starfish_2.png b/examples/quick/particles/images/starfish_2.png Binary files differnew file mode 100644 index 0000000000..c6c7e5a676 --- /dev/null +++ b/examples/quick/particles/images/starfish_2.png diff --git a/examples/quick/particles/images/starfish_3.png b/examples/quick/particles/images/starfish_3.png Binary files differnew file mode 100644 index 0000000000..307a89f815 --- /dev/null +++ b/examples/quick/particles/images/starfish_3.png diff --git a/examples/quick/particles/images/starfish_4.png b/examples/quick/particles/images/starfish_4.png Binary files differnew file mode 100644 index 0000000000..d61c26545a --- /dev/null +++ b/examples/quick/particles/images/starfish_4.png diff --git a/examples/quick/particles/images/starfish_mask.png b/examples/quick/particles/images/starfish_mask.png Binary files differnew file mode 100644 index 0000000000..2ef74f902b --- /dev/null +++ b/examples/quick/particles/images/starfish_mask.png diff --git a/examples/quick/particles/itemparticle/content/Delegate.qml b/examples/quick/particles/itemparticle/content/Delegate.qml new file mode 100644 index 0000000000..d0292f2467 --- /dev/null +++ b/examples/quick/particles/itemparticle/content/Delegate.qml @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 + +//![0] +Package { + Text { id: listDelegate; width: 200; height: 25; text: 'Empty'; Package.name: 'list' } + Text { id: gridDelegate; width: 100; height: 50; text: 'Empty'; Package.name: 'grid' } + + Rectangle { + id: wrapper + width: 200; height: 25 + color: 'lightsteelblue' + + Text { text: display; anchors.centerIn: parent } + MouseArea { + anchors.fill: parent + onClicked: { + if (wrapper.state == 'inList') + wrapper.state = 'inGrid'; + else + wrapper.state = 'inList'; + } + } + + state: 'inList' + states: [ + State { + name: 'inList' + ParentChange { target: wrapper; parent: listDelegate } + }, + State { + name: 'inGrid' + ParentChange { + target: wrapper; parent: gridDelegate + x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height + } + } + ] + + transitions: [ + Transition { + ParentAnimation { + NumberAnimation { properties: 'x,y,width,height'; duration: 300 } + } + } + ] + } +} +//![0] diff --git a/examples/quick/particles/itemparticle/content/Delegate2.qml b/examples/quick/particles/itemparticle/content/Delegate2.qml new file mode 100644 index 0000000000..710c168612 --- /dev/null +++ b/examples/quick/particles/itemparticle/content/Delegate2.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 + +//![0] +Package { + Item { id: gridDelegate; width: w; height: h; Package.name: 'grid' } + Item { id: particleDelegate; width: w; height: h; Package.name: 'particles' + + Rectangle { + id: wrapper + width: w; height: h; + color: col + rotation: Math.random()*360 + Behavior on rotation {RotationAnimation {}} + + states: State { + name: "gridded" + when: root.inGrid + PropertyChanges { + target: wrapper + rotation: 0 + } + ParentChange { + target: wrapper + parent: gridDelegate + x:0 + y:0 + } + } + transitions: [ + Transition { + ParentAnimation { + NumberAnimation { properties: 'x,y,width,height'; duration: 300 } + } + } + ] + } + } +} +//![0] diff --git a/examples/quick/particles/itemparticle/content/ExpandingDelegate.qml b/examples/quick/particles/itemparticle/content/ExpandingDelegate.qml new file mode 100644 index 0000000000..ee81873a7e --- /dev/null +++ b/examples/quick/particles/itemparticle/content/ExpandingDelegate.qml @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** 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 "../../../modelviews/listview/content" + +// This example illustrates expanding a list item to show a more detailed view. + + // Delegate for the recipes. This delegate has two modes: + // 1. List mode (default), which just shows the picture and title of the recipe. + // 2. Details mode, which also shows the ingredients and method. + Component { + id: recipeDelegate + + Item { + id: recipe + + // Create a property to contain the visibility of the details. + // We can bind multiple element's opacity to this one property, + // rather than having a "PropertyChanges" line for each element we + // want to fade. + property real detailsOpacity : 0 + + //this bit changed for aesthetics + width: 70 + height: 70 + // A simple rounded rectangle for the background + Rectangle { + id: background + x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2 + color: "ivory" + border.color: "orange" + radius: 5 + antialiasing: true + } + Image { + anchors.fill:parent + anchors.margins: -32 + source: "bubble.png" + } + + + // This mouse region covers the entire delegate. + // When clicked it changes mode to 'Details'. If we are already + // in Details mode, then no change will happen. + MouseArea { + anchors.fill: parent + onClicked: recipe.state = 'Details'; + } + + // Lay out the page: picture, title and ingredients at the top, and method at the + // bottom. Note that elements that should not be visible in the list + // mode have their opacity set to recipe.detailsOpacity. + Row { + id: topLayout + x: 10; y: 10; height: recipeImage.height; width: parent.width + spacing: 10 + + Image { + id: recipeImage + width: 50; height: 50 + source: "../../modelviews/listview/" + picture + } + + Column { + width: background.width - recipeImage.width - 20; height: recipeImage.height + spacing: 5 + + Text { + text: title + font.bold: true; font.pointSize: 16 + } + + Text { + text: "Ingredients" + font.pointSize: 12; font.bold: true + opacity: recipe.detailsOpacity + } + + Text { + text: ingredients + wrapMode: Text.WordWrap + width: parent.width + opacity: recipe.detailsOpacity + } + } + } + + Item { + id: details + x: 10; width: parent.width - 20 + anchors { top: topLayout.bottom; topMargin: 10; bottom: parent.bottom; bottomMargin: 10 } + opacity: recipe.detailsOpacity + + Text { + id: methodTitle + anchors.top: parent.top + text: "Method" + font.pointSize: 12; font.bold: true + } + + Flickable { + id: flick + width: parent.width + anchors { top: methodTitle.bottom; bottom: parent.bottom } + contentHeight: methodText.height + clip: true + + Text { id: methodText; text: method; wrapMode: Text.WordWrap; width: details.width } + } + + Image { + anchors { right: flick.right; top: flick.top } + source: "../../modelviews/listview/" + "content/pics/moreUp.png" + opacity: flick.atYBeginning ? 0 : 1 + } + + Image { + anchors { right: flick.right; bottom: flick.bottom } + source: "../../modelviews/listview/" + "content/pics/moreDown.png" + opacity: flick.atYEnd ? 0 : 1 + } + } + + // A button to close the detailed view, i.e. set the state back to default (''). + TextButton { + y: 10 + anchors { right: background.right; rightMargin: 10 } + opacity: recipe.detailsOpacity + text: "Close" + + onClicked: recipe.state = ''; + } + + states: State { + name: "Details" + + PropertyChanges { target: background; color: "white" } + PropertyChanges { target: recipeImage; width: 130; height: 130 } // Make picture bigger + PropertyChanges { target: recipe; detailsOpacity: 1; x: 0; opacity: 1 } // Make details visible + PropertyChanges { target: recipe; height: root.height; width: root.height; x:0; y:0; z:100} // Fill the entire list area with the detailed view + + // Move the list so that this item is at the top. + //PropertyChanges { target: recipe.ListView.view; explicit: true; contentY: recipe.y } + + // Disallow flicking while we're in detailed view + //PropertyChanges { target: recipe.ListView.view; interactive: false } + } + + transitions: Transition { + //The only strictly necessary particle specific lines + to: "Details" + reversible: true + ScriptAction {script: { + if(state == "Details") + mp.freeze(index); + else + mp.unfreeze(index); + } + } + // Make the state changes smooth + ParallelAnimation { + ColorAnimation { property: "color"; duration: 500 } + NumberAnimation { duration: 300; properties: "detailsOpacity,opacity,x,y,height,width" } + } + } + } + } diff --git a/examples/quick/particles/itemparticle/content/RssModel.qml b/examples/quick/particles/itemparticle/content/RssModel.qml new file mode 100644 index 0000000000..ed209a7ce5 --- /dev/null +++ b/examples/quick/particles/itemparticle/content/RssModel.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** 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.XmlListModel 2.0 + +XmlListModel { + property string tags : "" + + function encodeTags(x) { return encodeURIComponent(x.replace(' ',',')); } + + source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+encodeTags(tags)+"&" : "") + query: "/feed/entry" + namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';" + + XmlRole { name: "title"; query: "title/string()" } + XmlRole { name: "content"; query: "content/string()" } + XmlRole { name: "hq"; query: "link[@rel='enclosure']/@href/string()" } +} diff --git a/examples/quick/particles/itemparticle/content/bubble.png b/examples/quick/particles/itemparticle/content/bubble.png Binary files differnew file mode 100644 index 0000000000..c7f479e9e3 --- /dev/null +++ b/examples/quick/particles/itemparticle/content/bubble.png diff --git a/examples/quick/particles/itemparticle/content/script.js b/examples/quick/particles/itemparticle/content/script.js new file mode 100644 index 0000000000..e8ef93a847 --- /dev/null +++ b/examples/quick/particles/itemparticle/content/script.js @@ -0,0 +1,27 @@ +.pragma library + +function getWidth(string) { + return (string.match(/width=\"([0-9]+)\"/))[1] +} + +function getHeight(string) { + return (string.match(/height=\"([0-9]+)\"/))[1] +} + +function getImagePath(string) { + var pattern = /src=\"http:\/\/(\S+)\"/ + return (string.match(pattern))[1] +} + +function calculateScale(width, height, cellSize) { + var widthScale = (cellSize * 1.0) / width + var heightScale = (cellSize * 1.0) / height + var scale = 0 + + if (widthScale <= heightScale) { + scale = widthScale; + } else if (heightScale < widthScale) { + scale = heightScale; + } + return scale; +} diff --git a/examples/quick/particles/itemparticle/delegates.qml b/examples/quick/particles/itemparticle/delegates.qml new file mode 100644 index 0000000000..fa076a2657 --- /dev/null +++ b/examples/quick/particles/itemparticle/delegates.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** 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" + + function newPithySaying() { + switch (Math.floor(Math.random()*16)) { + case 0: return "Hello World"; + case 1: return "G'day Mate"; + case 2: return "Code Less"; + case 3: return "Create More"; + case 4: return "Deploy Everywhere"; + case 5: return "Qt Meta-object Language"; + case 6: return "Qt Magic Language"; + case 7: return "Fluid UIs"; + case 8: return "Touchable"; + case 9: return "How's it going?"; + case 10: return "Do you like text?"; + case 11: return "Enjoy!"; + case 12: return "ERROR: Out of pith"; + case 13: return "Punctuation Failure"; + case 14: return "I can go faster"; + case 15: return "I can go slower"; + default: return "OMGWTFBBQ"; + } + } + + ParticleSystem { + anchors.fill: parent + id: syssy + Emitter { + anchors.centerIn: parent + emitRate: 1 + lifeSpan: 4800 + lifeSpanVariation: 1600 + velocity: AngleDirection {angleVariation: 360; magnitude: 40; magnitudeVariation: 20} + } + ItemParticle { + delegate: Text { + text: root.newPithySaying(); + color: "white" + font.pixelSize: 18 + font.bold: true + } + } + } +} diff --git a/examples/quick/particles/itemparticle/particleview.qml b/examples/quick/particles/itemparticle/particleview.qml new file mode 100644 index 0000000000..2501e6a713 --- /dev/null +++ b/examples/quick/particles/itemparticle/particleview.qml @@ -0,0 +1,276 @@ +/**************************************************************************** +** +** 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 "content/script.js" as Script +import "content" + +Item { + id: root + width: 640 + height: 480 + Rectangle { + anchors.fill: parent + color: "black" + z: -1 + } + Item { + id: loading + Behavior on opacity {NumberAnimation {}} + anchors.fill: parent + Text { + anchors.centerIn: parent + text: "Loading" + color: "white" + } + } + ParticleSystem { + id: sys; + running: true + } + Emitter { + id: emitter + system: sys + height: parent.height - 132/2 + x: -132/2 + y: 132/2 + velocity: PointDirection { x: 32; xVariation: 8 } + emitRate: 0.5 + lifeSpan: Emitter.InfiniteLife + group: "photos" + } + Age { + system: sys + x: parent.width + 132/2 + height: parent.height + width: 1000 + } + ImageParticle { + system: sys + groups: ["fireworks"] + source: "../trails/../images/star.png" + color: "lightsteelblue" + alpha: 0 + colorVariation: 0 + z: 1000 + } + ItemParticle { + id: mp + z: 0 + system: sys + fade: false + groups: ["photos"] + } + Component { + id: alertDelegate + Rectangle { + width: 132 + height: 132 + NumberAnimation on scale { + running: true + loops: 1 + from: 0.2 + to: 1 + } + Image { + source: "../asteroid/../images/rocket.png" + anchors.centerIn: parent + } + Text { + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + text: "A new ship has arrived!" + } + } + } + property Item alertItem; + function alert() { + //resetter.active = false + force.active = true; + alertItem = alertDelegate.createObject(root); + alertItem.x = root.width/2 - alertItem.width/2 + alertItem.y = root.height/2 - alertItem.height/2 + spawnFireworks.pulse(200); + stopAlert.start(); + } + focus: true + Keys.onSpacePressed: alert(); + Timer { + id: stopAlert + running: false + repeat: false + interval: 800 + onTriggered: { + force.active = false + //resetter.active = true; + mp.take(alertItem, true); + centerEmitter.burst(1); + } + } + Attractor { + id: force + system: sys + pointX: root.width/2 + pointY: root.height/2 + strength: -10000 + enabled: false + anchors.centerIn: parent + width: parent.width/2 + height: parent.height/2 + groups:["photos"] + affectedParameter: Attractor.Position + } + Emitter { + id: centerEmitter + velocity: PointDirection { x: 32; xVariation: 8;} + emitRate: 0.5 + lifeSpan: 12000 //TODO: A -1 or something which does 'infinite'? (but need disable fade first) + maximumEmitted: 20 + group: "photos" + system: sys + anchors.centerIn: parent + enabled: false + + //TODO: Zoom in effect + } + Emitter { + id: spawnFireworks + group: "fireworks" + system: sys + maximumEmitted: 400 + emitRate: 400 + lifeSpan: 2800 + x: parent.width/2 + y: parent.height/2 - 64 + width: 8 + height: 8 + enabled: false + size: 32 + endSize: 8 + velocity: AngleDirection { magnitude: 160; magnitudeVariation: 120; angleVariation: 90; angle: 270 } + acceleration: PointDirection { y: 160 } + } + Item { x: -1000; y: -1000 //offscreen + Repeater {//Load them here, add to system on completed + model: theModel + delegate: theDelegate + } + } + RssModel {id: theModel; tags:"particle,particles"} + Component { + id: theDelegate + Rectangle { + id: container + border.width: 2 + antialiasing: true + property real myRand: Math.random();//'depth' + z: Math.floor(myRand * 100) + scale: (myRand + 1.0)/2; + //TODO: Darken based on 'depth' + width: 132 + height: 132 + //ItemParticle.onAttached: console.log("I'm in" + x + "," + y + ":" + opacity); + ItemParticle.onDetached: mp.take(container);//respawns + function manage() + { + if (state == "selected") { + console.log("Taking " + index); + mp.freeze(container); + } else { + console.log("Returning " +index); + mp.unfreeze(container); + } + } + Image { + id: img + anchors.centerIn: parent + antialiasing: true; + source: "http://" + Script.getImagePath(content); cache: true + fillMode: Image.PreserveAspectFit; + width: parent.width-4; height: parent.height-4 + onStatusChanged: if (img.status == Image.Ready) { + loading.opacity = 0; + mp.take(container); + } + } + Text { + anchors.bottom: parent.bottom + width: parent.width + horizontalAlignment: Text.AlignHCenter + elide: Text.ElideRight + text: title + color: "black" + } + MouseArea { + anchors.fill: parent + onClicked: container.state == "selected" ? container.state = "" : container.state = "selected" + } + states: State { + name: "selected" + ParentChange { + target: container + parent: root + x: 0 + y: 0 + } + PropertyChanges { + target: container + width: root.width + height: root.height + z: 101 + opacity: 1 + rotation: 0 + } + } + transitions: Transition { + to: "selected" + reversible: true + SequentialAnimation { + ScriptAction {script: container.manage();} + ParallelAnimation { + ParentAnimation {NumberAnimation { properties: "x,y" }}//Doesn't work, particles takes control of x,y instantly + NumberAnimation { properties: "width, height, z, rotation" } + } + } + } + } + } +} diff --git a/examples/quick/particles/particles.pro b/examples/quick/particles/particles.pro new file mode 100644 index 0000000000..9200113be8 --- /dev/null +++ b/examples/quick/particles/particles.pro @@ -0,0 +1,14 @@ +TEMPLATE = subdirs +SUBDIRS += affectors \ + customparticle \ + emitters \ + imageparticle \ + system + +EXAMPLE_FILES = \ + itemparticle + +#Install shared images too +qml.files = images +qml.path = $$[QT_INSTALL_EXAMPLES]/quick/particles +INSTALLS += qml diff --git a/examples/quick/particles/system/content/dynamiccomparison.qml b/examples/quick/particles/system/content/dynamiccomparison.qml new file mode 100644 index 0000000000..82591a6f82 --- /dev/null +++ b/examples/quick/particles/system/content/dynamiccomparison.qml @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** 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 + color: "black" + width: 640 + height: 480 + ParticleSystem { + id: sys + } + + ImageParticle { + system: sys + source: "../../images/particle.png" + color: "white" + colorVariation: 1.0 + alpha: 0.1 + entryEffect: ImageParticle.None + } + + Emitter { + id: emitter + system: sys + width: parent.width/2 + velocity: PointDirection {y: 72; yVariation: 24} + lifeSpan: 10000 + emitRate: 1000 + enabled: false + size: 32 + } + + //! [fake] + Item { + id: fakeEmitter + function burst(number) { + while (number > 0) { + var item = fakeParticle.createObject(root); + item.lifeSpan = Math.random() * 5000 + 5000; + item.x = Math.random() * (root.width/2) + (root.width/2); + item.y = 0; + number--; + } + } + + Component { + id: fakeParticle + Image { + id: container + property int lifeSpan: 10000 + width: 32 + height: 32 + source: "../../images/particle.png" + y: 0 + PropertyAnimation on y {from: -16; to: root.height-16; duration: container.lifeSpan; running: true} + SequentialAnimation on opacity { + running: true + NumberAnimation { from:0; to: 1; duration: 500} + PauseAnimation { duration: container.lifeSpan - 1000} + NumberAnimation { from:1; to: 0; duration: 500} + ScriptAction { script: container.destroy(); } + } + } + } + } + //! [fake] + + //Hooked to a timer, but click for extra bursts that really stress performance + Timer { + interval: 10000 + triggeredOnStart: true + repeat: true + running: true + onTriggered: { + emitter.burst(1000); + fakeEmitter.burst(1000); + } + } + Text { + anchors.left: parent.left + anchors.bottom: parent.bottom + text: "1000 particles" + color: "white" + MouseArea { + anchors.fill: parent + onClicked: emitter.burst(1000); + } + } + Text { + anchors.right: parent.right + anchors.bottom: parent.bottom + text: "1000 items" + color: "white" + MouseArea { + anchors.fill: parent + onClicked: fakeEmitter.burst(1000); + } + } +} diff --git a/examples/quick/particles/system/content/dynamicemitters.qml b/examples/quick/particles/system/content/dynamicemitters.qml new file mode 100644 index 0000000000..bd4bcad397 --- /dev/null +++ b/examples/quick/particles/system/content/dynamicemitters.qml @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** 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 + color: "black" + width: 640 + height: 480 + ParticleSystem { + id: sys + } + ImageParticle { + system: sys + source: "../../images/particle.png" + color: "white" + colorVariation: 1.0 + alpha: 0.1 + } + + Component { + id: emitterComp + Emitter { + id: container + Emitter { + id: emitMore + system: sys + emitRate: 128 + lifeSpan: 600 + size: 16 + endSize: 8 + velocity: AngleDirection {angleVariation:360; magnitude: 60} + } + + property int life: 2600 + property real targetX: 0 + property real targetY: 0 + function go() { + xAnim.start(); + yAnim.start(); + container.enabled = true + } + system: sys + emitRate: 32 + lifeSpan: 600 + size: 24 + endSize: 8 + NumberAnimation on x { + id: xAnim; + to: targetX + duration: life + running: false + } + NumberAnimation on y { + id: yAnim; + to: targetY + duration: life + running: false + } + Timer { + interval: life + running: true + onTriggered: container.destroy(); + } + } + } + + function customEmit(x,y) { + //! [0] + for (var i=0; i<8; i++) { + var obj = emitterComp.createObject(root); + obj.x = x + obj.y = y + obj.targetX = Math.random() * 240 - 120 + obj.x + obj.targetY = Math.random() * 240 - 120 + obj.y + obj.life = Math.round(Math.random() * 2400) + 200 + obj.emitRate = Math.round(Math.random() * 32) + 32 + obj.go(); + } + //! [0] + } + + Timer { + interval: 10000 + triggeredOnStart: true + running: true + repeat: true + onTriggered: customEmit(Math.random() * 320, Math.random() * 480) + } + MouseArea { + anchors.fill: parent + onClicked: customEmit(mouse.x, mouse.y); + } + + Text { + anchors.horizontalCenter: parent.horizontalCenter + text: "Click Somewhere" + color: "white" + font.pixelSize: 24 + } +} diff --git a/examples/quick/particles/system/content/multiplepainters.qml b/examples/quick/particles/system/content/multiplepainters.qml new file mode 100644 index 0000000000..174f527f1f --- /dev/null +++ b/examples/quick/particles/system/content/multiplepainters.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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: "darkblue" + property bool cloneMode: false + ParticleSystem { + id: sys + } + MouseArea { + anchors.fill: parent + onClicked: cloneMode = !cloneMode; + } + Text { + anchors.horizontalCenter: parent.horizontalCenter + text: "Click to Toggle" + color: "white" + font.pixelSize: 24 + } + Emitter { + system: sys + y:root.height + 20 + width: root.width + emitRate: 200 + lifeSpan: 4000 + startTime: 4000 + velocity: PointDirection { y: -120; } + } + + ImageParticle { + system: sys + visible: !cloneMode + source: "../../images/particle2.png" + } + + ImageParticle { + system: sys + visible: cloneMode + z: 0 + source: "../../images/particle3.png" + } + + ImageParticle { + system: sys + clip: true + visible: cloneMode + y: 120 + height: 240 + width: root.width + z: 1 + source: "../../images/particle.png" + } +} diff --git a/examples/quick/particles/system/content/startstop.qml b/examples/quick/particles/system/content/startstop.qml new file mode 100644 index 0000000000..f0433e1b39 --- /dev/null +++ b/examples/quick/particles/system/content/startstop.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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" + Text { + text: "Left click to start/stop\nRight click to pause/unpause" + color: "white" + font.pixelSize: 24 + } + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: { + if (mouse.button == Qt.LeftButton) + particles.running = !particles.running + else + particles.paused = !particles.paused; + } + } + + ParticleSystem { + id: particles + running: false + } + + ImageParticle { + anchors.fill: parent + system: particles + source: "../../images/star.png" + sizeTable: "../../images/sparkleSize.png" + alpha: 0 + colorVariation: 0.6 + } + + Emitter { + anchors.fill: parent + system: particles + emitRate: 2000 + lifeSpan: 2000 + size: 30 + sizeVariation: 10 + } +} diff --git a/examples/quick/particles/system/content/timedgroupchanges.qml b/examples/quick/particles/system/content/timedgroupchanges.qml new file mode 100644 index 0000000000..86ea811614 --- /dev/null +++ b/examples/quick/particles/system/content/timedgroupchanges.qml @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** 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: 600 + color: "black" + ParticleSystem { + anchors.fill: parent + id: syssy + //! [0] + ParticleGroup { + name: "fire" + duration: 2000 + durationVariation: 2000 + to: {"splode":1} + } + //! [0] + //! [1] + ParticleGroup { + name: "splode" + duration: 400 + to: {"dead":1} + TrailEmitter { + group: "works" + emitRatePerParticle: 100 + lifeSpan: 1000 + maximumEmitted: 1200 + size: 8 + velocity: AngleDirection {angle: 270; angleVariation: 45; magnitude: 20; magnitudeVariation: 20;} + acceleration: PointDirection {y:100; yVariation: 20} + } + } + //! [1] + //! [2] + ParticleGroup { + name: "dead" + duration: 1000 + Affector { + once: true + onAffected: worksEmitter.burst(400,x,y) + } + } + //! [2] + + Timer { + interval: 6000 + running: true + triggeredOnStart: true + repeat: true + onTriggered:startingEmitter.pulse(100); + } + Emitter { + id: startingEmitter + group: "fire" + width: parent.width + y: parent.height + enabled: false + emitRate: 80 + lifeSpan: 6000 + velocity: PointDirection {y:-100;} + size: 32 + } + + Emitter { + id: worksEmitter + group: "works" + enabled: false + emitRate: 100 + lifeSpan: 1600 + maximumEmitted: 6400 + size: 8 + velocity: CumulativeDirection { + PointDirection {y:-100} + AngleDirection {angleVariation: 360; magnitudeVariation: 80;} + } + acceleration: PointDirection {y:100; yVariation: 20} + } + + ImageParticle { + groups: ["works", "fire", "splode"] + source: "../../images/particle.png" + entryEffect: ImageParticle.Scale + } + } +} + diff --git a/examples/quick/particles/system/doc/images/qml-system-example.png b/examples/quick/particles/system/doc/images/qml-system-example.png Binary files differnew file mode 100644 index 0000000000..1a317c4be8 --- /dev/null +++ b/examples/quick/particles/system/doc/images/qml-system-example.png diff --git a/examples/quick/particles/system/doc/src/system.qdoc b/examples/quick/particles/system/doc/src/system.qdoc new file mode 100644 index 0000000000..8c381a57ec --- /dev/null +++ b/examples/quick/particles/system/doc/src/system.qdoc @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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/system + \brief This is a collection of examples using Affectors in the QML particle system. + \image qml-system-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. + + Dynamic comparison compares using the particle system to getting a similar effect with the following code that dynamically instantiates Image elements. + \snippet particles/system/content/dynamiccomparison.qml fake + Note how the Image elements are not able to be randomly colorized. + + Start and Stop simply sets the running and paused states of a ParticleSystem. While the system does not perform any simulation when stopped or paused, a restart restarts the simulation from the beginning, while unpausing resumes the simulation from where it was. + + Timed group changes is an example that highlights the ParticleGroup element. While normally referring to groups with a string name is sufficent, additional effects can be + done by setting properties on groups. + The first group has a variable duration on it, but always transitions to the second group. + \snippet particles/system/content/timedgroupchanges.qml 0 + The second group has a TrailEmitter on it, and a fixed duration for emitting into the third group. By placing the TrailEmitter as a direct child of the ParticleGroup, it automatically selects that group to follow. + \snippet particles/system/content/timedgroupchanges.qml 1 + The third group has an Affector as a direct child, which makes the affector automatically target this group. The affector means that as soon as particles enter this group, a burst function can be called on another emitter, using the x,y positions of this particle. + \snippet particles/system/content/timedgroupchanges.qml 2 + + If TrailEmitter does not suit your needs for multiple emitters, you can also dynamically create Emitters while still using the same ParticleSystem and image particle + \snippet particles/system/content/dynamicemitters.qml 0 + Note that this effect, a flurry of flying rainbow spears, would be better served with TrailEmitter. It is only done with dynamic emitters in this example to show the concept more simply. + + Multiple Painters shows how to control paint ordering of individual particles. While the paint ordering of particles within one ImagePainter is not strictly defined, ImageParticle elements follow the normal Z-ordering rules for QtQuick items. This example allow you to paint the inside of the particles above the black borders using a pair of ImageParticles each painting different parts of the same logical particle. + +*/ + diff --git a/examples/quick/particles/system/main.cpp b/examples/quick/particles/system/main.cpp new file mode 100644 index 0000000000..ea67283822 --- /dev/null +++ b/examples/quick/particles/system/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(system) diff --git a/examples/quick/particles/system/system.pro b/examples/quick/particles/system/system.pro new file mode 100644 index 0000000000..f2e3567543 --- /dev/null +++ b/examples/quick/particles/system/system.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/system +qml.files = system.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/system +INSTALLS += target qml diff --git a/examples/quick/particles/system/system.qml b/examples/quick/particles/system/system.qml new file mode 100644 index 0000000000..a299d0af27 --- /dev/null +++ b/examples/quick/particles/system/system.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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("Dynamic Comparison", "Compares with dynamically created elements", Qt.resolvedUrl("content/dynamiccomparison.qml")); + addExample("StartStop", "Start and stop the simulation", Qt.resolvedUrl("content/startstop.qml")); + addExample("Timed group changes", "Emit into managed groups", Qt.resolvedUrl("content/timedgroupchanges.qml")); + addExample("Dynamic Emitters", "Dynamically instantiated emitters with a single system", Qt.resolvedUrl("content/dynamicemitters.qml")); + addExample("Multiple Painters", "Several ParticlePainters on the same logical particles", Qt.resolvedUrl("content/multiplepainters.qml")); + } + } +} diff --git a/examples/quick/particles/system/system.qmlproject b/examples/quick/particles/system/system.qmlproject new file mode 100644 index 0000000000..1f9df3cecf --- /dev/null +++ b/examples/quick/particles/system/system.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.1 + +Project { + mainFile: "system.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +} |