-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqml-01-graphing.q
49 lines (41 loc) · 1.01 KB
/
qml-01-graphing.q
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
use "lang/qml" = qml
win = qml.Window("Graph")
win.setSize(600, 600)
win.centerOnScreen()
surface = qml.Surface(600, 600)
# Calculate graph
f = sin
coordR = 4
function coord(x)
return (x + coordR) * 600 / (coordR * 2)
stepX = 0.1
dataX = -coordR:+coordR:stepX
dataY = map(f, dataX)
# Draw coordinates
surface.setColor([0, 0, 255])
surface.drawLine(0, 300, 600, 300)
surface.drawLine(300, 0, 300, 600)
surface.setColor([255, 0, 0])
through 0:-coordR as x
surface.drawText(coord(x), 300, string(x))
through 0:coordR as x
surface.drawText(coord(x), 300, string(x))
through 0:-coordR as y
surface.drawText(300, coord(y), string(y))
through 0:coordR as y
surface.drawText(300, coord(y), string(y))
surface.drawText(320, 20, "y")
surface.drawText(560, 310, "x")
# Draw graph
surface.setColor([0, 255, 0])
through 0:(dataX.size()-1) as i {
surface.drawLine(
coord(dataX[i]),
coord(dataY[i]),
coord(dataX[i+1]),
coord(dataY[i+1])
)
}
win.draw(surface)
win.setVisible(true)
while win.isVisible() {}