Advertisement
Guest User

Untitled

a guest
Feb 9th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var snow = {
  2.     "NUMBER_OF_DROPS": 200,
  3.     "NUMBER_OF_IMAGES": 4,
  4.     "createADrop": function () {
  5.         var dropDiv = Qt.createQmlObject(
  6.                     'import QtQuick 2.0; Item {width: 20; height: 20}',
  7.                     dropContainer)
  8.         var image = Qt.createQmlObject(
  9.                     'import QtQuick 2.0; Image {width: 20; height: 20}',
  10.                     dropDiv)
  11.         image.source = "snow-" + this.randomInteger(
  12.                     1, this.NUMBER_OF_IMAGES) + ".png"
  13.         var anim = Qt.createQmlObject(
  14.                     'import QtQuick 2.0;import QtGraphicalEffects 1.0; NumberAnimation {}',
  15.                     dropDiv)
  16.         dropDiv.y = this.randomInteger(-dropContainer.height * 2,
  17.                                        -dropContainer.height)
  18.         dropDiv.x = this.randomInteger(0, dropContainer.width)
  19.         anim.target = dropDiv
  20.         anim.property = "y"
  21.         anim.from = dropDiv.y
  22.         anim.to = dropContainer.height
  23.         anim.loops = Animation.Infinite
  24.         anim.duration = Math.random() * (15000 - 1000) + 1000
  25.  
  26.         anim.start()
  27.         return dropDiv
  28.     },
  29.     "init": function () {
  30.         var container = dropContainer
  31.         for (var i = 0; i < this.NUMBER_OF_DROPS; i++) {
  32.             this.createADrop()
  33.         }
  34.     },
  35.     "randomFloat": function (low, high) {
  36.         return low + Math.random() * (high - low)
  37.     },
  38.     "randomInteger": function (low, high) {
  39.         return low + Math.floor(Math.random() * (high - low))
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement