-
Notifications
You must be signed in to change notification settings - Fork 32
/
orbiting-asteroids.qml
247 lines (234 loc) · 9.69 KB
/
orbiting-asteroids.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* Copyright (C) 2018 - Timo Könnecke <[email protected]>
* 2016 - Sylvia van Os <[email protected]>
* 2015 - Florent Revest <[email protected]>
* 2012 - Vasiliy Sorokin <[email protected]>
* Aleksey Mikhailichenko <[email protected]>
* Arto Jalkanen <[email protected]>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
Item {
property var radian: 0.01745329252
property string imgPath: "../watchfaces-img/orbiting-asteroids-"
Canvas {
id: secondCanvas
property var second: 0
anchors.fill: parent
smooth: true
renderStrategy: Canvas.Cooperative
onPaint: {
var ctx = getContext("2d")
var rot = (wallClock.time.getSeconds() - 15)*6
var rot_half = (wallClock.time.getSeconds() - 22)*6
ctx.reset()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 2.15, (rot_half-35)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(0.945, 0.769, 0.059, 0.7)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 2.25, (rot_half-120)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(0.945, 0.769, 0.059, 0.45)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 2.35, (rot_half-230)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(0.945, 0.769, 0.059, 0.20)
ctx.stroke()
}
}
Canvas {
id: minuteCanvas
property var minute: 0
anchors.fill: parent
smooth: true
renderStrategy: Canvas.Cooperative
onPaint: {
var ctx = getContext("2d")
var rot = (wallClock.time.getMinutes() -15 )*6
var rot_half = (wallClock.time.getMinutes() -42 )*6
ctx.reset()
ctx.beginPath()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 2.63, (rot_half+35)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(1, 0.549, 0.149, 0.7)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 2.77, (rot_half-40)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(1, 0.549, 0.149, 0.51)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 2.92, (rot_half-95)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(1, 0.549, 0.149, 0.38)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 3.08, (rot_half-130)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(1, 0.549, 0.149, 0.20)
ctx.stroke()
}
}
Canvas {
id: hourCanvas
property var hour: 0
anchors.fill: parent
smooth: true
renderStrategy: Canvas.Cooperative
onPaint: {
var ctx = getContext("2d")
var rot = 0.5 * (60 * (wallClock.time.getHours()-3) + wallClock.time.getMinutes())
var rot_half = 0.5 * (60 * (wallClock.time.getHours()-7.5) + wallClock.time.getMinutes())
ctx.reset()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 3.57, (rot_half+35)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(0.871, 0.165, 0.102, 0.7)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 3.87, (rot_half-20)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(0.871, 0.165, 0.102, 0.55)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 4.17, (rot_half-70)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(0.871, 0.165, 0.102, 0.4)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 4.47, (rot_half-125)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(0.871, 0.165, 0.102, 0.25)
ctx.stroke()
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, width / 4.77, (rot_half-190)* radian, rot* radian, false);
ctx.lineWidth = parent.width/42
ctx.strokeStyle = Qt.rgba(0.871, 0.165, 0.102, 0.2)
ctx.stroke()
}
}
Image {
id: secondAsteroid
property var rotS: (wallClock.time.getSeconds() - 15)/60
property var centerX: parent.width/2-width/2
property var centerY: parent.height/2-height/2
source: imgPath + "second.png"
x: centerX+Math.cos(rotS * 2 * Math.PI)*width*5.78
y: centerY+Math.sin(rotS * 2 * Math.PI)*width*5.78
width: parent.width/13
height: parent.width/13
}
Image {
id: minuteAsteroid
property var rotM: (wallClock.time.getMinutes() - 15)/60
property var centerX: parent.width/2-width/2
property var centerY: parent.height/2-height/2
source: imgPath + "minute.png"
x: centerX+Math.cos(rotM * 2 * Math.PI)*width*3.9
y: centerY+Math.sin(rotM * 2 * Math.PI)*width*3.9
width: parent.width/11
height: parent.width/11
}
Image {
id: hourAsteroid
property var rotH: (wallClock.time.getHours()-3 + wallClock.time.getMinutes()/60) / 12
property var centerX: parent.width/2-width/2
property var centerY: parent.height/2-height/2
source: imgPath + "hour.png"
x: (centerX+Math.cos(rotH * 2 * Math.PI)*width*2.23)
y: (centerY+Math.sin(rotH * 2 * Math.PI)*width*2.23)
width: parent.width/9
height: parent.width/9
}
Text {
id: hourDisplay
font.pixelSize: parent.height/4
font.family: "OpenSans"
font.styleName:"Bold"
color: "white"
opacity: 0.8
style: Text.Outline; styleColor: "#80000000"
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text: if (use12H.value) {
wallClock.time.toLocaleString(Qt.locale(), "hh ap").slice(0, 2) }
else
wallClock.time.toLocaleString(Qt.locale(), "HH")
}
Text {
id: minuteDisplay
property var rotM: (wallClock.time.getMinutes() - 12.2)/60
property var centerX: parent.width/2-width/2
property var centerY: parent.height/2-height/2
font.pixelSize: parent.height/12.7
font.family: "OpenSans"
color: "white"
style: Text.Outline; styleColor: "#80000000"
opacity: 0.9
x: centerX+Math.cos(rotM * 2 * Math.PI)*width*4.1
y: centerY+Math.sin(rotM * 2 * Math.PI)*width*4.1
text: wallClock.time.toLocaleString(Qt.locale(), "<b>mm</b>")
}
Text {
id: secondDisplay
property var rotS: (wallClock.time.getSeconds() - 13.05)/60
property var centerX: parent.width/2-width/2
property var centerY: parent.height/2-height/2
font.pixelSize: parent.height/14
font.family: "OpenSans"
color: "white"
style: Text.Outline; styleColor: "#80000000"
opacity: 0.95
x: centerX+Math.cos(rotS * 2 * Math.PI)*height*4.54
y: centerY+Math.sin(rotS * 2 * Math.PI)*height*4.54
text: wallClock.time.toLocaleString(Qt.locale(), "ss")
}
Connections {
target: wallClock
function onTimeChanged() {
var hour = wallClock.time.getHours()
var minute = wallClock.time.getMinutes()
var second = wallClock.time.getSeconds()
var date = wallClock.time.getDate()
if(secondCanvas.second != second) {
secondCanvas.second = second
secondCanvas.requestPaint()
}if(minuteCanvas.minute != minute) {
minuteCanvas.minute = minute
minuteCanvas.requestPaint()
hourCanvas.hour = hour
hourCanvas.requestPaint()
}
}
}
Component.onCompleted: {
var hour = wallClock.time.getHours()
var minute = wallClock.time.getMinutes()
var second = wallClock.time.getSeconds()
var date = wallClock.time.getDate()
secondCanvas.second = second
secondCanvas.requestPaint()
minuteCanvas.minute = minute
minuteCanvas.requestPaint()
hourCanvas.hour = hour
hourCanvas.requestPaint()
}
}