def draw_bar_area_caps(self): ac.glColor4f(*config.BACKGROUND_COLOR.rgba) radius = config.BAR_CORNER_RADIUS segments = config.BAR_CORNER_SEGMENTS height = config.BAR_HEIGHT self._draw_horizontal_cap(radius, 0, -radius, height, radius, segments) self._draw_horizontal_cap(config.BAR_WIDTH - radius, 0, radius, height, radius, segments)
def draw(self, data, delta_t: float) -> None: # Calculates the current suspension travel in percentage. travel = (data.susp_t / data.susp_m_t) if data.susp_m_t > 0.0 else 0.5 # Checks the correct color. if travel > 0.95 or travel < 0.05: self._back.color = Colors.red elif travel > 0.90 or travel < 0.1: self._back.color = Colors.yellow else: self._back.color = Colors.blue if data.susp_v else Colors.white self._draw(Suspension.texture_id) # Initial padding is 10x44 rect = copy.copy(self._box.rect) rect[0] += 10 * self.__mult rect[1] += 44 * self.__mult rect[2] -= 20 * self.__mult rect[3] -= 88 * self.__mult # 100% # Why there is negative and above maximum numbers, KUNOS??? rect[3] = min(rect[3], max(0.0, rect[3] * (1.0 - travel))) ac.glColor4f(*self._back.color) ac.glQuad(*rect)
def donut(x, y, radius, width, start=0, stop=360, color=Color(1, 1, 1, 1), filled=True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glBegin(2) else: ac.glBegin(1) sample = (stop - start) / (36 * radius) while start <= stop: rad1 = start rad2 = min(start + 1, stop) ac.glVertex2f(x + cos(rad1) * radius, y - sin(rad1) * radius) ac.glVertex2f(x + cos(rad2) * radius, y - sin(rad2) * radius) ac.glVertex2f(x + cos(rad1) * (radius - width), y - sin(rad1) * (radius - width)) ac.glVertex2f(x + cos(rad2) * (radius - width), y - sin(rad2) * (radius - width)) if filled: ac.glVertex2f(x + cos(rad2) * radius, y - sin(rad2) * radius) ac.glVertex2f(x + cos(rad1) * (radius - width), y - sin(rad1) * (radius - width)) start += sample ac.glEnd()
def appGL(deltaT): global gX, gY, gZ, gXleft, gZback # drawing the gauge's background primitive aka a square # initial values x0 = 20.0 # point 1 y0 = 20.0 x1 = 20.0 # point 2 y1 = 500.0 #500 x2 = 500.0 # point 3 y2 = 500.0 x3 = 500.0 #500 point 4 y3 = 20.0 # so I'm gonna have to find a way to make these variables be affected by gforces # calucated values with gforces into account x00 = x0 + (abs(gZ)*100) # forward y00 = y0 + (abs(gXleft)*100) #right x11 = x1 + (abs(gZback)*100) #reverse y11 = y1 - (abs(gXleft)*100) #right x22 = x2 - (abs(gZback)*100) #reverse y22 = y2 - (abs(gX)*100) #left x33 = x3 - (abs(gZ)*100) #forward y33 = y3 + (abs(gX)*100) #left ac.glBegin(acsys.GL.Quads) ac.glColor4f(50,0,0,0.5) ac.glVertex2f(x00, y00) # top left in brainlet terms aka for dummies like me ac.glVertex2f(x11, y11) # bottom left ac.glVertex2f(x22, y22) # bottom right ac.glVertex2f(x33, y33) #top right ac.glEnd()
def draw_delta_bar(self, time_delta, speed_delta, bar_moves): # Color bar_color = self._delta_stripe_color(speed_delta) ac.glColor4f(*bar_color) # Calculations clamped_time_delta = self._clamp_time_delta(time_delta) delta_stripe_width = int((abs(clamped_time_delta) * config.BAR_SCALE)) delta_stripe_rect_width = delta_stripe_width should_draw_cap = delta_stripe_width > config.BAR_INNER_RECT_MAX_WIDTH if time_delta < 0: delta_rect_origin_x = config.BAR_WIDTH_HALF delta_label_position = delta_rect_origin_x + delta_stripe_width else: delta_rect_origin_x = config.BAR_WIDTH_HALF - delta_stripe_width delta_label_position = delta_rect_origin_x # Draw rounded cap and modify width and origin if should_draw_cap: delta_stripe_rect_width = config.BAR_INNER_RECT_MAX_WIDTH if time_delta > 0: delta_rect_origin_x = config.BAR_WIDTH_HALF - delta_stripe_rect_width self._draw_delta_stripe_cap(time_delta, delta_rect_origin_x, delta_stripe_width) # Draw stripe rect if delta_stripe_width > 0: ac.glQuad(delta_rect_origin_x, config.BAR_INNER_Y, delta_stripe_rect_width, config.BAR_INNER_HEIGHT) # Delta label self._update_delta_label(time_delta, delta_label_position, bar_moves)
def draw_delta_bar(self, time_delta, speed_delta, bar_moves): # Color if config.BAR_COLORS_OLD: bar_color = self._delta_stripe_color_old(speed_delta) else: bar_color = self._delta_stripe_color(speed_delta) ac.glColor4f(*bar_color) # Calculations clamped_time_delta = self._clamp_time_delta(time_delta) delta_stripe_width = int((abs(clamped_time_delta) * config.BAR_SCALE)) delta_stripe_rect_width = delta_stripe_width should_draw_cap = delta_stripe_width > config.BAR_INNER_RECT_MAX_WIDTH if time_delta < 0: delta_rect_origin_x = config.BAR_WIDTH_HALF delta_label_position = delta_rect_origin_x + delta_stripe_width else: delta_rect_origin_x = config.BAR_WIDTH_HALF - delta_stripe_width delta_label_position = delta_rect_origin_x # Draw rounded cap and modify width and origin if should_draw_cap: delta_stripe_rect_width = config.BAR_INNER_RECT_MAX_WIDTH if time_delta > 0: delta_rect_origin_x = config.BAR_WIDTH_HALF - delta_stripe_rect_width self._draw_delta_stripe_cap(time_delta, delta_rect_origin_x, delta_stripe_width) # Draw stripe rect if delta_stripe_width > 0: ac.glQuad(delta_rect_origin_x, config.BAR_INNER_Y, delta_stripe_rect_width, config.BAR_INNER_HEIGHT) # Delta label self._update_delta_label(time_delta, delta_label_position, bar_moves)
def colorTyres(temp): global TYREINFO hue = (TYREINFO.optimal_temp + 0.5 * temp_range - temp) / temp_range * 240 if hue < 0: hue = 0 elif hue > 240: hue = 240 r, g, b = hsv2rgb(hue, 1, 0.8) ac.glColor4f(r, g, b, 1)
def drawBrakeGauge(): global posting, post_time_elapsed, post_total_time inner_min_rad = math.asin((brake_gauge_root_y-brake_gauge_min_y)/brake_gauge_inner_radius) inner_max_rad = math.asin((brake_gauge_root_y-brake_gauge_max_y)/brake_gauge_inner_radius) outer_min_rad = math.asin((brake_gauge_root_y-brake_gauge_min_y)/brake_gauge_outer_radius) outer_max_rad = math.asin((brake_gauge_root_y-brake_gauge_max_y)/brake_gauge_outer_radius) for i in range(0,int((ac.getCarState(0,acsys.CS.Brake))*100),1): # p1 = inner, p2 = outer # p3 = inner, p4 = outer rad1 = (inner_max_rad-inner_min_rad)/100*i + inner_min_rad + (math.pi if brake_gauge_right else 0) rad2 = (outer_max_rad-outer_min_rad)/100*i + outer_min_rad + (math.pi if brake_gauge_right else 0) rad3 = (inner_max_rad-inner_min_rad)/100*(i+1) + inner_min_rad + (math.pi if brake_gauge_right else 0) rad4 = (outer_max_rad-outer_min_rad)/100*(i+1) + outer_min_rad + (math.pi if brake_gauge_right else 0) p1_x = math.cos(rad1)*brake_gauge_inner_radius + brake_gauge_root_x p1_y = brake_gauge_root_y - math.sin(rad1)*brake_gauge_inner_radius p2_x = math.cos(rad2)*brake_gauge_outer_radius + brake_gauge_root_x p2_y = brake_gauge_root_y - math.sin(rad2)*brake_gauge_outer_radius p3_x = math.cos(rad3)*brake_gauge_inner_radius + brake_gauge_root_x p3_y = brake_gauge_root_y - math.sin(rad3)*brake_gauge_inner_radius p4_x = math.cos(rad4)*brake_gauge_outer_radius + brake_gauge_root_x p4_y = brake_gauge_root_y - math.sin(rad4)*brake_gauge_outer_radius ac.glBegin(2) ac.glColor4f(brake_gauge_color[0],brake_gauge_color[1],brake_gauge_color[2],brake_gauge_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p3_x,p3_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(brake_gauge_color[0],brake_gauge_color[1],brake_gauge_color[2],brake_gauge_color[3]) ac.glVertex2f(p3_x,p3_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p4_x,p4_y) ac.glEnd()
def drawLinePlot(self, colourFades, dataPoints): ac.glBegin(1) for dataPoint, colour in zip(dataPoints, colourFades): ac.glColor4f(*colour) x, y = self.gPlotter.plotG(dataPoint['x'], dataPoint['z']) ac.glVertex2f(x, y) ac.glEnd()
def donut(x: int, y: int, r: int, w: int, start: int = 0, stop: int = 360, color: Color = Color(1, 1, 1, 1), filled: bool = True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glBegin(2) else: ac.glBegin(1) sample = (stop - start) / (36 * r) while start <= stop: rad1 = start rad2 = min(start + 1, stop) ac.glVertex2f(x + cos(rad1) * r, y - sin(rad1) * r) ac.glVertex2f(x + cos(rad2) * r, y - sin(rad2) * r) ac.glVertex2f(x + cos(rad1) * (r - w), y - sin(rad1) * (r - w)) ac.glVertex2f(x + cos(rad2) * (r - w), y - sin(rad2) * (r - w)) if filled: ac.glVertex2f(x + cos(rad2) * r, y - sin(rad2) * r) ac.glVertex2f(x + cos(rad1) * (r - w), y - sin(rad1) * (r - w)) start += sample ac.glEnd()
def onWindowRender(deltaT): global flag_textures flag_value = info.graphics.flag texture_id = flag_textures[flag_value] ac.glColor4f(1.0, 1.0, 1.0, FLAG_BACKGROUND_OPACITY) ac.glQuadTextured(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, texture_id)
def circle(x: int, y: int, radius: int, color: Color = Color(1, 1, 1, 1), filled: bool = True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glBegin(2) else: ac.glBegin(1) start = 0 stop = 360 sample = 36 * radius while start <= stop: rad1 = start rad2 = min(start + 1, stop) ac.glVertex2f(x + cos(rad1) * radius, y - sin(rad1) * radius) ac.glVertex2f(x + cos(rad2) * radius, y - sin(rad2) * radius) if filled: ac.glVertex2f(x, y) start += sample ac.glEnd()
def draw(self, data): # Calculates the current suspension travel in percentage. travel = (data.susp_t / data.susp_m_t) if data.susp_m_t > 0.0 else 0.5 # Keeps only the last 60 values. self.__last_values.append(travel) self.__last_values = self.__last_values[-60:] # Use the last 60 values to check if the suspension was maxed/'mined' out. maxed = max(self.__last_values) mined = min(self.__last_values) if maxed > 0.95 or mined < 0.05: self._back.color = Colors.red elif maxed > 0.90 or mined < 0.1: self._back.color = Colors.yellow else: self._back.color = Colors.blue if data.susp_v else Colors.white self._draw(Suspension.texture_id) # Initial padding is 10x44 rect = copy.copy(self._box.rect) rect[0] += 10 * self.__mult rect[1] += 44 * self.__mult rect[2] -= 20 * self.__mult rect[3] -= 88 * self.__mult # 100% # Why there is negative and above maximum numbers, KUNOS??? rect[3] = min(rect[3], max(0.0, rect[3] * (1.0 - travel))) ac.glColor4f(*self._back.color) ac.glQuad(*rect)
def drawLinePlot(self, colourFades, dataPoints): ac.glBegin(1) for dataPoint, colour in zip(dataPoints, colourFades): ac.glColor4f(*colour) x, y = self.gPlotter.plotG(dataPoint['x'], dataPoint['z']) ac.glVertex2f(x,y) ac.glEnd()
def onFormRender(deltaT): global showWindowTitle, appWindowActivated, appWindow, dbgLabel, running if not running: return #Important: Other apps can alter the global ac.gl Color and Alpha; let's reset this to White ac.glColor4f(1, 1, 1, 1) #Show/Hide the title shortly after the app became visible if showWindowTitle: if (time.clock() - appWindowActivated > showTitle): showWindowTitle = False ac.setBackgroundOpacity(appWindow, 0) ac.setIconPosition(appWindow, -7000, -3000) ac.setTitle(appWindow, "") try: #we won't do all the calculations every time, so we have to sort out some frames. #But: We'll need the graphics stuff every single time, or we'll have flickering. But no worry, opengl is fast if timeForCalculationCame(): doCalculationStuff() #Now we draw the current cars on the minimap drawCars() except Exception as e: ac.log("helipicapew::onFormRender() %s" % e) #Important: We'll clean the color again, so we might not affect other apps ac.glColor4f(1, 1, 1, 1)
def drawClutchGauge(): global posting, post_time_elapsed, post_total_time inner_min_rad = math.asin((clutch_gauge_root_y-clutch_gauge_min_y)/clutch_gauge_inner_radius) inner_max_rad = math.asin((clutch_gauge_root_y-clutch_gauge_max_y+1)/clutch_gauge_inner_radius) outer_min_rad = math.asin((clutch_gauge_root_y-clutch_gauge_min_y)/clutch_gauge_outer_radius) outer_max_rad = math.asin((clutch_gauge_root_y-clutch_gauge_max_y+1)/clutch_gauge_outer_radius) for i in range(0,int((1-ac.getCarState(0,acsys.CS.Clutch))*100),1): # p1 = inner, p2 = outer # p3 = inner, p4 = outer rad1 = (inner_max_rad-inner_min_rad)/100*(100-i) - inner_max_rad + (math.pi if clutch_gauge_right else 0) rad2 = (outer_max_rad-outer_min_rad)/100*(100-i) - outer_max_rad + (math.pi if clutch_gauge_right else 0) rad3 = (inner_max_rad-inner_min_rad)/100*(100 - i+1) - inner_max_rad + (math.pi if clutch_gauge_right else 0) rad4 = (outer_max_rad-outer_min_rad)/100*(100 - i+1) - outer_max_rad + (math.pi if clutch_gauge_right else 0) p1_x = math.cos(rad1)*clutch_gauge_inner_radius + clutch_gauge_root_x p1_y = clutch_gauge_root_y - math.sin(rad1)*clutch_gauge_inner_radius p2_x = math.cos(rad2)*clutch_gauge_outer_radius + clutch_gauge_root_x p2_y = clutch_gauge_root_y - math.sin(rad2)*clutch_gauge_outer_radius p3_x = math.cos(rad3)*clutch_gauge_inner_radius + clutch_gauge_root_x p3_y = clutch_gauge_root_y - math.sin(rad3)*clutch_gauge_inner_radius p4_x = math.cos(rad4)*clutch_gauge_outer_radius + clutch_gauge_root_x p4_y = clutch_gauge_root_y - math.sin(rad4)*clutch_gauge_outer_radius ac.glBegin(2) ac.glColor4f(clutch_gauge_color[0],clutch_gauge_color[1],clutch_gauge_color[2],clutch_gauge_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p3_x,p3_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(clutch_gauge_color[0],clutch_gauge_color[1],clutch_gauge_color[2],clutch_gauge_color[3]) ac.glVertex2f(p3_x,p3_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p4_x,p4_y) ac.glEnd()
def draw_triangle(points, color=[1, 1, 1]): r, g, b = color ac.glColor4f(r, g, b, 1) ac.glBegin(acsys.GL.Triangles) for x_y_tuple in points: x, y = x_y_tuple ac.glVertex2f(x, y) ac.glEnd()
def draw(self): """ Draws all info on screen. """ ac.setBackgroundOpacity(self.__window_id, 0.0) for component in self.__components: if self.__options[type(component).__name__] == True: ac.glColor4f(*Colors.white) component.draw(self.__data) ac.glColor4f(*Colors.white)
def drawTire(self, suspX, suspY, suspH, flip=False): global Options try: x = self.xPosition + 25 y = self.yPosition #~ rad = self.value * Options["radScale"] #~ rad = self.value * Options["radScale"] / (2 * -Options["targetCamber"]) rad = self.value if flip: #~ x = self.xPosition + 50 rad = math.pi - rad ac.glColor4f(self.color['r'], self.color['g'], self.color['b'], self.color['a']) h = Options["tireHeight"] w = h / 2 cosrad = math.cos(rad) sinrad = math.sin(rad) halfpi = math.pi / 2 if flip: cosradnorm = math.cos(rad + halfpi) sinradnorm = math.sin(rad + halfpi) # Have to draw counterclockwise ac.glBegin(acsys.GL.Quads) ac.glVertex2f(x, y) ac.glVertex2f(x + h * cosradnorm, y + h * sinradnorm) ac.glVertex2f(x + w * cosrad + h * cosradnorm, y + w * sinrad + h * sinradnorm) ac.glVertex2f(x + w * cosrad, y + w * sinrad) ac.glEnd() else: cosradnorm = math.cos(rad - halfpi) sinradnorm = math.sin(rad - halfpi) # Have to draw counterclockwise ac.glBegin(acsys.GL.Quads) ac.glVertex2f(x, y) ac.glVertex2f(x + w * cosrad, y + w * sinrad) ac.glVertex2f(x + w * cosrad + h * cosradnorm, y + w * sinrad + h * sinradnorm) ac.glVertex2f(x + h * cosradnorm, y + h * sinradnorm) ac.glEnd() # Suspension bits ac.glColor4f(0.9, 0.9, 0.9, 0.9) ac.glBegin(acsys.GL.Lines) ac.glVertex2f(x + (h / 2 - suspH) * cosradnorm, y + (h / 2 - suspH) * sinradnorm) ac.glVertex2f(suspX, suspY + suspH) ac.glVertex2f(x + (h / 2 + suspH) * cosradnorm, y + (h / 2 + suspH) * sinradnorm) ac.glVertex2f(suspX, suspY - suspH) ac.glEnd() except Exception: ac.log("CamberExtravaganza ERROR: drawTire(): %s" % traceback.format_exc())
def draw_colored_bars_with_points(slip, tyre): global max_slip, rectangle_corners r, g, b = get_color(slip) ac.glColor4f(r, g, b, 1) ac.glBegin(acsys.GL.Quads) for corner in rectangle_corners: x, y = tyre[corner] ac.glVertex2f(x, y) ac.glEnd()
def update(self): """ Updates the engine information. """ self.__data.update(self.__info) if self.__options["Logging"] == True: self.__data_log.append(copy.copy(self.__data)) for component in self.__components: ac.glColor4f(*Colors.white) component.update(self.__data)
def draw_bar(points, color=[1, 1, 1]): global rectangle_corners r, g, b = color ac.glColor4f(r, g, b, 1) ac.glBegin(acsys.GL.Quads) for corner in rectangle_corners: x, y = points[corner] ac.glVertex2f(x, y) ac.glEnd()
def draw(self, data, delta_t: float) -> None: dirt = data.tire_d * self.__mult rect = copy.copy(self._box.rect) rect[1] += (rect[3] - dirt) rect[3] = dirt ac.glColor4f(*Colors.brown) ac.glQuad(*rect)
def draw(self, delta_t: float) -> None: """ Draws all info on screen. """ ac.setBackgroundOpacity(self.__window_id, 0.0) for component in self.__components: if self.__options[type(component).__name__] == True: ac.glColor4f(*Colors.white) component.draw(self.__data, delta_t) else: component.clear() ac.glColor4f(*Colors.white)
def drawboostBars(x, y): ac.glColor4f(1, 0.31, 0, 1) ac.glQuad(0, 42, percentage_boost * 4.35, 8) #ac.glQuad(960,42,-percentage_boost*4.35,8) ac.glBegin(acsys.GL.Quads) ac.glVertex2f(960, 42) ac.glVertex2f(960 - percentage_boost * 4.35, 42) ac.glVertex2f(960 - percentage_boost * 4.35, 50) ac.glVertex2f(960, 50) ac.glEnd()
def drawboostBars(x,y): ac.glColor4f(1,0.31,0,1) ac.glQuad(0,42,percentage_boost*4.35,8) #ac.glQuad(960,42,-percentage_boost*4.35,8) ac.glBegin(acsys.GL.Quads) ac.glVertex2f(960,42) ac.glVertex2f(960-percentage_boost*4.35,42) ac.glVertex2f(960-percentage_boost*4.35,50) ac.glVertex2f(960,50) ac.glEnd()
def polygon(points, color=Color(1, 1, 1, 1), filled=True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glBegin(2) else: ac.glBegin(1) for i in points: if isinstance(i, Point): ac.glVertex2f(i.x, i.y) ac.glEnd()
def texture_rect(x: int, y: int, w: int, h: int, color: Color, tex_id: int = -1, tex: Texture = None): ac.glColor4f(color.r, color.g, color.b, color.a) if tex_id != -1: ac.glQuadTextured(x, y, w, h, tex_id) elif tex: ac.glQuadTextured(x, y, w, h, tex.texture)
def drawGMeter(): global posting, post_time_elapsed, post_total_time # Colors c1 = [0.0,200/255,1.0,g_meter_opacity] # Middle one c2 = [0.0,150/255,1.0,g_meter_opacity] # Inner c3 = [0.0,125/255,1.0,g_meter_opacity] # Middle inner c4 = [0.0,100/255,1.0,g_meter_opacity] # Outer g = ac.getCarState(0,acsys.CS.AccG)[0] # Neg range: 660..511 # Pos range: 660..809 l_x = r_x = 0 pixels = int(abs(g)*(g_meter_range/2.52)) if abs(g) >= 2.52: pixels = g_meter_range # ALL OF THEM if g < 0: r_x = g_meter_x_anchor l_x = r_x - pixels else: l_x = g_meter_x_anchor r_x = l_x + pixels t_y = g_meter_y_anchor for i in range(0,11,1): c = [] offset = 0 if i == 0 or i == 1 or i == 9 or i == 10: c = c4 offset = 4 elif i == 2 or i == 8: c = c3 offset = 2 elif i == 3 or i == 7: c = c3 offset = 1 elif i == 4 or i == 6: c = c2 offset = 1 else: c = c1 if g > 0 and r_x - offset <= l_x: continue elif g < 0 and l_x + offset >= r_x: continue l_offset = r_offset = 0 if g > 0: r_offset = - offset if g < 0: l_offset = offset ac.glBegin(0) ac.glColor4f(c[0],c[1],c[2],c[3]) ac.glVertex2f(l_x+l_offset,t_y+i) ac.glVertex2f(r_x+r_offset,t_y+i) ac.glEnd()
def draw(self, rect, texture_id=None) -> None: """ Draws the box background. """ if self.size > 0.0 and self.border[3] > 0.0: twice = self.size * 2.0 ac.glColor4f(*self.border) ac.glQuad(rect[0] - self.size, rect[1] - self.size, rect[2] + twice, rect[3] + twice) ac.glColor4f(*self.color) if texture_id is None: ac.glQuad(*rect) else: ac.glQuadTextured(rect[0], rect[1], rect[2], rect[3], texture_id)
def quad(x: int, y: int, w: int, h: int, colors=None, r=None): if type(colors) == list: ac.glBegin(3) if len(colors) >= 1: c = colors[0] ac.glColor4f(c.r, c.g, c.b, c.a) if r is not None: ac.glVertex2f(r.x, r.y) else: ac.glVertex2f(x, y) if len(colors) >= 2: c = colors[1] ac.glColor4f(c.r, c.g, c.b, c.a) if r is not None: ac.glVertex2f(r.x, r.y + r.h) else: ac.glVertex2f(x, y + h) if len(colors) >= 3: c = colors[2] ac.glColor4f(c.r, c.g, c.b, c.a) if r is not None: ac.glVertex2f(r.x + r.w, r.y + r.h) else: ac.glVertex2f(x + w, y + h) if len(colors) >= 4: c = colors[3] ac.glColor4f(c.r, c.g, c.b, c.a) if r is not None: ac.glVertex2f(r.x + r.w, r.y) else: ac.glVertex2f(x + w, y) ac.glEnd()
def drawYourself(self): global colorRecipeList # 配色 recipe = colorRecipeList[self.colorRecipe] ac.glColor4f(1, 1, 1, self.maxOpacity * maxiumAlpha) ac.glBegin(3) # 3 : Draw quads. # 先画底框(被车框覆盖后就会留下边线) ac.glColor4f(recipe[2][0], recipe[2][1], recipe[2][2], self.maxOpacity * maxiumAlpha) for i, pt in enumerate(self.guiBorderPtList): ac.glVertex2f(pt.x, pt.y) ac.glEnd() # 再画车框 ac.glBegin(3) # 3 : Draw quads. #ac.log('helipicapew::drawYourself car paint pt list:-----------') for i, pt in enumerate(self.guiPtList): #ac.log('helipicapew::drawYourself tyre index: {}, pt: {} {}'.format(pt.partIndex, pt.x, pt.y)) # 根据点代表的轮胎位置更新颜色设置 if pt.partIndex == 0 or pt.partIndex == 1: ac.glColor4f(recipe[0][0], recipe[0][1], recipe[0][2], self.maxOpacity * maxiumAlpha) else: ac.glColor4f(recipe[1][0], recipe[1][1], recipe[1][2], self.maxOpacity * maxiumAlpha) ac.glVertex2f(pt.x, pt.y) ac.glEnd()
def draw(self, data, delta_t: float) -> None: rect = self._box.rect camber = data.camber tan = math.tan(camber) * rect[2] tan_left = -(tan if camber < 0.0 else 0.0) tan_right = tan if camber > 0.0 else 0.0 ac.glBegin(acsys.GL.Quads) ac.glColor4f(*Colors.white) ac.glVertex2f(rect[0], rect[1] + tan_left) ac.glVertex2f(rect[0], rect[1] + rect[3]) ac.glVertex2f(rect[0] + rect[2], rect[1] + rect[3]) ac.glVertex2f(rect[0] + rect[2], rect[1] + tan_right) ac.glEnd()
def drawIndicators(maxIndicatorL, maxIndicatorR, alpha): if helipicapewcar.showIndicators and alpha > 0: #left side if maxIndicatorL == 1: ac.glColor4f(indicator1Colors[0], indicator1Colors[1], indicator1Colors[2], alpha) #yellow ac.glQuadTextured(0, helipicapewcar.yOff * z - 152 * z / 2, 100 * z, 152 * z, texture_indicator_left) elif maxIndicatorL == 2: ac.glColor4f(indicator2Colors[0], indicator2Colors[1], indicator2Colors[2], alpha) #orange ac.glQuadTextured(0, helipicapewcar.yOff * z - 152 * z / 2, 100 * z, 152 * z, texture_indicator_left) #right side if maxIndicatorR == 1: ac.glColor4f(indicator1Colors[0], indicator1Colors[1], indicator1Colors[2], alpha) #yellow ac.glQuadTextured(helipicapewcar.xOff * z, helipicapewcar.yOff * z - 152 * z / 2, 100 * z, 152 * z, texture_indicator_right) elif maxIndicatorR == 2: ac.glColor4f(indicator2Colors[0], indicator2Colors[1], indicator2Colors[2], alpha) #orange ac.glQuadTextured(helipicapewcar.xOff * z, helipicapewcar.yOff * z - 152 * z / 2, 100 * z, 152 * z, texture_indicator_right)
def drawrpmBars(x,y): if(abs(percentage_rpm)<max_user_rpm):ac.glColor4f(1,1,1,1) if(abs(percentage_rpm)>max_user_rpm):ac.glColor4f(1,0,0,1) if(percentage_rpm <min_user_rpm): ac.glQuad(0,20,0,20) ac.glQuad(960,20,0,20) if(percentage_rpm >min_user_rpm): ac.glQuad(0,20,abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm),20) #ac.glQuad(960,20,-(abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm)),20) ac.glBegin(acsys.GL.Quads) ac.glVertex2f(960,20) ac.glVertex2f(960-abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm),20) ac.glVertex2f(960-abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm),40) ac.glVertex2f(960, 40) ac.glEnd()
def rect(x, y, w, h, color=Color(1, 1, 1, 1), filled=True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glQuad(x, y, w, h) else: ac.glBegin(1) ac.glVertex2f(x, y) ac.glVertex2f(x + w, y) ac.glVertex2f(x + w, y) ac.glVertex2f(x + w, y + h) ac.glVertex2f(x + w, y + h) ac.glVertex2f(x, y + h) ac.glVertex2f(x, y + h) ac.glVertex2f(x, y) ac.glEnd()
def draw(self, data, delta_t: float) -> None: self._draw() rpm = data.rpm ratio = min(rpm / data.max_rpm, 1.0) bar = copy.copy(self._box.rect) bar[2] *= ratio color = self.__calc.interpolate_color(rpm) ac.glColor4f(*color) ac.glQuad(*bar) ac.setFontColor(self.__lb, color[0], color[1], color[2], color[3]) ac.setText(self.__lb, "{} RPM".format(rpm))
def drawSpeedometer(): speed = ac.getCarState(0,acsys.CS.DriveTrainSpeed)/dt_ratio #Drivetrain speed seems to be about 75-90% of the real speed wtf if imperial: speed = speed / 1.632 # degree range: 190..-10 r = abs(speedo_min_angle - speedo_max_angle) speed_deg = speedo_max_angle - (speed/indicated_max_speed)*r speed_rad = math.radians(speed_deg) for i in range(0,indicated_max_speed+1,5): if i % 20 == 0: rad = math.radians(speedo_max_angle - (i/indicated_max_speed)*r) p1_x = math.cos(rad)*speedo_radius+speed_pivot_x p1_y = -math.sin(rad)*speedo_radius+speed_pivot_y p2_x = math.cos(rad)*(speedo_radius*4/5)+speed_pivot_x p2_y = -math.sin(rad)*(speedo_radius*4/5)+speed_pivot_y ac.glBegin(0) ac.glColor4f(speedo_bigline_color[0],speedo_bigline_color[1],speedo_bigline_color[2],speedo_bigline_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glEnd() elif i % 5 == 0 and i != 0: rad = math.radians(speedo_max_angle - (i/indicated_max_speed)*r) p1_x = math.cos(rad)*speedo_radius+speed_pivot_x p1_y = -math.sin(rad)*speedo_radius+speed_pivot_y p2_x = math.cos(rad)*(speedo_radius*9.25/10)+speed_pivot_x p2_y = -math.sin(rad)*(speedo_radius*9.25/10)+speed_pivot_y ac.glBegin(0) ac.glColor4f(speedo_smallline_color[0],speedo_smallline_color[1],speedo_smallline_color[2],speedo_smallline_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glEnd() # Needle speed_x = math.cos(speed_rad)*(speedo_radius-3)+speed_pivot_x speed_y = -math.sin(speed_rad)*(speedo_radius-3)+speed_pivot_y speed_end_x = math.cos(speed_rad+math.pi)*speedo_needle_end+speed_pivot_x speed_end_y = -math.sin(speed_rad+math.pi)*speedo_needle_end+speed_pivot_y speed_p1_x = speed_x + math.cos(speed_rad-math.pi/2)*1.5 speed_p1_y = speed_y - math.sin(speed_rad-math.pi/2)*1.5 speed_p2_x = speed_x + math.cos(speed_rad+math.pi/2)*1.5 speed_p2_y = speed_y - math.sin(speed_rad+math.pi/2)*1.5 speed_end_p1_x = speed_end_x + math.cos(speed_rad+math.pi/2)*3 speed_end_p1_y = speed_end_y - math.sin(speed_rad+math.pi/2)*3 speed_end_p2_x = speed_end_x + math.cos(speed_rad-math.pi/2)*3 speed_end_p2_y = speed_end_y - math.sin(speed_rad-math.pi/2)*3 ac.glBegin(2) ac.glColor4f(speedo_needle_color1[0],speedo_needle_color1[1],speedo_needle_color1[2],speedo_needle_color1[3]) ac.glVertex2f(speed_p1_x,speed_p1_y) ac.glVertex2f(speed_end_p1_x,speed_end_p1_y) ac.glVertex2f(speed_end_p2_x,speed_end_p2_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(speedo_needle_color1[0],speedo_needle_color1[1],speedo_needle_color1[2],speedo_needle_color1[3]) ac.glVertex2f(speed_p1_x,speed_p1_y) ac.glVertex2f(speed_end_p2_x,speed_end_p2_y) ac.glVertex2f(speed_p2_x,speed_p2_y) ac.glEnd()
def drawNeedle(delta_t): speed = ac.getCarState(0, acsys.CS.SpeedKMH) if limited and speed > speedMaximum: speed = speedMaximum radValue = speed / speedMaximum * radRange + radStartingPoint dx = math.sin(radValue) dy = math.cos(radValue) tx = halfWidth - dx * halfWidth ty = halfHeight + dy * halfHeight ax = dx * halfArrowWidth ay = dy * halfArrowWidth ac.glColor4f(1.0, 0.2, 0.2, 0.8) # color ac.glBegin(acsys.GL.Quads) ac.glVertex2f(halfWidth + ay, halfHeight + ax) ac.glVertex2f(halfWidth - ay, halfHeight - ax) ac.glVertex2f(tx - ay, ty - ax) ac.glVertex2f(tx + ay, ty + ax) ac.glEnd()
def drawCars(): global hSession #The whole appearance is dependent on the highest alpha setting of the near cars, #so we need to figure that one out. As we already iterate we also get the indicator values maxOpacity = 0.0 maxIndicatorL = 0 maxIndicatorR = 0 for c in hSession.nearcars: if c.maxOpacity > maxOpacity: maxOpacity = c.maxOpacity if c.overlapIndicatorL > maxIndicatorL: maxIndicatorL = c.overlapIndicatorL if c.overlapIndicatorR > maxIndicatorR: maxIndicatorR = c.overlapIndicatorR #nothing to draw is nothing to draw if maxOpacity == 0.0: return #First: Draw background. It's dependent on the setting as well as the maximum alpha value if showBackgroundPic == 1: ac.glColor4f(1, 1, 1, maxOpacity) ac.glQuadTextured(0, 0, 200 * z, 200 * z, texture_radar) #basicall we iterate all the (near) cars and try to draw points or #whatever shapes of them - relative to the player's position and direction #first we check wether to show any indicators if helipicapewcar.showIndicators: drawIndicators(maxIndicatorL, maxIndicatorR, maxOpacity) if showCars: #then we draw all near cars for c in hSession.nearcars: c.drawYourself() # then we'll draw the players car at the center. hSession.player.maxOpacity = maxOpacity hSession.player.drawYourself()
def drawOdometer(): global posting root_x = speed_pivot_x - 48 root_y = speed_pivot_y - 50 fg = odometer_fg bg = odometer_bg distance = sim_info.graphics.distanceTraveled/1000 if imperial: distance = distance / 1.632 s = "%3.1f" % (sim_info.graphics.distanceTraveled/1000) # zero-padding while len(s) < 5: s = "0" + s i = 0 for c in s: if c != '.': drawNineSegment(root_x+96-24*(4-i),root_y,24,36,c,fg,bg) i = i + 1 # Decimal point ac.glColor4f(0.0,0.0,0.0,1.0) ac.glQuad(root_x+48+22,root_y+30,4,4)
def onFormRender(deltaT): kersValue = ac.getCarState(0, acsys.CS.KersCharge) usage = getErsCurrent() / getERSMax() ac.glColor4f(255, 255, 255, 0.4) ac.glQuad(300, 90, 40, 100) ac.glColor4f(0, 255, 0, 0.5) ac.glQuad(300, 90 - ((100 * kersValue) - 100), 40, (100 * kersValue)) ac.glColor4f(255, 255, 255, 0.4) ac.glQuad(400, 90, 40, 100) ac.glColor4f(0, 0, 255, 0.5) ac.glQuad(400, 90 - ((100 * usage) - 100), 40, (100 * usage))
def drawrpmBars(x, y): if (abs(percentage_rpm) < max_user_rpm): ac.glColor4f(1, 1, 1, 1) if (abs(percentage_rpm) > max_user_rpm): ac.glColor4f(1, 0, 0, 1) if (percentage_rpm < min_user_rpm): ac.glQuad(0, 20, 0, 20) ac.glQuad(960, 20, 0, 20) if (percentage_rpm > min_user_rpm): ac.glQuad( 0, 20, abs(percentage_rpm - min_user_rpm) * 435 / (100 - min_user_rpm), 20) #ac.glQuad(960,20,-(abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm)),20) ac.glBegin(acsys.GL.Quads) ac.glVertex2f(960, 20) ac.glVertex2f( 960 - abs(percentage_rpm - min_user_rpm) * 435 / (100 - min_user_rpm), 20) ac.glVertex2f( 960 - abs(percentage_rpm - min_user_rpm) * 435 / (100 - min_user_rpm), 40) ac.glVertex2f(960, 40) ac.glEnd()
def draw(self): if self.color is not None: ac.glColor4f(*self.color) ac.glQuadTextured(self.pos_x, self.pos_y, self.width, self.height, self.id)
def drawBoostGauge(): global max_boost boost = ac.getCarState(0,acsys.CS.TurboBoost) if boost > max_boost: max_boost = boost rad = (boost/max_boost)*math.pi # 180 deg range so it's easy outer_radius = boost_radius inner_radius = outer_radius - 4 for i in range(0,int((boost/max_boost)*100),1): # p3 p4 - rad2 # p1 p2 - rad1 rad1 = math.pi - math.pi*(i/100) rad2 = math.pi - math.pi*((i+1)/100) p1_x = math.cos(rad1)*outer_radius + boost_pivot_x p1_y = boost_pivot_y - math.sin(rad1)*outer_radius p2_x = math.cos(rad1)*inner_radius + boost_pivot_x p2_y = boost_pivot_y - math.sin(rad1)*inner_radius p3_x = math.cos(rad2)*outer_radius + boost_pivot_x p3_y = boost_pivot_y - math.sin(rad2)*outer_radius p4_x = math.cos(rad2)*inner_radius + boost_pivot_x p4_y = boost_pivot_y - math.sin(rad2)*inner_radius ac.glBegin(2) ac.glColor4f(boost_bar_color[0],boost_bar_color[1],boost_bar_color[2],boost_bar_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p3_x,p3_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(boost_bar_color[0],boost_bar_color[1],boost_bar_color[2],boost_bar_color[3]) ac.glVertex2f(p3_x,p3_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p4_x,p4_y) ac.glEnd() # Needle rad = math.pi - rad bigend_x = math.cos(rad)*boost_radius + boost_pivot_x bigend_y = boost_pivot_y - math.sin(rad)*boost_radius littleend_x = math.cos(rad+math.pi)*boost_needle_end + boost_pivot_x littleend_y = boost_pivot_y - math.sin(rad+math.pi)*boost_needle_end # p1 p2 = big end # p3 p4 = little end p1_x = math.cos(rad+math.pi/2) + bigend_x p1_y = bigend_y - math.sin(rad+math.pi/2) p2_x = math.cos(rad-math.pi/2) + bigend_x p2_y = bigend_y - math.sin(rad-math.pi/2) p3_x = math.cos(rad+math.pi/2) + littleend_x p3_y = littleend_y - math.sin(rad+math.pi/2) p4_x = math.cos(rad-math.pi/2) + littleend_x p4_y = littleend_y - math.sin(rad-math.pi/2) ac.glBegin(2) ac.glColor4f(boost_needle_color[0],boost_needle_color[1],boost_needle_color[2],boost_needle_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p3_x,p3_y) ac.glVertex2f(p4_x,p4_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(boost_needle_color[0],boost_needle_color[1],boost_needle_color[2],boost_needle_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p4_x,p4_y) ac.glVertex2f(p2_x,p2_y) ac.glEnd()
def drawTachometer(deltaT): rpm = ac.getCarState(0,acsys.CS.RPM) # degree range: 190..-10 r = abs(tach_min_angle - tach_max_angle) rpm_deg = tach_max_angle - (rpm/indicated_max_rpm)*r rpm_rad = math.radians(rpm_deg) # Redline redline_start = (max_rpm - 500) - (max_rpm % 250) for i in range(0,indicated_max_rpm+1,250): if i >= redline_start and i+250 <= indicated_max_rpm: rad1 = math.radians(tach_max_angle - (i/indicated_max_rpm)*r) rad2 = math.radians(tach_max_angle - ((i+250)/indicated_max_rpm)*r) p1_x = math.cos(rad1)*tach_radius+rpm_pivot_x p1_y = -math.sin(rad1)*tach_radius+rpm_pivot_y p2_x = math.cos(rad1)*(tach_radius*9/10)+rpm_pivot_x p2_y = -math.sin(rad1)*(tach_radius*9/10)+rpm_pivot_y p3_x = math.cos(rad2)*tach_radius+rpm_pivot_x p3_y = -math.sin(rad2)*tach_radius+rpm_pivot_y p4_x = math.cos(rad2)*(tach_radius*9/10)+rpm_pivot_x p4_y = -math.sin(rad2)*(tach_radius*9/10)+rpm_pivot_y ac.glBegin(2) ac.glColor4f(tach_redline_color[0],tach_redline_color[1],tach_redline_color[2],tach_redline_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p3_x,p3_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(tach_redline_color[0],tach_redline_color[1],tach_redline_color[2],tach_redline_color[3]) #ac.glColor4f(1,1,1,1) ac.glVertex2f(p3_x,p3_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p4_x,p4_y) ac.glEnd() if i % 1000 == 0: rad = math.radians(tach_max_angle - (i/indicated_max_rpm)*r) p1_x = math.cos(rad)*tach_radius+rpm_pivot_x p1_y = -math.sin(rad)*tach_radius+rpm_pivot_y p2_x = math.cos(rad)*(tach_radius*4/5)+rpm_pivot_x p2_y = -math.sin(rad)*(tach_radius*4/5)+rpm_pivot_y ac.glBegin(0) ac.glColor4f(tach_bigline_color[0],tach_bigline_color[1],tach_bigline_color[2],tach_bigline_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glEnd() elif i % 250 == 0 and i != 0: rad = math.radians(tach_max_angle - (i/indicated_max_rpm)*r) p1_x = math.cos(rad)*tach_radius+rpm_pivot_x p1_y = -math.sin(rad)*tach_radius+rpm_pivot_y p2_x = math.cos(rad)*(tach_radius*9.25/10)+rpm_pivot_x p2_y = -math.sin(rad)*(tach_radius*9.25/10)+rpm_pivot_y ac.glBegin(0) ac.glColor4f(tach_smallline_color[0],tach_smallline_color[1],tach_smallline_color[2],tach_smallline_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glEnd() # Needle rpm_x = math.cos(rpm_rad)*(tach_radius-3)+rpm_pivot_x rpm_y = -math.sin(rpm_rad)*(tach_radius-3)+rpm_pivot_y rpm_end_x = math.cos(rpm_rad+math.pi)*tach_needle_end+rpm_pivot_x rpm_end_y = -math.sin(rpm_rad+math.pi)*tach_needle_end+rpm_pivot_y rpm_p1_x = rpm_x + math.cos(rpm_rad-math.pi/2)*1.5 rpm_p1_y = rpm_y - math.sin(rpm_rad-math.pi/2)*1.5 rpm_p2_x = rpm_x + math.cos(rpm_rad+math.pi/2)*1.5 rpm_p2_y = rpm_y - math.sin(rpm_rad+math.pi/2)*1.5 rpm_end_p1_x = rpm_end_x + math.cos(rpm_rad-math.pi/2)*3 rpm_end_p1_y = rpm_end_y - math.sin(rpm_rad-math.pi/2)*3 rpm_end_p2_x = rpm_end_x + math.cos(rpm_rad+math.pi/2)*3 rpm_end_p2_y = rpm_end_y - math.sin(rpm_rad+math.pi/2)*3 ac.glBegin(2) ac.glColor4f(tach_needle_color1[0],tach_needle_color1[1],tach_needle_color1[2],tach_needle_color1[3]) ac.glVertex2f(rpm_p1_x,rpm_p1_y) ac.glVertex2f(rpm_p2_x,rpm_p2_y) ac.glVertex2f(rpm_end_p1_x,rpm_end_p1_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(tach_needle_color1[0],tach_needle_color1[1],tach_needle_color1[2],tach_needle_color1[3]) #ac.glColor4f(1,1,1,1) ac.glVertex2f(rpm_p2_x,rpm_p2_y) ac.glVertex2f(rpm_end_p2_x,rpm_end_p2_y) ac.glVertex2f(rpm_end_p1_x,rpm_end_p1_y) ac.glEnd()
def drawTyreMonitor(): global flt_label1, frt_label1, rlt_label1, rrt_label1 # Temp global flt_label2, frt_label2, rlt_label2, rrt_label2 # Pressure fl_t, fr_t, rl_t, rr_t = ac.getCarState(0,acsys.CS.CurrentTyresCoreTemp) temps = [fl_t, fr_t, rl_t, rr_t] fl_p, fr_p, rl_p, rr_p = ac.getCarState(0,acsys.CS.DynamicPressure) wheelslip = ac.getCarState(0,acsys.CS.TyreSlip) wear = sim_info.physics.tyreWear dirt = sim_info.physics.tyreDirtyLevel ac.setText(flt_label1,"%dC"%fl_t) ac.setText(frt_label1,"%dC"%fr_t) ac.setText(rlt_label1,"%dC"%rl_t) ac.setText(rrt_label1,"%dC"%rr_t) # Outside of tyre = white if normal, yellow if losing grip, red if lost grip for i in range(0,4): outside_color = [1.0,1.0,1.0,tyre_monitor_opacity] if wheelslip[i] >= 35000: outside_color = [1.0,0.0,0.0,tyre_monitor_opacity] elif wheelslip[i] >= 25000: percent = (int(wheelslip[i])-25000)/10000 outside_color = [1.0,(165 - 165*percent)/255,0.0,tyre_monitor_opacity] # Orange elif wheelslip[i] >= 10000: percent = (int(wheelslip[i])-10000)/15000 outside_color = [1.0,(255 - 90*percent)/255,0.0,tyre_monitor_opacity] elif wheelslip[i] > 7000: # 100% = [1.0,1.0,0.0,1.0] # 0% = [1.0,1.0,1.0,1.0] percent = (int(wheelslip[i])-7000)/3000 outside_color = [1.0,1.0,1-percent,tyre_monitor_opacity] root_x = tyre_mon_xpos root_y = tyre_mon_ypos if i == 1 or i == 3: root_x = root_x + 80 if i == 2 or i == 3: root_y = root_y + 96 ac.glColor4f(outside_color[0],outside_color[1],outside_color[2],outside_color[3]) ac.glQuad(root_x,root_y,36,4) ac.glQuad(root_x,root_y+4,4,56) ac.glQuad(root_x+32,root_y+4,4,56) ac.glQuad(root_x,root_y+60,36,4) # 28x56 # Dirty level ac.glColor4f(150/255,75/255,0.0,tyre_monitor_opacity) ac.glQuad(root_x+4,root_y+60,28,-(56*dirt[i]/5)) # Inside of tyre = blue if v. cold, light blue if cold, white if normal, yellow if hot, red if v. hot inside_color = [1.0,1.0,1.0,tyre_monitor_opacity] if temps[i] < (tyre_optimal_temp[0]-25): inside_color = [0.0,100.0/255,1.0,tyre_monitor_opacity] elif temps[i] < (tyre_optimal_temp[0]-10): percent = (-int(temps[i])+tyre_optimal_temp[0])/25 inside_color = [0.0,(255 - 155*percent)/255,1.0,tyre_monitor_opacity] elif temps[i] < tyre_optimal_temp[0]: percent = (tyre_optimal_temp[0]-int(temps[i]))/10 inside_color = [1-percent,1.0,1.0,tyre_monitor_opacity] elif int(temps[i]) in tyre_optimal_temp: inside_color = [1.0,1.0,1.0,tyre_monitor_opacity] elif temps[i] < (tyre_optimal_temp[-1]+15): percent = (int(temps[i])-tyre_optimal_temp[-1])/15 inside_color = [1.0,1.0,1-percent,tyre_monitor_opacity] elif temps[i] <= (tyre_optimal_temp[-1]+25): percent = (int(temps[i])-tyre_optimal_temp[-1]-15)/10 inside_color = [1.0,1-percent,0.0,tyre_monitor_opacity] else: # DANGER inside_color = [1.0,0.0,0.0,tyre_monitor_opacity] # no. of bars inside tyre = wear level bars = int(wear[i]/10) if bars > 9: bars = 9 for j in range(0,bars): ac.glColor4f(inside_color[0],inside_color[1],inside_color[2],inside_color[3]) ac.glQuad(root_x + 6,root_y + 54 - 6*j,24,4) ac.setText(flt_label2,"%d psi"%fl_p) ac.setText(frt_label2,"%d psi"%fr_p) ac.setText(rlt_label2,"%d psi"%rl_p) ac.setText(rrt_label2,"%d psi"%rr_p)
def drawNineSegment(x,y,x_size,y_size,digit,colors,background): # Background ac.glBegin(2) ac.glColor4f(background[0],background[1],background[2],background[3]) ac.glVertex2f(x,y) ac.glVertex2f(x+x_size,y+y_size) ac.glVertex2f(x+x_size,y) ac.glEnd() ac.glBegin(2) ac.glColor4f(background[0],background[1],background[2],background[3]) #ac.glColor4f(1,1,1,1) ac.glVertex2f(x,y+y_size) ac.glVertex2f(x+x_size,y+y_size) ac.glVertex2f(x,y) ac.glEnd() # 2px padding root_x = x + 2 root_y = y + 2 max_x = x + x_size - 2 max_y = y + y_size - 2 # Definitions (DIFFERENT FOR SEGMENTS 8 AND 9) segment_width = (max_y - root_y)/9 segment_height = (max_x - root_x)/6 i = 1 segment_dict = { '1' : [ False, True, True, False, False, False, False, False, False], '2' : [ True, True, False, True, True, False, True, False, False], '3' : [ True, True, True, True, False, False, True, False, False], '4' : [ False, True, True, False, False, True, True, False, False], '5' : [ True, False, True, True, False, True, True, False, False], '6' : [ True, False, True, True, True, True, True, False, False], '7' : [ True, True, True, False, False, True, False, False, False], '8' : [ True, True, True, True, True, True, True, False, False], '9' : [ True, True, True, True, False, True, True, False, False], '0' : [ True, True, True, True, True, True, False, False, False], 'N' : [ False, True, True, False, True, True, False, True, True], 'R' : [ True, True, False, False, True, True, True, False, True], '' : [ False, False, False, False, False, False, False, False, False]} segments = segment_dict.get(digit,[True, True, True, True, True, True, True, True, True]) for segment in segments: if segment: if i == 1 or i == 4 or i == 7: # horizontal segments l_x = segment_height + 1 t_y = 0 if i == 1: t_y = 1 elif i == 7: t_y = segment_width*4 + 1 elif i == 4: t_y = segment_width*8 + 1 r_x = l_x + segment_height*4 - 2 b_y = t_y + segment_width - 2 # left/right triangle vertexes lt_x = l_x - segment_height/2 + 1 tr_y = t_y + segment_width/2 - 1 rt_x = r_x + segment_height/2 - 1 # Adding the base coords l_x = l_x + root_x r_x = r_x + root_x t_y = t_y + root_y b_y = b_y + root_y lt_x = lt_x + root_x rt_x = rt_x + root_x tr_y = tr_y + root_y # Drawing the triangles # Left ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(lt_x,tr_y) ac.glVertex2f(l_x,b_y) ac.glVertex2f(l_x,t_y) ac.glEnd() # Right ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(rt_x,tr_y) ac.glVertex2f(r_x,t_y) ac.glVertex2f(r_x,b_y) ac.glEnd() # Middle top lt lb rt ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(l_x,t_y) ac.glVertex2f(l_x,b_y) ac.glVertex2f(r_x,t_y) ac.glEnd() # Middle bottom lb rt rb ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(l_x,b_y) ac.glVertex2f(r_x,b_y) ac.glVertex2f(r_x,t_y) ac.glEnd() elif i == 2 or i == 3 or i == 5 or i == 6: # (2 and 3) and (5 and 6) have same X coords # (2 and 6) and (3 and 5) have same Y coords l_x = r_x = t_y = b_y = tr_x = tt_y = bt_y = 0 # X coords if i == 2 or i == 3: l_x = segment_height*5 + 1 r_x = l_x + segment_height - 2 tr_x = segment_height*5 + (segment_height - 2)/2 + 1 elif i == 5 or i == 6: l_x = 1 r_x = l_x + segment_height - 2 tr_x = (segment_height - 2)/2 + 1 # Y coords if i == 2 or i == 6: t_y = segment_width + 1 b_y = segment_width*4 - 1 tt_y = t_y - (segment_width - 2)/2 + 1 bt_y = b_y + (segment_width - 2)/2 - 1 elif i == 3 or i == 5: t_y = segment_width*5 + 1 b_y = segment_width*8 - 1 tt_y = t_y - (segment_width - 2)/2 + 1 bt_y = b_y + (segment_width - 2)/2 - 1 # Adding the base coords l_x = l_x + root_x r_x = r_x + root_x t_y = t_y + root_y b_y = b_y + root_y tr_x = tr_x + root_x tt_y = tt_y + root_y bt_y = bt_y + root_y # Drawing the triangles # Top ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(tr_x,tt_y) ac.glVertex2f(l_x,t_y) ac.glVertex2f(r_x,t_y) ac.glEnd() # Bottom ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(l_x,b_y) ac.glVertex2f(tr_x,bt_y) ac.glVertex2f(r_x,b_y) ac.glEnd() # Middle top lt lb rt ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(l_x,t_y) ac.glVertex2f(l_x,b_y) ac.glVertex2f(r_x,t_y) ac.glEnd() # Middle bottom lb rt rb ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(l_x,b_y) ac.glVertex2f(r_x,b_y) ac.glVertex2f(r_x,t_y) ac.glEnd() elif i == 8: # Top diagonal t1_x = segment_height + segment_width/4 t2_x = segment_height t1_y = segment_width t2_y = t1_y + segment_width/4 b1_x = segment_height*3 b2_x = b1_x - segment_width/2 b_y = segment_width*4 # Adding the base t1_x = t1_x + root_x t2_x = t2_x + root_x t1_y = t1_y + root_y t2_y = t2_y + root_y b1_x = b1_x + root_x b2_x = b2_x + root_x b_y = b_y + root_y ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(t1_x,t1_y) ac.glVertex2f(t2_x,t2_y) ac.glVertex2f(b1_x,b_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(b2_x,b_y) ac.glVertex2f(b1_x,b_y) ac.glVertex2f(t2_x,t2_y) ac.glEnd() elif i == 9: # Bottom diagonal t_x = segment_height*5 t1_y = segment_width*8 - segment_width/2 t2_y = t1_y + segment_width/2 b1_x = segment_height*3 + segment_width/2 b2_x = b1_x - segment_width/2 b_y = segment_width*5 # Adding the base t_x = t_x + root_x t1_y = t1_y + root_y t2_y = t2_y + root_y b1_x = b1_x + root_x b2_x = b2_x + root_x b_y = b_y + root_y ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) ac.glVertex2f(t_x,t2_y) ac.glVertex2f(t_x,t1_y) ac.glVertex2f(b1_x,b_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(colors[0],colors[1],colors[2],colors[3]) #ac.glColor4f(1,1,1,1) ac.glVertex2f(b1_x,b_y) ac.glVertex2f(b2_x,b_y) ac.glVertex2f(t_x,t2_y) ac.glEnd() i = i + 1
def drawGrid(self, radius): ac.glColor4f(0.8, 0.8, 0.8, 0.7) self.drawCross(radius) ac.glColor4f(1.0, 1.0, 1.0, 0.9) self.drawCircumference(radius, {'x':0, 'z':0}) self.drawCircumference(radius/2, {'x':0, 'z':0})
def drawTyresDirt(x, y, w, h, dirt): ac.glColor4f(0.9, 0.6, 0.2, 1) ac.glQuad(x, y, w, -(10 * dirt))
def onWindowRender(deltaT): ac.log("Rendering window") global debug_label, indicated_max_rpm, max_rpm, indicated_max_speed, shift_light_drawn, sl_timer global tach_radius, rpm_pivot_x, rpm_pivot_y, speedo_radius, speed_pivot_x, speed_pivot_y global speedo_tl_x, speedo_tl_y, speedo_total_width, speedo_total_height, gear_color, gear_background, speedo_color, speedo_background global abs_label, abs_off_label, tcs_label, tcs_off_label global draw_abs_status, draw_tcs_status global telemetry_client if draw_abs_status: if telemetry_client.abs_enabled: ac.setPosition(abs_off_label,-10000,-10000) else: ac.setPosition(abs_off_label,0,0) if telemetry_client.abs_in_action: ac.setPosition(abs_label,0,0) else: ac.setPosition(abs_label,-10000,-10000) if draw_tcs_status: if telemetry_client.tc_enabled: ac.setPosition(tcs_off_label,-10000,-10000) else: ac.setPosition(tcs_off_label,0,0) if telemetry_client.tc_in_action: ac.setPosition(tcs_label,0,0) else: ac.setPosition(tcs_label,-10000,-10000) rpm = ac.getCarState(0,acsys.CS.RPM) # Distance covered if draw_odometer: drawOdometer() # Tach if draw_tachometer: drawTachometer(deltaT) # Speedo if draw_speedometer: drawSpeedometer() # Shift light if draw_shift_light: sl_center_x = shift_light_x sl_center_y = shift_light_y sl_radius = shift_light_radius if sl_timer > 0.1: shift_light_drawn = not shift_light_drawn sl_timer = 0 else: sl_timer = sl_timer + deltaT if max_rpm - rpm <= 500 and shift_light_drawn: color = shift_light_on_color else: color = shift_light_off_color for i in range(0,360,15): ac.glBegin(2) ac.glColor4f(color[0],color[1],color[2],color[3]) ac.glVertex2f(sl_center_x + math.cos(math.radians(i+15))*sl_radius,sl_center_y + math.sin(math.radians(i+15))*sl_radius) ac.glVertex2f(sl_center_x + math.cos(math.radians(i))*sl_radius,sl_center_y + math.sin(math.radians(i))*sl_radius) ac.glVertex2f(sl_center_x,sl_center_y) ac.glEnd() # Gear if draw_gear_indicator: gear = ac.getCarState(0,acsys.CS.Gear) digit = '' if gear > 1: digit = "%d" % (gear - 1) elif gear == 1: digit = "N" elif gear == 0: digit = "R" drawNineSegment(gear_x,gear_y,gear_width,gear_height,digit,gear_color,gear_background) # Digital speedo if draw_digital_speedo: # First Digit hundred = '' speed = ac.getCarState(0,acsys.CS.SpeedKMH) # Actual speed instead of drivetrain speed if imperial: speed = ac.getCarState(0,acsys.CS.SpeedMPH) if speed >= 100: hundred = "%d" % ((speed - (speed % 100))/100) drawNineSegment(speedo_tl_x,speedo_tl_y,speedo_total_width/3,speedo_total_height,hundred,speed_color,speed_background) # Second Digit ten = '' if speed >= 10: ten = "%d" % (((speed % 100) - (speed % 10))/10) drawNineSegment(speedo_tl_x+speedo_total_width/3,speedo_tl_y,speedo_total_width/3,speedo_total_height,ten,speed_color,speed_background) # Third Digit dec = "%d" % (speed % 10) drawNineSegment(speedo_tl_x+2*(speedo_total_width/3),speedo_tl_y,speedo_total_width/3,speedo_total_height,dec,speed_color,speed_background) # Brake Gauge if draw_brake_gauge: drawBrakeGauge() # Throttle Gauge if draw_throttle_gauge: drawThrottleGauge() # Clutch Gauge if draw_clutch_gauge: drawClutchGauge() # G Meter if draw_g_meter: drawGMeter() # Tyre Monitor if draw_tyre_monitor: drawTyreMonitor() # BOOOOOST if draw_boost_gauge: drawBoostGauge() # Fuel if draw_fuel_gauge: drawFuelGauge()
def drawScatterPlot(self, colourFades, dataPoints): for dataPoint, colour in zip(dataPoints, colourFades): ac.glColor4f(*colour) self.drawCircle(self.scatterSize, dataPoint) ac.glColor3f(1.0, 1.0, 1.0)
def drawFuelGauge(): global max_fuel, fuel_warning_label fuel = sim_info.physics.fuel rad = (fuel/max_fuel)*math.pi # 180 deg range so it's easy outer_radius = fuel_radius inner_radius = outer_radius - 4 if fuel/max_fuel > 0.125: ac.setPosition(fuel_warning_label,-10000,0) else: ac.setPosition(fuel_warning_label,fuel_pivot_x - 6,fuel_pivot_y - 30) for i in range(0,int((fuel/max_fuel)*100),1): # p3 p4 - rad2 # p1 p2 - rad1 rad1 = math.pi - math.pi*(i/100) rad2 = math.pi - math.pi*((i+1)/100) p1_x = math.cos(rad1)*outer_radius + fuel_pivot_x p1_y = fuel_pivot_y - math.sin(rad1)*outer_radius p2_x = math.cos(rad1)*inner_radius + fuel_pivot_x p2_y = fuel_pivot_y - math.sin(rad1)*inner_radius p3_x = math.cos(rad2)*outer_radius + fuel_pivot_x p3_y = fuel_pivot_y - math.sin(rad2)*outer_radius p4_x = math.cos(rad2)*inner_radius + fuel_pivot_x p4_y = fuel_pivot_y - math.sin(rad2)*inner_radius ac.glBegin(2) ac.glColor4f(fuel_bar_color[0],fuel_bar_color[1],fuel_bar_color[2],fuel_bar_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p3_x,p3_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(fuel_bar_color[0],fuel_bar_color[1],fuel_bar_color[2],fuel_bar_color[3]) ac.glVertex2f(p3_x,p3_y) ac.glVertex2f(p2_x,p2_y) ac.glVertex2f(p4_x,p4_y) ac.glEnd() # Needle rad = math.pi - rad bigend_x = math.cos(rad)*fuel_radius + fuel_pivot_x bigend_y = fuel_pivot_y - math.sin(rad)*fuel_radius littleend_x = math.cos(rad+math.pi)*fuel_needle_end + fuel_pivot_x littleend_y = fuel_pivot_y - math.sin(rad+math.pi)*fuel_needle_end # p1 p2 = big end # p3 p4 = little end p1_x = math.cos(rad+math.pi/2) + bigend_x p1_y = bigend_y - math.sin(rad+math.pi/2) p2_x = math.cos(rad-math.pi/2) + bigend_x p2_y = bigend_y - math.sin(rad-math.pi/2) p3_x = math.cos(rad+math.pi/2) + littleend_x p3_y = littleend_y - math.sin(rad+math.pi/2) p4_x = math.cos(rad-math.pi/2) + littleend_x p4_y = littleend_y - math.sin(rad-math.pi/2) ac.glBegin(2) ac.glColor4f(fuel_needle_color[0],fuel_needle_color[1],fuel_needle_color[2],fuel_needle_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p3_x,p3_y) ac.glVertex2f(p4_x,p4_y) ac.glEnd() ac.glBegin(2) ac.glColor4f(fuel_needle_color[0],fuel_needle_color[1],fuel_needle_color[2],fuel_needle_color[3]) ac.glVertex2f(p1_x,p1_y) ac.glVertex2f(p4_x,p4_y) ac.glVertex2f(p2_x,p2_y) ac.glEnd()