aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/particles/system/dynamiccomparison.qml
blob: d29b72f998495a6dfc39064f39197d0fadce44f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick.Particles

pragma ComponentBehavior: Bound

Rectangle {
    id: root
    color: "black"
    width: 640
    height: 480
    ParticleSystem {
        id: sys
    }

    ImageParticle {
        system: sys
        source: "qrc:///particleresources/glowdot.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) {
                let 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: "qrc:///particleresources/glowdot.png"
                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: qsTr("1000 particles")
        color: "white"
        MouseArea {
            anchors.fill: parent
            onClicked: emitter.burst(1000);
        }
    }
    Text {
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        text: qsTr("1000 items")
        color: "white"
        MouseArea {
            anchors.fill: parent
            onClicked: fakeEmitter.burst(1000);
        }
    }
}