-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdashDials.py
225 lines (166 loc) · 7.8 KB
/
dashDials.py
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
#!/usr/bin/python
# dashDials.py module
#Copyright (C) 2014 Eilidh Fridlington http://eilidh.fridlington.com
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 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 pygame
import math
from pygame.locals import *
import pygame.gfxdraw
pygame.init()
def convertToMPH(self,inputData):
return int(round ((inputData * 2.11) * 0.621371192237334))
def convertToRev(self,inputData):
return int(round((inputData * 12.5),2))
def convertToTemp(self,inputData):
return inputData - 50
def convertToBattery(self,inputData):
return round(((inputData * 80) / 1000),1)
def convertToMAF(self,inputData):
return inputData * 5
def convertToAAC(self,inputData):
return inputData / 2
def convertToInjection(self,inputData):
return inputData / 100
def convertToTiming(self,inputData):
return 110 - inputData
fifeteen = pygame.font.SysFont("Sans", 15)
twenty = pygame.font.SysFont("Sans", 18)
sixty = pygame.font.SysFont("Sans", 60)
BLACK = (0,0,0)
RED = (255,0,0)
WHITE = (255,255,255)
BLUE = (136,196,255)
percent = u'\N{PERCENT SIGN}'
millivolt = 'mV'
volt = 'V'
degree = u"\u00B0"
def indicatorLegend(
legendValue,
displayValue,
positionX,
positionY,
length,
destination,
fontSize,
doubleLength=False,
drawLine=True,
doubleLine=6,
singleLine=3,
displayDivision=1,
backgroundColour = WHITE,
dialType = False
):
position = (positionX,positionY)
if doubleLength:
lineLength = doubleLine
else:
lineLength = singleLine
x = position[0] - math.cos(math.radians(legendValue)) * length
y = position[1] - math.sin(math.radians(legendValue)) * length
xa = position[0] - math.cos(math.radians(legendValue)) * (length - int(length / lineLength))
ya = position[1] - math.sin(math.radians(legendValue)) * (length - int(length / lineLength))
xlabel = position[0] - math.cos(math.radians(legendValue)) * (length - int(length / singleLine))
ylabel = position[1] - math.sin(math.radians(legendValue)) * (length - int(length / singleLine))
if drawLine:
pygame.draw.aaline(destination, BLUE, (x,y),(xa,ya), False)
if dialType:
label = fontSize.render(("%s%s" % ((displayValue / displayDivision),dialType)),
1, BLUE, backgroundColour)
else:
label = fontSize.render((str(displayValue / displayDivision)),
1, BLUE, backgroundColour)
labelRect = label.get_rect()
labelRect.centerx = int(xlabel)
labelRect.centery = int(ylabel)# + 5
destination.blit(label, (labelRect))
def indicatorNeedle(
needleDestination,
needleValue = 0,
needleLength = 358,
positionX = 600,
positionY = 360,
fontSize = sixty,
backgroundColour = RED,
startPosition = 0,
endPosition = 0,
maximumValue = 10,
doubleLine = 6,
singleLine = 3,
displayDivision = 1,
displayNeedle = True,
displayCircle = True,
dialLabel = False,
dialType = False
):
position = (positionX,positionY)
length = needleLength
length2 = int(needleLength / 20)
length3 = length2 + 5
destination = needleDestination
fontSize = fontSize
singleLine = singleLine
doubleLine = doubleLine
backgroundColour = backgroundColour
dialType = dialType
degreesDifference = 360 - (startPosition + (180 - endPosition))
value = int((needleValue * (degreesDifference / (maximumValue * 10.0))) + startPosition)
displayValue = (needleValue * (degreesDifference / (maximumValue * 10.0))) + startPosition
x = position[0] - math.cos(math.radians(value)) * (length - int(length / singleLine))
y = position[1] - math.sin(math.radians(value)) * (length - int(length / singleLine))
x2 = position[0] - math.cos(math.radians(value - 90)) * length2
y2 = position[1] - math.sin(math.radians(value - 90)) * length2
x3 = position[0] - math.cos(math.radians(value + 180)) * length3
y3 = position[1] - math.sin(math.radians(value + 180)) * length3
x4 = position[0] - math.cos(math.radians(value + 90)) * length2
y4 = position[1] - math.sin(math.radians(value + 90)) * length2
xa = position[0] - math.cos(math.radians(value)) * length
ya = position[1] - math.sin(math.radians(value)) * length
xa2 = x - math.cos(math.radians(value))
ya2 = y - math.sin(math.radians(value))
xa3 = x - math.cos(math.radians(value + 180))
ya3 = y - math.sin(math.radians(value + 180))
xa4 = x - math.cos(math.radians(value + 90)) * (length2 + 4)
ya4 = y - math.sin(math.radians(value + 90)) * (length2 + 4)
if displayCircle:
#pygame.gfxdraw.aacircle(destination,position[0],position[1], length, RED)
pygame.draw.circle(destination, backgroundColour, (position[0],position[1]), length , 0)
if dialLabel:
showLabel = fontSize.render(dialLabel, 1, BLUE, backgroundColour)
labelRect = showLabel.get_rect()
labelRect.centerx = position[0]
labelRect.centery = position[1] - (length / 5)
destination.blit(showLabel, (labelRect))
valueDivisions = degreesDifference / 10
indicatorLegend(startPosition, 0, position[0], position[1], length,
destination, fontSize,False,True,doubleLine,singleLine,1,backgroundColour)
for divisions in range(1,10):
if needleValue >= (maximumValue * divisions):
indicatorLegend((startPosition + (valueDivisions * divisions)), (maximumValue * divisions),
position[0], position[1], length, destination, fontSize,True,True,doubleLine
,singleLine,displayDivision,backgroundColour)
if displayNeedle:
pygame.draw.aalines(destination, BLUE, True, ((x,y), (x2,y2), (x3, y3), (x4, y4)), False)
pygame.gfxdraw.arc(destination,position[0],position[1],
(length - int(length / singleLine)),(180 + value),endPosition, BLUE)
pygame.draw.aaline(destination, BLUE, (x,y),(xa,ya), False)
pygame.gfxdraw.arc(destination,position[0],position[1],
length,(180 + startPosition), (value - 180), BLUE)
pygame.gfxdraw.arc(destination,position[0],position[1],
(length - int(length / doubleLine)),(180 + startPosition) , (value - 180), BLUE)
if dialType:
indicatorLegend((180 + endPosition), needleValue, position[0], position[1],
length, destination, fontSize, False, False,
doubleLine,singleLine,1,backgroundColour,dialType)
else:
indicatorLegend((180 + endPosition), needleValue , position[0], position[1],
length, destination, fontSize, False, False,
doubleLine,singleLine,1,backgroundColour)