浏览代码

Improve upon Cascade with the algorithmic help of Herr Gabriel

Donald Carr 8 年之前
父节点
当前提交
4fb24cc7b9
共有 4 个文件被更改,包括 47 次插入54 次删除
  1. 37 48
      qml/cascade/Cascade.qml
  2. 3 3
      qml/cascade/CascadeDelegate.qml
  3. 3 3
      qml/common/ArtImage.qml
  4. 4 0
      qml/main.qml

+ 37 - 48
qml/cascade/Cascade.qml

@@ -4,11 +4,10 @@ import Qt.labs.settings 1.0
 
 import ".."
 
-View {
+Item {
     id: root
 
     signal togglePause
-    signal toggleChaos
     signal next
 
     property var columnArray: []
@@ -18,69 +17,69 @@ View {
 
     anchors.fill: parent
 
+    Settings {
+        id: cascadeSettings
+        category: "Cascade"
+        property int columnCount: 5
+        property int feedRate: 1000
+    }
+
     QtObject {
         id: d
-        property int columnCount: 6
-        property real pace: cascadeSettings.pace/60.0
+        property real goldenRatio: 1.61803398875
+        property real pace: 1.0/20.0
         property bool paused: false
+        function goldenBeast(col) {
+            return (1 - d.goldenRatio)/(1 - Math.pow(d.goldenRatio, col))
+        }
+
+        property real columnWidth: {
+            var foo = root.width*goldenBeast(cascadeSettings.columnCount)
+            console.log('Column width is:', foo)
+            return foo
+        }
     }
 
     Repeater {
-        model: d.columnCount
+        model: cascadeSettings.columnCount
         delegate: columnComponent
     }
 
-    Settings {
-        id: cascadeSettings
-        category: "Cascade"
-
-        property int feedRate: 1000
-        // 0 is abutting
-        property int verticalOffset: 500
-        property real pace: 3
-        property real density: 1.0
-        property real friction: 1.0
-        // Very computationally heavy: 40% vs 20% for 0.1 vs 0
-        property real restitution: 0
-    }
-
     Component {
         id: columnComponent
 
         Item {
             id: column
 
-            property bool shifty: false
             property int stackHeight: 0
-            property int xOffset: width * index
+            property int xOffset: d.columnWidth/d.goldenBeast(index)
             property var pictureArray: []
+            property bool full: stackHeight > (1.3 + 1/cascadeSettings.columnCount)*root.height
 
             function addExistingImage(image) {
                 // make sure there is no spacial conflict in limbo, or shit goes tits up
+                image.width = width
                 image.x = image.y = index*-1000
                 image.linearVelocity.x = image.linearVelocity.y = 0.0
                 image.beyondThePale.connect(removeImage)
-                image.x = xOffset
+
                 stackHeight += image.height
-                image.y = -image.height - pictureArray.length*100
+                image.x = xOffset
+                image.y = - stackHeight
                 image.world = isolatedWorld
 
                 pictureArray.push(image)
             }
 
             function addImage() {
-                var image = pictureDelegate.createObject(column, { x: -1000, y: -1000 })
+                var image = pictureDelegate.createObject(column)
                 addExistingImage(image)
-
                 globalUtil.itemCount++
             }
 
             function removeImage(image) {
                 image.beyondThePale.disconnect(removeImage)
-                stackHeight -= image.height
-                //console.log('Image slipped through the cracks')
-                if (index === d.columnCount-1) {
-                    console.log('Image deleted')
+                if (index === cascadeSettings.columnCount-1) {
                     image.destroy()
                     globalUtil.itemCount--
                 } else {
@@ -89,19 +88,12 @@ View {
             }
 
             function shift() {
-                if (pictureArray.length > 0) {
-                    var image = pictureArray.shift()
-                    image.world = image.world.limbo
-                }
-            }
-
-            onStackHeightChanged: {
-                if (stackHeight > (1.3 + 1/d.columnCount)*root.height) {
-                    shifty = true
-                }
+                var image = pictureArray.shift()
+                image.world = image.world.limbo
+                stackHeight -= image.height
             }
 
-            width: parent.width/globalSettings.columnCount
+            width: d.columnWidth*Math.pow(d.goldenRatio, index)
             anchors { top: parent.top; bottom: parent.bottom }
 
             World {
@@ -128,22 +120,19 @@ View {
 
             Timer {
                 id: pumpTimer
-                interval: 1000
+                interval: full ? cascadeSettings.feedRate : 10
                 repeat: true
-                running: (index === 0) && !shifty
+                running: index === 0
                 onTriggered: addImage()
             }
 
             Timer {
                 id: deathTimer
-                running: true
+                running: full
                 repeat: true
-                interval: 5000
+                interval: cascadeSettings.feedRate
                 onTriggered: {
-                    if (shifty) {
-                        shift()
-                        shifty = false
-                    }
+                    shift()
                 }
             }
 

+ 3 - 3
qml/cascade/CascadeDelegate.qml

@@ -13,9 +13,9 @@ ArtBoxBody {
         }
     }
 
-    density: 1 //cascadeSettings.density
-    friction: 1.0 //cascadeSettings.friction
-    restitution: 0.0 //cascadeSettings.restitution
+    density: 1
+    friction: 1.0
+    restitution: 0.0
 
     fixedRotation: true
     bodyType: Body.Dynamic

+ 3 - 3
qml/common/ArtImage.qml

@@ -8,14 +8,14 @@ Rectangle {
     property var effect
     property int modelIndex
 
-    color: "black"
+    color: globalSettings.randomTapestryColour ? Qt.rgba(Math.random(255), Math.random(255), Math.random(255), 1.0) : "black"
 
     height: Math.ceil(width/imageModel.data(modelIndex, PictureModel.RatioRole))
     width: parent.width
 
     Image {
         id: image
-        opacity: 0
+        opacity: globalSettings.fadeInImages ? 0 : 1.0
         anchors.fill: parent
         asynchronous: true
         fillMode: Image.PreserveAspectFit
@@ -37,7 +37,7 @@ Rectangle {
 
         onStatusChanged: {
             if (status === Image.Ready) {
-                opacity = 1
+                opacity = globalSettings.artOpacity
             }
         }
     }

+ 4 - 0
qml/main.qml

@@ -90,6 +90,10 @@ Window {
         property bool commonFeed: true
         property bool commonFeedRoundRobin: true
 
+        property real artOpacity: 1.0
+        property bool randomTapestryColour: false
+        property bool fadeInImages: true
+
         onColumnCountChanged: globalUtil.reset()
         Component.onCompleted: loader.source = globalSettings.view.toLowerCase() + "/" + globalSettings.view + ".qml"
     }