コード例 #1
0
    def _draw_cell(self, data_cube, x, y, z, scale, xpos, ypos, w, h, draw_labels, show_broken_cells=True):
        if reactor.cell_type(x, y) != " ":
            index = cell_index(x, y, z)
            cx = xpos + w / 2
            cy = ypos + h / 2

            # Get temperature
            t = data_cube[index]

            # Calculate color for temp
            normalized_temp = t / (t + scale)
            red = normalized_temp
            blue = 1.0 - normalized_temp
            green = (normalized_temp - 0.5) * 2
            if green < 0:
                green = 0
            color = (255 * red, 255 * green, 255 * blue)

            # Draw cell
            if draw_labels:
                self.screen.lock()
            pygame.draw.rect(self.screen, color, (xpos, ypos, w - 1, h - 1))
            if draw_labels:
                self.screen.unlock()

            # Draw label, if there is room for it
            if draw_labels:
                label = reactor.cell_name(x, y)
                textutils.drawTextAtPos(self.screen, label, cx, cy, black, color, textutils.tinyFont)

            if draw_labels:
                self.screen.lock()

            # Draw rod, if it crosses the cell (change size by how much it overlaps the cell).
            rodPos = 1.0 * self.rod_position[rod_index(x, y)]
            rodCover = min(0.0, max(1.0 * rodPos - z, 1.0))
            if rodCover > 0.0:
                rodx = int(xpos + (1.0 - rodCover * 0.5) * w)
                rody = int(ypos + (1.0 - rodCover * 0.5) * h)
                rodw = int(w * rodCover)
                rodh = int(h * rodCover)
                # TODO: Doesn't seem to draw the ellipse for some reason :/
                elipseRect = Rect(rodx, rody, rodx + rodw, rody + rodh)
                pygame.draw.ellipse(self.screen, black, elipseRect, 0)

            # Cross over if melted
            if show_broken_cells and not self.operational[index]:
                crossover_thickness = 2
                pygame.draw.line(self.screen, black, (xpos, ypos), (xpos + w - 1, ypos + h - 1), crossover_thickness)
                pygame.draw.line(self.screen, black, (xpos + w - 1, ypos), (xpos, ypos + h - 1), crossover_thickness)

            if draw_labels:
                self.screen.unlock()
コード例 #2
0
ファイル: graph.py プロジェクト: zbyso23/reactor
    def _draw_line(self, surface, area, num):

        start_x = area.left
        end_x = area.right - self.text_offset

        # Reference line
        y = self.scale_value_to_area_y(num, area)
        surface.lock()
        pygame.draw.line(surface, self.reference_line_color, (start_x, y), (end_x, y), 1)
        surface.unlock()

        # Value and unit
        s = str(num) + "  " + self.name
        textutils.drawTextAtPos(surface, s, end_x, y, self.color, self.background_color, self.font, 1)
コード例 #3
0
ファイル: reactor_visualizer.py プロジェクト: zbyso23/reactor
    def _draw_cell(self,
                   data_cube,
                   x,
                   y,
                   z,
                   scale,
                   xpos,
                   ypos,
                   w,
                   h,
                   draw_labels,
                   show_broken_cells=True):
        if reactor.cell_type(x, y) != ' ':
            index = cell_index(x, y, z)
            cx = xpos + w / 2
            cy = ypos + h / 2

            # Get temperature
            t = data_cube[index]

            # Calculate color for temp
            normalized_temp = t / (t + scale)
            red = normalized_temp
            blue = 1.0 - normalized_temp
            green = (normalized_temp - 0.5) * 2
            if green < 0: green = 0
            color = (255 * red, 255 * green, 255 * blue)

            # Draw cell
            if draw_labels: self.screen.lock()
            pygame.draw.rect(self.screen, color, (xpos, ypos, w - 1, h - 1))
            if draw_labels: self.screen.unlock()

            # Draw label, if there is room for it
            if draw_labels:
                label = reactor.cell_name(x, y)
                textutils.drawTextAtPos(self.screen, label, cx, cy, black,
                                        color, textutils.tinyFont)

            if draw_labels: self.screen.lock()

            # Draw rod, if it crosses the cell (change size by how much it overlaps the cell).
            rodPos = 1.0 * self.rod_position[rod_index(x, y)]
            rodCover = min(0.0, max(1.0 * rodPos - z, 1.0))
            if rodCover > 0.0:
                rodx = int(xpos + (1.0 - rodCover * 0.5) * w)
                rody = int(ypos + (1.0 - rodCover * 0.5) * h)
                rodw = int(w * rodCover)
                rodh = int(h * rodCover)
                # TODO: Doesn't seem to draw the ellipse for some reason :/
                elipseRect = Rect(rodx, rody, rodx + rodw, rody + rodh)
                pygame.draw.ellipse(self.screen, black, elipseRect, 0)

            # Cross over if melted
            if show_broken_cells and not self.operational[index]:
                crossover_thickness = 2
                pygame.draw.line(self.screen, black, (xpos, ypos),
                                 (xpos + w - 1, ypos + h - 1),
                                 crossover_thickness)
                pygame.draw.line(self.screen, black, (xpos + w - 1, ypos),
                                 (xpos, ypos + h - 1), crossover_thickness)

            if draw_labels: self.screen.unlock()