Warning, /education/gcompris/external/qml-box2d/examples/rope/main.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.2 0002 import Box2D 2.0 0003 import QtQuick.Controls 1.1 0004 import "../shared" 0005 0006 Rectangle { 0007 id: screen 0008 0009 width: 800 0010 height: 600 0011 0012 Slider { 0013 id: lengthSlider 0014 x: 180 0015 y: 50 0016 width: 100 0017 height: 50 0018 maximumValue: 50 0019 minimumValue: 20 0020 value: 30 0021 } 0022 0023 Component { 0024 id: linkComponent 0025 PhysicsItem { 0026 id: ball 0027 0028 width: 20 0029 height: 20 0030 bodyType: Body.Dynamic 0031 0032 property color color: "#EFEFEF" 0033 0034 fixtures: Circle { 0035 radius: ball.width / 2 0036 density: 0.5 0037 } 0038 0039 Rectangle { 0040 radius: parent.width / 2 0041 border.color: "blue" 0042 color: parent.color 0043 width: parent.width 0044 height: parent.height 0045 smooth: true 0046 } 0047 } 0048 } 0049 0050 Component { 0051 id: jointComponent 0052 RopeJoint { 0053 localAnchorA: Qt.point(10,10) 0054 localAnchorB: Qt.point(10,10) 0055 maxLength: lengthSlider.value 0056 collideConnected: true 0057 } 0058 } 0059 0060 World { id: physicsWorld } 0061 0062 Component.onCompleted: { 0063 var prev = leftWall; 0064 for (var i = 60;i < 740;i += 20) { 0065 var newLink = linkComponent.createObject(screen); 0066 newLink.color = "orange"; 0067 newLink.x = i; 0068 newLink.y = 100; 0069 var newJoint = jointComponent.createObject(screen); 0070 if (i === 60) 0071 newJoint.localAnchorA = Qt.point(40, 100); 0072 newJoint.bodyA = prev.body; 0073 newJoint.bodyB = newLink.body; 0074 prev = newLink; 0075 } 0076 newJoint = jointComponent.createObject(screen); 0077 newJoint.localAnchorB = Qt.point(0,100); 0078 newJoint.bodyA = prev.body; 0079 newJoint.bodyB = rightWall.body; 0080 } 0081 0082 PhysicsItem { 0083 id: ground 0084 height: 40 0085 anchors { 0086 left: parent.left 0087 right: parent.right 0088 bottom: parent.bottom 0089 } 0090 fixtures: Box { 0091 width: ground.width 0092 height: ground.height 0093 friction: 1 0094 density: 1 0095 } 0096 Rectangle { 0097 anchors.fill: parent 0098 color: "#DEDEDE" 0099 } 0100 } 0101 0102 Wall { 0103 id: topWall 0104 height: 40 0105 anchors { 0106 left: parent.left 0107 right: parent.right 0108 top: parent.top 0109 } 0110 } 0111 0112 Wall { 0113 id: leftWall 0114 width: 40 0115 anchors { 0116 left: parent.left 0117 top: parent.top 0118 bottom: parent.bottom 0119 bottomMargin: 40 0120 } 0121 } 0122 0123 Wall { 0124 id: rightWall 0125 width: 40 0126 anchors { 0127 right: parent.right 0128 top: parent.top 0129 bottom: parent.bottom 0130 bottomMargin: 40 0131 } 0132 } 0133 0134 Rectangle { 0135 id: debugButton 0136 x: 50 0137 y: 50 0138 width: 120 0139 height: 30 0140 Text { 0141 text: "Debug view: " + (debugDraw.visible ? "on" : "off") 0142 anchors.centerIn: parent 0143 } 0144 color: "#DEDEDE" 0145 border.color: "#999" 0146 radius: 5 0147 MouseArea { 0148 anchors.fill: parent 0149 onClicked: debugDraw.visible = !debugDraw.visible; 0150 } 0151 } 0152 0153 DebugDraw { 0154 id: debugDraw 0155 world: physicsWorld 0156 opacity: 1 0157 visible: false 0158 } 0159 0160 Timer { 0161 id: ballsTimer 0162 interval: 500 0163 running: true 0164 repeat: true 0165 onTriggered: { 0166 var newBox = linkComponent.createObject(screen); 0167 newBox.x = 40 + (Math.random() * screen.width - 80); 0168 newBox.y = 50; 0169 } 0170 } 0171 }