Debian Codegraph @

examples/wallpapers/autumn/contents/ui/main.qml

raw
1 /*
2 SPDX-FileCopyrightText: 2013 Digia Plc and /or its subsidiary(-ies) <http://www.qt-project.org/legal>
3
4 This file is part of the examples of the Qt Toolkit.
5
6 SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 import QtQuick
10 import QtQuick.Particles
11
12 Item {
13 width: 360
14 height: 600
15
16 Image {
17 source: "../images/backgroundLeaves.jpg"
18 anchors.fill: parent
19 }
20 ParticleSystem {
21 anchors.fill: parent
22 Emitter {
23 width: parent.width
24 emitRate: 4
25 lifeSpan: 14000
26 size: 80
27 velocity: PointDirection { y: wallpaper.configuration.Speed }
28 }
29 Wander {
30 anchors.fill: parent
31 anchors.bottomMargin: 100
32 xVariance: 60
33 pace: 60
34 }
35
36 //! [0]
37 Affector {
38 property real coefficient: 2.0
39 property real velocity: 1.5
40 width: parent.width
41 height: parent.height - 100
42 onAffectParticles: {
43 /* //Linear movement
44 if (particle.r == 0) {
45 particle.r = Math.random() > 0.5 ? -1 : 1;
46 } else if (particle.r == 1) {
47 particle.rotation += velocity * dt;
48 if (particle.rotation >= maxAngle)
49 particle.r = -1;
50 } else if (particle.r == -1) {
51 particle.rotation -= velocity * dt;
52 if (particle.rotation <= -1 * maxAngle)
53 particle.r = 1;
54 }
55 */
56 //Wobbly movement
57 for (var i=0; i<particles.length; i++) {
58 var particle = particles[i];
59 if (particle.r == 0.0) {
60 particle.r = Math.random() + 0.01;
61 }
62 particle.rotation += velocity * particle.r * dt;
63 particle.r -= particle.rotation * coefficient;
64 if (particle.r == 0.0)
65 particle.r -= particle.rotation * 0.000001;
66 particle.update = 1;
67 }
68 }
69 }
70 //! [0]
71
72 //! [1]
73 Affector {//Custom Friction, adds some 'randomness'
74 x: -60
75 width: parent.width + 120
76 height: 100
77 anchors.bottom: parent.bottom
78 onAffectParticles: {
79 for (var i=0; i<particles.length; i++) {
80 var particle = particles[i];
81 var pseudoRand = (Math.floor(particle.t*1327) % 10) + 1;
82 var yslow = dt * pseudoRand * 0.5 + 1;
83 var xslow = dt * pseudoRand * 0.05 + 1;
84 if (particle.vy < 1)
85 particle.vy = 0;
86 else
87 particle.vy = (particle.vy / yslow);
88 if (particle.vx < 1)
89 particle.vx = 0;
90 else
91 particle.vx = (particle.vx / xslow);
92 particle.update = true;
93 }
94 }
95 }
96 //! [1]
97
98 ImageParticle {
99 anchors.fill: parent
100 id: particles
101 sprites: [Sprite {
102 source: "../images/realLeaf1.png"
103 frameCount: 1
104 frameDuration: 1
105 to: {"a":1, "b":1, "c":1, "d":1}
106 }, Sprite {
107 name: "a"
108 source: "../images/realLeaf1.png"
109 frameCount: 1
110 frameDuration: 10000
111 },
112 Sprite {
113 name: "b"
114 source: "../images/realLeaf2.png"
115 frameCount: 1
116 frameDuration: 10000
117 },
118 Sprite {
119 name: "c"
120 source: "../images/realLeaf3.png"
121 frameCount: 1
122 frameDuration: 10000
123 },
124 Sprite {
125 name: "d"
126 source: "../images/realLeaf4.png"
127 frameCount: 1
128 frameDuration: 10000
129 }
130 ]
131
132 z:4
133 }
134 }
135 }