Gravity.qml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import QtQuick 2.5
  2. import Box2D 2.0
  3. Item {
  4. id: root
  5. signal togglePause
  6. signal toggleChaos
  7. signal next
  8. property bool globalWorld: settings.fitByHeight
  9. property var worldArray: []
  10. property var pictureDelegate: Qt.createComponent(settings.fitByHeight ? "VerticalArtDelegate.qml" : "HorizontalArtDelegate.qml")
  11. anchors.fill: parent
  12. QtObject {
  13. id: d
  14. property double pace: settings.pace/60.0
  15. property int itemCount: 0
  16. }
  17. World {
  18. id: bullshitWorld
  19. timeStep: d.pace
  20. }
  21. World {
  22. // Global world at odds with relative positions!
  23. id: commonWorld
  24. timeStep: d.pace
  25. }
  26. Component {
  27. id: columnComponent
  28. Item {
  29. id: column
  30. x: xOffset - effectiveXOffset
  31. width: parent.width/settings.columnCount
  32. anchors { top: parent.top; bottom: parent.bottom }
  33. property var pictureArray: []
  34. property var physicsWorld: settings.globalWorld ? commonWorld : columnWorld
  35. property bool fixedRotation: true
  36. property int xOffset: width * index
  37. property int effectiveXOffset: settings.globalWorld ? xOffset : 0
  38. World {
  39. id: columnWorld
  40. timeStep: d.pace
  41. Component.onCompleted: worldArray.push(columnWorld)
  42. }
  43. RectangleBoxBody {
  44. world: physicsWorld
  45. height: 1
  46. anchors {
  47. left: parent.left
  48. right: parent.right
  49. top: parent.bottom
  50. }
  51. friction: 1
  52. density: 1
  53. }
  54. Timer {
  55. id: feedTimer
  56. running: true
  57. repeat: true
  58. interval: 1000*(settings.interval > 60 ? 60*(settings.interval-60) : settings.interval)*(Math.random()+1)
  59. onTriggered: {
  60. if (pictureArray.length > 0) {
  61. pictureArray.shift().world = bullshitWorld
  62. }
  63. var colHeight = 0
  64. pictureArray.forEach(function (picture) { colHeight += picture.height; })
  65. do {
  66. var item = pictureDelegate.createObject(column)
  67. item.leftViewport.connect(function() { d.itemCount--; })
  68. item.y = -colHeight - item.height
  69. d.itemCount++
  70. pictureArray.push(item)
  71. colHeight += item.height
  72. } while (colHeight < 1.5*root.height)
  73. }
  74. }
  75. Connections {
  76. target: root
  77. onTogglePause: feedTimer.running = !feedTimer.running
  78. onNext: feedTimer.triggered()
  79. onToggleChaos: fixedRotation = !fixedRotation
  80. }
  81. Timer {
  82. id: settleTimer
  83. running: false
  84. interval: 200
  85. onTriggered: feedTimer.triggered()
  86. }
  87. Component.onCompleted: settleTimer.start()
  88. }
  89. }
  90. // floor
  91. RectangleBoxBody {
  92. id: floor
  93. world: commonWorld
  94. height: 1
  95. anchors {
  96. left: parent.left
  97. right: parent.right
  98. top: parent.bottom
  99. }
  100. friction: 1
  101. density: 1
  102. }
  103. Repeater {
  104. model: settings.columnCount
  105. delegate: columnComponent
  106. }
  107. Connections {
  108. target: settings
  109. onColumnCountChanged: d.itemCount = 0
  110. }
  111. // TODO: The boot (Monty Python foot) of death to be applied to the stacks
  112. RectangleBoxBody {
  113. id: rect
  114. enabled: false
  115. visible: false
  116. friction: 1.0
  117. density: 1000
  118. color: "red"
  119. width: 50; height: 50
  120. bullet: true
  121. SequentialAnimation {
  122. id: murderAnimation
  123. //loops: Animation.Infinite
  124. //running: true
  125. ScriptAction { script: { root.togglePause() } }
  126. ScriptAction { script: { rect.world = worldArray.pop() } }
  127. PropertyAction { target: rect; property: "x"; value: -rect.width }
  128. PropertyAction { target: rect; property: "y"; value: root.height }
  129. ParallelAnimation {
  130. NumberAnimation { target: rect; property: "x"; to: 2560; duration: 1000 }
  131. NumberAnimation { target: rect; property: "y"; to: 0; duration: 1000 }
  132. }
  133. }
  134. }
  135. Rectangle {
  136. z: 1
  137. color: "black"
  138. anchors { right: parent.right; top: parent.top }
  139. width: itemCountLabel.width
  140. height: itemCountLabel.height
  141. Text {
  142. id: itemCountLabel
  143. font.pixelSize: 100
  144. text: d.itemCount
  145. color: "white"
  146. }
  147. }
  148. Keys.onUpPressed: root.togglePause()
  149. Keys.onDownPressed: root.toggleChaos() //root.next()
  150. }