diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2012-07-17 18:32:16 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-24 05:01:59 +0200 |
commit | dbe4d2010816f1f22f48f3f5bce0d15d3ad7a7e2 (patch) | |
tree | d8e205e14e5497411ee7dd3d9a3c569851b73fb6 /examples/particles/affectors/content | |
parent | bd2493e21d7619e448b205f215777d1d7b023075 (diff) |
Particle example restyling
For self-contained particle systems, placing them inside the
ParticleSystem element is encouraged.
Change-Id: Iafc5a94bb07c4c0dac0daec300d01e0fde165146
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Diffstat (limited to 'examples/particles/affectors/content')
-rw-r--r-- | examples/particles/affectors/content/attractor.qml | 257 | ||||
-rw-r--r-- | examples/particles/affectors/content/customaffector.qml | 215 | ||||
-rw-r--r-- | examples/particles/affectors/content/friction.qml | 111 | ||||
-rw-r--r-- | examples/particles/affectors/content/turbulence.qml | 146 |
4 files changed, 352 insertions, 377 deletions
diff --git a/examples/particles/affectors/content/attractor.qml b/examples/particles/affectors/content/attractor.qml index 71e66a046e..797270f46f 100644 --- a/examples/particles/affectors/content/attractor.qml +++ b/examples/particles/affectors/content/attractor.qml @@ -50,150 +50,141 @@ Rectangle { source: "../../images/finalfrontier.png" anchors.centerIn:parent } - Emitter { - group: "stars" - system: particles - emitRate: 40 - lifeSpan: 4000 - enabled: true - size: 30 - sizeVariation: 10 - velocity: PointDirection { x: 220; xVariation: 40 } - height: parent.height - } - Emitter { - group: "roids" - system: particles - emitRate: 10 - lifeSpan: 4000 - enabled: true - size: 30 - sizeVariation: 10 - velocity: PointDirection { x: 220; xVariation: 40 } - height: parent.height - } ParticleSystem { id: particles anchors.fill: parent - } - ImageParticle { - id: stars - groups: ["stars"] - system: particles - source: "../../images/star.png" - color: "white" - colorVariation: 0.1 - alpha: 0 - } - ImageParticle { - id: roids - groups: ["roids"] - system: particles - sprites: Sprite { - id: spinState - name: "spinning" - source: "../../images/meteor.png" - frameCount: 35 - frameDuration: 60 + + Emitter { + group: "stars" + emitRate: 40 + lifeSpan: 4000 + enabled: true + size: 30 + sizeVariation: 10 + velocity: PointDirection { x: 220; xVariation: 40 } + height: parent.height } - } - ImageParticle { - id: shot - groups: ["shot"] - system: particles - source: "../../images/star.png" + 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"] - system: particles - source: "../../images/particle4.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 + color: "orange" + SequentialAnimation on color { + loops: Animation.Infinite + ColorAnimation { + from: "red" + to: "cyan" + duration: 1000 + } + ColorAnimation { + from: "cyan" + to: "red" + duration: 1000 + } } - } - colorVariation: 0.2 - } - //! [0] - Attractor { - id: gs; pointX: root.width/2; pointY: root.height/2; strength: 4000000; - system: particles - affectedParameter: Attractor.Acceleration - proportionalToDistance: Attractor.InverseQuadratic - } - //! [0] - Age { - system: particles - x: gs.pointX - 8; - y: gs.pointY - 8; - width: 16 - height: 16 - } - Rectangle { - color: "black" - width: 8 - height: 8 - radius: 4 - x: gs.pointX - 4 - y: gs.pointY - 4 - } + 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} + 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} + } } - 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 } - } - Emitter { - group: "engine" - system: particles - 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" - system: particles - 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/particles/affectors/content/customaffector.qml b/examples/particles/affectors/content/customaffector.qml index 8f634fbea3..4ddfc4802c 100644 --- a/examples/particles/affectors/content/customaffector.qml +++ b/examples/particles/affectors/content/customaffector.qml @@ -50,127 +50,118 @@ Item { anchors.fill: parent } ParticleSystem { - id: sys - } - Emitter { - system: sys - width: parent.width - emitRate: 4 - lifeSpan: 14000 - size: 80 - velocity: PointDirection { y: 60 } - } - Wander { - system: sys anchors.fill: parent - anchors.bottomMargin: 100 - xVariance: 60 - pace: 60 - } + 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 { - system: sys - 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; + //! [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; } - 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] + //! [0] - //! [1] - Affector {//Custom Friction, adds some 'randomness' - system: sys - 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] + 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] + //! [1] - ImageParticle { - anchors.fill: parent - id: particles - system: sys - 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 - } - ] + 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 + z:4 + } } } diff --git a/examples/particles/affectors/content/friction.qml b/examples/particles/affectors/content/friction.qml index bed1cf2a33..c9c42fd895 100644 --- a/examples/particles/affectors/content/friction.qml +++ b/examples/particles/affectors/content/friction.qml @@ -49,64 +49,63 @@ Item { source: "../../images/backgroundLeaves.jpg" anchors.fill: parent } - ParticleSystem { id: sys } - Emitter { - system: sys - width: parent.width - emitRate: 4 - lifeSpan: 14000 - size: 80 - velocity: PointDirection { y: 160; yVariation: 80; xVariation: 20 } - } - - ImageParticle { + ParticleSystem { anchors.fill: parent - id: particles - system: sys - 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 - } - ] + Emitter { + width: parent.width + emitRate: 4 + lifeSpan: 14000 + size: 80 + velocity: PointDirection { y: 160; yVariation: 80; xVariation: 20 } + } - width: 100 - height: 100 - x: 20 - y: 20 - z:4 - } + 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 + } + ] - //! [0] - Friction { - anchors.fill: parent - anchors.margins: -40 - system: sys - factor: 0.4 + width: 100 + height: 100 + x: 20 + y: 20 + z:4 + } + + //! [0] + Friction { + anchors.fill: parent + anchors.margins: -40 + factor: 0.4 + } + //! [0] } - //! [0] } diff --git a/examples/particles/affectors/content/turbulence.qml b/examples/particles/affectors/content/turbulence.qml index 62231e12ad..36b9561385 100644 --- a/examples/particles/affectors/content/turbulence.qml +++ b/examples/particles/affectors/content/turbulence.qml @@ -54,85 +54,79 @@ Rectangle { anchors.horizontalCenterOffset: 2 } ParticleSystem { - id: ps - } - MouseArea { anchors.fill: parent - onClicked: turb.enabled = !turb.enabled - } + MouseArea { + anchors.fill: parent + onClicked: turb.enabled = !turb.enabled + } - //! [0] - Turbulence { - id: turb - system: ps - 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] + //! [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"] - system: ps - source: "../../images/particle.png" - color: "#11111111" - colorVariation: 0 - } - ImageParticle { - groups: ["flame"] - system: ps - source: "../../images/particle.png" - color: "#11ff400f" - colorVariation: 0.1 - } - Emitter { - anchors.centerIn: parent - system: ps - 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 - system: ps - group: "smoke" - follow: "flame" + 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" - 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 - system: ps - 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 } + 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 } + } } } |