-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmazakodron.qml
188 lines (155 loc) · 4.74 KB
/
mazakodron.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import Qt 4.7
Rectangle {
signal requestDraw(double x1, double y1, double x2, double y2);
property bool mazak_down: false;
property bool robot_hidden: false;
property bool robot_transparent: false;
property double constROBOT_R: 119.5;
property double constWHEEL_R: 18.0;
property double constREV_STEP: 1.0/4096.0;
property double constSTEP: 0.220875/8.0;
property int counter: 0;
Timer {
id: timer
interval: 250;
running: false;
repeat: false;
triggeredOnStart: false;
onTriggered: drawing.source="image://mazakodron/drawing"+counter
}
function draw(x1, y1, x2, y2) {
if (mazak_down) {
requestDraw(x1, y1, x2, y2)
counter++;
timer.start()
}
}
function goForward() {
var oldXPos = mazak.xPos, oldYPos = mazak.yPos;
var angle = (mazak.rotation/360)*2*3.14;
mazak.xPos += (-constSTEP * Math.sin(angle))/297;
mazak.yPos += (constSTEP * Math.cos(angle))/210;
draw(oldXPos, oldYPos, mazak.xPos, mazak.yPos);
}
function goBackward() {
var oldXPos = mazak.xPos, oldYPos = mazak.yPos;
var angle = (mazak.rotation/360)*2*3.14;
mazak.xPos -= (-constSTEP * Math.sin(angle))/297;
mazak.yPos -= (constSTEP * Math.cos(angle))/210;
draw(oldXPos, oldYPos, mazak.xPos, mazak.yPos);
}
function rotateLeft() {
mazak.rotation -= (constWHEEL_R*constREV_STEP*360)/constROBOT_R;
}
function rotateRight() {
mazak.rotation += (constWHEEL_R*constREV_STEP*360)/constROBOT_R;
}
function liftMazak() {
mazak_down = false;
drawing.source="image://mazakodron/drawing"+counter;
}
function dropMazak() {
mazak_down = true;
}
function hideRobot() {
robot_hidden = true;
}
function showRobot() {
robot_hidden = false;
}
id: view
anchors.fill: parent;
color: "grey";
Rectangle {
id: paper;
x: view.width/2 - paper.width/2;
y: view.height/2 - paper.height/2;
width: Math.min(view.width, view.height*1.41)*0.75;
height: Math.min(view.height, view.width*0.7)*0.75;
color: "white";
Image {
id: drawing;
anchors.fill: parent;
source: "image://mazakodron/drawing";
smooth: true;
asynchronous: false;
}
Image {
property double xPos: 0;
property double yPos: 0;
id: mazak;
opacity: 1;
x: xPos*paper.width;
y: yPos*paper.height;
width: 0;
height: 0;
rotation: 0;
states:[ State {
name: "hidden"; when: robot_hidden == true;
PropertyChanges {
target: mazak;
opacity: 0
}
},
State {
name: "transparent"; when: robot_transparent == true;
PropertyChanges {
target: mazakodron;
opacity: 0.5
}
}
]
transitions: [ Transition {
from: "*"; to: "hidden"; reversible: true;
SequentialAnimation {
NumberAnimation { target: mazak; property: "opacity"; duration: 5000; easing.type:Easing.InQuad; }
}
}, Transition {
from: "*"; to: "transparent"; reversible: true;
SequentialAnimation {
NumberAnimation { target: mazakodron; property: "opacity"; duration: 500;}
}
}]
Image {
id: mazakodron;
x: -0.435*paper.width;
y: -0.27*paper.height;
width: 0.8825*paper.width;
height: 0.5505*paper.height;
source: "mazakodron.png";
asynchronous: true;
smooth: true;
}
Image {
id: mazak_img;
x: -0.036*paper.width;
y: -0.052*paper.height-(0.12*paper.height);
width: 0.064*paper.width+(0.01*paper.width);
height: 0.11*paper.height+(0.01*paper.width);
source: "mazak.png";
asynchronous: true;
smooth: true;
states: State {
name: "down"; when: mazak_down == true;
PropertyChanges {
target: mazak_img;
x: -0.036*paper.width;
y: -0.052*paper.height;
width: 0.064*paper.width;
height: 0.11*paper.height;
}
}
transitions: Transition {
from: ""; to: "down"; reversible: true;
SequentialAnimation {
NumberAnimation { target: mazak_img; properties: "x,y,width,height"; duration: 100; easing.type:Easing.InQuad; }
}
}
}
}
}
MouseArea {
anchors.fill: parent
onClicked: { robot_transparent = !robot_transparent;}
}
}