Commit 53bc356c authored by bharatak's avatar bharatak
Browse files

First version of Free Fall Tower

parent 215fc59f
File added
import QtQuick 2.0
Image{
id: ball
width: 30
height: 30
property int weight: 100
property int timeTaken:0
property string text:"ball"
signal clicked
onWeightChanged: {
ball.width=30*weight/100;
ball.height=30*weight/100;
}
MouseArea{
anchors.fill: parent
onClicked: ball.clicked();
}
}
import QtQuick 2.0
Rectangle{
id: root
color: "#49BAB6"
property int duration
property string medium
property alias ball: ball
property alias ballWeight : ball.weight
property alias ballSource : ball.source
property alias ballVisible : ball.visible
signal clicked;
Ball {
id: ball
weight: 0
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
root.clicked();
}
Behavior on y{
NumberAnimation{
duration: root.duration;
easing.type: Easing.InOutSine
}
}
}
}
import QtQuick 2.0
import "Constants.js" as Constants
Item {
id: root
width: 100
height: 100
signal footballClicked;
signal golfballClicked;
signal ironballClicked;
signal cottonballClicked;
Grid{
id: grid
rows: 2; columns: 2; spacing: 4
Ball {
id:footBall
source: Constants.footBallSource
text: Constants.footBallText
onClicked:{
root.footballClicked();
}
}
Ball {
id:golfBall
source: Constants.golfBallSource
text: Constants.golfBallText
onClicked:{
root.golfballClicked();
}
}
Ball {
id:ironBall
source: Constants.ironBallSource
text: Constants.ironBallText
onClicked:{
root.ironballClicked();
}
}
Ball {
id:cottonBall
source: Constants.cottonBallSource
text: Constants.cottonBallText
onClicked:{
root.cottonballClicked();
}
}
}
}
import QtQuick 2.0
Rectangle{
id: root
width: parent.width
height: 30
radius: 15
// anchors.topMargin: 15
// anchors.top: parent.top
color: "#FCDE4A"
property alias text: btnText.text
signal clicked;
Text{
id: btnText
anchors.centerIn: parent
text: "Pickup"
}
MouseArea{
anchors.fill: parent
onClicked: root.clicked();
}
}
.pragma library
var weighingMachineSource = "images/scale2.png";
var rulerSource = "images/Ruler.png";
var footBallSource = "images/football.png";
var golfBallSource = "images/golfball.png";
var ironBallSource = "images/ironball.png";
var cottonBallSource = "images/cottonball.png";
var footBallText = "Foot Ball";
var golfBallText = "Golf Ball";
var ironBallText = "Iron Ball";
var cottonBallText = "Cotton Ball";
import QtQuick 2.0
import QtQuick.Controls 1.2
Rectangle {
id: resultsTable
property alias results : results
ListModel {
id: results
}
TableView {
width: parent.width
height: parent.height
TableViewColumn{ role: "objects" ; title: "Objects" ; width: parent.width*.20 }
TableViewColumn{ role: "mass" ; title: "Mass" ; width: parent.width*.20 }
TableViewColumn{ role: "height" ; title: "Height in Meters" ; width: parent.width*.20 }
TableViewColumn{ role: "time_taken" ; title: "Time in Milli Secs" ; width: parent.width*.20 }
TableViewColumn{ role: "medium" ; title: "Medium" ; width: parent.width*.20 }
model: results
}
}
import QtQuick 2.2
import QtQuick.Controls 1.2
import "Constants.js" as Constants
Rectangle {
width: 850
height: 1000
id: root
color: "#49BAB6"
property int slow: 4000
property int medium: 1000
property int fast: 500
property bool isVacuum: true
Rectangle{
id: top
height: root.height*0.7
width: root.width
color: root.color
WeighingMachine {
id: scaleLeft
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.leftMargin: 8
onBallClicked: {
freeFall.leftBallContainer.ballSource = scaleLeft.ball.source;
freeFall.leftBallContainer.ballWeight = scaleLeft.ball.weight;
freeFall.leftBallContainer.ballVisible = scaleLeft.ball.visible;
freeFall.leftBallContainer.ball.text = scaleLeft.ball.text;
console.log("Ball Text: "+ scaleLeft.ball.text);
scaleLeft.ball.visible = false;
freeFall.leftBallContainer.duration = root.medium;
freeFall.scale.spaceAboveScale.dropButton.visible = true
}
}
BallsKit{
id:leftKit
anchors.left: parent.left
anchors.leftMargin: 8
anchors.top: parent.top
anchors.topMargin: 15
//TODO: Change this logic to STATE into WeighingMachine
onFootballClicked: {
scaleLeft.ball.source = Constants.footBallSource;
scaleLeft.ball.visible = true;
scaleLeft.ball.text = Constants.footBallText;
scaleLeft.ballText = Constants.footBallText;
}
onIronballClicked:{
scaleLeft.ball.source = Constants.ironBallSource;
scaleLeft.ball.visible = true;
scaleLeft.ball.text = Constants.ironBallText;
scaleLeft.ballText = Constants.ironBallText;
}
onCottonballClicked:{
scaleLeft.ball.source = Constants.cottonBallSource;
scaleLeft.ball.visible = true;
scaleLeft.ball.text = Constants.cottonBallText;
scaleLeft.ballText = Constants.cottonBallText;
}
onGolfballClicked:{
scaleLeft.ball.source = Constants.golfBallSource;
scaleLeft.ball.visible = true;
scaleLeft.ball.text = Constants.golfBallText;
scaleLeft.ballText = Constants.golfBallText;
}
}
Rectangle{
id:freeFall
width: 400
height: parent.height
anchors.centerIn: parent
//anchors.left:scaleLeft.right
//anchors.right:scaleRight.left
color: root.color
property alias leftBallContainer: leftTree.ballContainer
property alias rightBallContainer: rightTree.ballContainer
property alias scale : scale
MonkeyTree{
id:leftTree
height: parent.height
width: parent.width*.35
anchors.right : scale.left
anchors.left: parent.left
color:root.color
}
Rectangle{
id:scale
width: 150
height: parent.height
anchors.centerIn: parent
property alias spaceAboveScale : spaceAboveScale
Rectangle{
id:spaceAboveScale
width: parent.width
height: parent.height * .22
anchors.top: parent.top
color:"#49BAB6"
property alias dropButton : btnDrop
/** TODO1 add this group box for radio button **/
GroupBox {
id: mediumBox
title: "Medium:"
anchors.horizontalCenter: parent.horizontalCenter
Column {
ExclusiveGroup { id: tabPositionGroup }
spacing: 10
RadioButton {
text: "Vacuum"
checked: true
exclusiveGroup: tabPositionGroup
onClicked: {
isVacuum = true
}
}
RadioButton {
text: "Air"
exclusiveGroup: tabPositionGroup
onClicked: {
isVacuum = false
}
}
}
}
Button2{
id: btnDrop
text: "Drop"
anchors.bottom:parent.bottom //TODO1: environment check
visible: false
onClicked: {
if(!isVacuum){
var exp = Math.exp((leftTree.currentHeight * 240)/leftTree.ballContainer.ball.weight);
var acosh = Math.log(exp + Math.sqrt(exp * exp -1));
leftTree.ballContainer.ball.timeTaken = 1000 *Math.sqrt(leftTree.ballContainer.ball.weight/(9.8 * 240))*acosh;
if(rightTree.ballContainer.ball.weight != 0){
exp = Math.exp((rightTree.currentHeight * 240)/rightTree.ballContainer.ball.weight);
acosh = Math.log(exp + Math.sqrt(exp * exp -1));
rightTree.ballContainer.ball.timeTaken = 1000 * Math.sqrt(rightTree.ballContainer.ball.weight/(9.8 * 240))*acosh;
//rightTree.ballContainer.ball.timeTaken = Math.sqrt(200000 * rightTree.currentHeight / (9.8*rightTree.ballContainer.ball.weight)).toFixed(2)
}
freeFall.leftBallContainer.medium = "Air"
freeFall.rightBallContainer.medium = "Air"
}
else{
leftTree.ballContainer.ball.timeTaken = (1000 * Math.sqrt((2 * leftTree.currentHeight) / 9.8)).toFixed(2)
rightTree.ballContainer.ball.timeTaken = (1000 * Math.sqrt((2 * rightTree.currentHeight) / 9.8)).toFixed(2)
freeFall.leftBallContainer.medium = "Vaccum"
freeFall.rightBallContainer.medium = "Vaccum"
}
if(leftTree.ballContainer.ball.timeTaken > rightTree.ballContainer.ball.timeTaken)
{
freeFall.leftBallContainer.duration = slow;
freeFall.rightBallContainer.duration = fast;
}
else if(leftTree.ballContainer.ball.timeTaken < rightTree.ballContainer.ball.timeTaken)
{
freeFall.leftBallContainer.duration = fast
freeFall.rightBallContainer.duration = slow
}
else{
freeFall.leftBallContainer.duration = fast;
freeFall.rightBallContainer.duration = fast;
}
freeFall.leftBallContainer.duration = leftTree.ballContainer.ball.timeTaken ;
freeFall.rightBallContainer.duration = rightTree.ballContainer.ball.timeTaken;
freeFall.leftBallContainer.ball.y = freeFall.leftBallContainer.height - freeFall.leftBallContainer.ball.height;
freeFall.rightBallContainer.ball.y = freeFall.rightBallContainer.height - freeFall.rightBallContainer.ball.height;
btnDrop.visible = false
btnReset.visible = true
if(leftTree.ballContainer.ballWeight !=0)
{
bottom.results.append({objects:freeFall.leftBallContainer.ball.text,height:leftTree.currentHeight, mass: freeFall.leftBallContainer.ball.weight, time_taken: leftTree.ballContainer.ball.timeTaken, medium: freeFall.leftBallContainer.medium })
}
if(rightTree.ballContainer.ballWeight !=0)
{
bottom.results.append({objects:freeFall.rightBallContainer.ball.text,height:rightTree.currentHeight, mass: freeFall.rightBallContainer.ball.weight, time_taken: rightTree.ballContainer.ball.timeTaken, medium: freeFall.rightBallContainer.medium })
}
}
}
Button2{
id: btnReset
text: "Reset"
visible: false
anchors.bottom:parent.bottom
onClicked: {
freeFall.leftBallContainer.duration = 0;
freeFall.rightBallContainer.duration = 0;
freeFall.leftBallContainer.ball.y = 0;
freeFall.rightBallContainer.ball.y = 0;
freeFall.leftBallContainer.ball.visible = false;
freeFall.rightBallContainer.ball.visible = false;
freeFall.leftBallContainer.ball.weight = 0;
freeFall.rightBallContainer.ball.weight = 0;
btnReset.visible = false;
//btnDrop.visible = true
}
}
}
Image{
id:rulerImg
source: Constants.rulerSource
width: parent.width
smooth: true
anchors.top:spaceAboveScale.bottom
anchors.bottom: parent.bottom
}
}
MonkeyTree{
id:rightTree
height: parent.height
color:"blue"
width: parent.width*.35
anchors.left : scale.right
anchors.right: parent.right
}
}
BallsKit{
id:rightKit
anchors.right: parent.right
anchors.top: parent.top
anchors.topMargin: 15
onFootballClicked: {
scaleRight.ball.source = Constants.footBallSource;
scaleRight.ball.visible = true;
scaleRight.ballText = Constants.footBallText;
scaleRight.ball.text = Constants.footBallText;
}
onIronballClicked:{
scaleRight.ball.source = Constants.ironBallSource;
scaleRight.ball.visible = true;
scaleRight.ballText = Constants.ironBallText;
scaleRight.ball.text = Constants.ironBallText;
}
onCottonballClicked:{
scaleRight.ball.source = Constants.cottonBallSource;
scaleRight.ball.visible = true;
scaleRight.ballText = Constants.cottonBallText;
scaleRight.ball.text = Constants.cottonBallText;
}
onGolfballClicked:{
scaleRight.ball.source = Constants.golfBallSource;
scaleRight.ball.visible = true;
scaleRight.ballText = Constants.golfBallText;
scaleRight.ball.text = Constants.golfBallText;
}
}
WeighingMachine{
id: scaleRight
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.rightMargin: 8
onBallClicked: {
freeFall.rightBallContainer.ballSource = scaleRight.ball.source;
freeFall.rightBallContainer.ballWeight = scaleRight.ball.weight;
freeFall.rightBallContainer.ballVisible = scaleRight.ball.visible;
freeFall.rightBallContainer.ball.text = scaleRight.ball.text
freeFall.rightBallContainer.duration = root.medium;
scaleRight.ball.visible = false;
freeFall.scale.spaceAboveScale.dropButton.visible = true
}
}
}
Rectangle{
id: bottom
anchors.top: top.bottom
anchors.bottom: parent.bottom
width: root.width
height:root.height/2
property alias results: table.results
/*gradient: Gradient{
GradientStop{position: 0.0 ; color: "#C2E8EF"}
GradientStop{position: 1.0; color: "#52D1E8"}
}
MouseArea{
anchors.fill: parent
onClicked:{
table.results.append({objects:"golf ball", mass: 200, time_taken: 200, medium: "Vacuum"})
//.append({ objects: current_drop_item.objectName ,
// mass: current_drop_item.objectMass,
// time_taken: Math.sqrt(2 * simulate_button.currentLayer * height_per_layer / 9.8).toFixed(2),
// medium: "Vaccum" })
}
}*/
ExperimentTable{
id: table
anchors.centerIn: parent
anchors { fill: parent; topMargin: 6; bottomMargin: 6; leftMargin: 6; rightMargin: 6 }
}
}
}
import QtQuick 2.2
Rectangle {
id:root
property int totalMonkeyHeight:monkeyTail.height+tree.height+monkey.height
property alias monkeyX: monkey.x
property alias monkeyY: monkey.y
height: parent.height
width: parent.width
property alias ballContainer: ballContainer
property int currentHeight: (15/(parent.height *.78))*ballContainer.height
clip:true
border.color: "black"
Image{
id:tree
width: parent.width
height: parent.height * .1
anchors.top: parent.top
source: "images/Tree.jpg"
}
Image {
id: monkeyTail
width: parent.width
anchors.top: tree.bottom
source: "images/MonkeyTail.jpg"
height: monkey.y - tree.height
}
Image {
id: monkey
y:tree.height+10
height: parent.height * .1
anchors.left:parent.left
anchors.right:parent.right
source: "images/Monkey.jpg"
MouseArea{
id:dragMonkey
anchors.fill: parent
drag.target: parent
drag.maximumY: root.height-parent.height
drag.minimumY:tree.height
}
}
BallContainer{
id: ballContainer
anchors.bottom: parent.bottom
anchors.top: monkey.bottom
width: parent.width
color:"#49BAB6"
}
}
import QtQuick 2.0
import QtQuick.Controls 1.2
Rectangle{
id: root
width: 200
height: 300
color: "#4abbb4"
property alias text: weightText.text
signal onSlideValueChanged;
property alias slideValue: slider1.value
property alias ball: ball
property alias ballText: labelText.text
property alias anim: anim
signal ballClicked
Ball{
id: ball
x: scale.x + (scale.width-width)/2
y: 0
source:""
anchors.bottom: scale.top
visible: false
width:30
height:30
onClicked: {
root.ballClicked();
}
}
states:[
State{
name: "football"
PropertyChanges{ target:ball; source:"images/football.png"}
PropertyChanges{ target:ball; visible:true}
PropertyChanges{ target:ball; text:"FOOT BALL"}
}
]
ParallelAnimation{
id: anim
NumberAnimation{
target: ball
properties:x
to: 242
duration: 200
}
NumberAnimation{
target: ball
properties:y
to: 52