BackgroundSwirls.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2015 The Qt Company Ltd.
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the examples of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:BSD$
  9. ** You may use this file under the terms of the BSD license as follows:
  10. **
  11. ** "Redistribution and use in source and binary forms, with or without
  12. ** modification, are permitted provided that the following conditions are
  13. ** met:
  14. ** * Redistributions of source code must retain the above copyright
  15. ** notice, this list of conditions and the following disclaimer.
  16. ** * Redistributions in binary form must reproduce the above copyright
  17. ** notice, this list of conditions and the following disclaimer in
  18. ** the documentation and/or other materials provided with the
  19. ** distribution.
  20. ** * Neither the name of The Qt Company Ltd nor the names of its
  21. ** contributors may be used to endorse or promote products derived
  22. ** from this software without specific prior written permission.
  23. **
  24. **
  25. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40. import QtQuick 2.5
  41. import QtQuick.Particles 2.0
  42. Item {
  43. anchors.fill: parent
  44. Rectangle {
  45. anchors.fill: parent
  46. gradient: Gradient {
  47. GradientStop { position: 0; color: "lightsteelblue" }
  48. GradientStop { position: 1; color: "black" }
  49. }
  50. }
  51. Rectangle {
  52. id: colorTableItem
  53. width: 16
  54. height: 16
  55. anchors.fill: parent
  56. property color color1: Qt.rgba(0.8, 0.8, 1, 0.3)
  57. property color color2: Qt.rgba(0.8, 0.8, 1, 0.3)
  58. gradient: Gradient {
  59. GradientStop { position: 0.0; color: "transparent"}
  60. GradientStop { position: 0.05; color: colorTableItem.color1 }
  61. GradientStop { position: 0.3; color: "transparent" }
  62. GradientStop { position: 0.7; color: "transparent" }
  63. GradientStop { position: 0.95; color: colorTableItem.color2 }
  64. GradientStop { position: 1.0; color: "transparent" }
  65. }
  66. visible: false
  67. }
  68. ShaderEffectSource {
  69. id: colorTableSource
  70. sourceItem: colorTableItem
  71. smooth: true
  72. }
  73. Repeater {
  74. model: 4
  75. Swirl {
  76. width: parent.width
  77. anchors.bottom: parent.bottom
  78. height: parent.height / (2 + index)
  79. opacity: 0.3
  80. speed: (index + 1) / 5
  81. colorTable: colorTableSource
  82. }
  83. }
  84. ParticleSystem{
  85. id: particles
  86. }
  87. ImageParticle{
  88. anchors.fill: parent
  89. system: particles
  90. source: "particle.png"
  91. alpha: 0
  92. colorVariation: 0.3
  93. }
  94. Emitter{
  95. anchors.fill: parent
  96. system: particles
  97. emitRate: Math.sqrt(parent.width * parent.height) / 30
  98. lifeSpan: 2000
  99. size: 4
  100. sizeVariation: 2
  101. acceleration: AngleDirection { angle: 90; angleVariation: 360; magnitude: 20; }
  102. velocity: AngleDirection { angle: -90; angleVariation: 360; magnitude: 10; }
  103. }
  104. }