Пример #1
0
def render(screen, particle):
    """
    """
    draw.circle(screen, color.Color("black"), particle.pos(), 2)
    particle.update()
    draw.circle(screen, color.Color("white"), particle.pos(), 2)
    display.update()
Пример #2
0
    def run(self):
        self.running = True
        while self.running:
            model = self.arbalet.end_model.data_frame
            with self.arbalet.sdl_lock:
                self.display.lock()
                for w in range(self.arbalet.width):
                    for h in range(self.arbalet.height):
                        pixel = model[h, w]
                        self.display.fill(
                            color.Color(int(pixel[0]), int(pixel[1]),
                                        int(pixel[2])),
                            Rect(w * self.cell_width, h * self.cell_height,
                                 self.cell_width, self.cell_height))

                # Draw vertical lines
                for w in range(self.arbalet.width):
                    draw.line(self.display, color.Color(40, 40, 40),
                              (w * self.cell_width, 0),
                              (w * self.cell_width, self.sim_height),
                              self.border_thickness)
                # Draw horizontal lines
                for h in range(self.arbalet.height):
                    draw.line(self.display, color.Color(40, 40, 40),
                              (0, h * self.cell_height),
                              (self.sim_width, h * self.cell_height),
                              self.border_thickness)
                display.update()
                self.display.unlock()
            self.rate.sleep()

        with self.arbalet.sdl_lock:
            display.quit()
Пример #3
0
    def update(self):
        self.display.lock()
        try:
            for w in range(self.model.width):
                for h in range(self.model.height):
                    pixel = self.model[h, w]
                    self.display.fill(
                        color.Color(int(pixel[0] * 255), int(pixel[1] * 255),
                                    int(pixel[2] * 255)),
                        Rect(w * self.cell_width, h * self.cell_height,
                             self.cell_width, self.cell_height))

            # Draw vertical lines
            for w in range(self.model.width):
                draw.line(self.display, color.Color(40, 40, 40),
                          (w * self.cell_width, 0),
                          (w * self.cell_width, self.sim_height),
                          self.border_thickness)
            # Draw horizontal lines
            for h in range(self.model.height):
                draw.line(self.display, color.Color(40, 40, 40),
                          (0, h * self.cell_height),
                          (self.sim_width, h * self.cell_height),
                          self.border_thickness)

            display.update()
        finally:
            self.display.unlock()
            return True
Пример #4
0
    def update(self):
        if not self.closed:
            for e in event.get():
                if e.type == QUIT:
                    return False
            self.display.lock()
            try:
                for w in range(self.model.width):
                    for h in range(self.model.height):
                        pixel = self.model[h, w]
                        self.display.fill(
                            color.Color(int(pixel[0]), int(pixel[1]),
                                        int(pixel[2])),
                            Rect(w * self.cell_width, h * self.cell_height,
                                 self.cell_width, self.cell_height))

                # Draw vertical lines
                for w in range(self.model.width):
                    draw.line(self.display, color.Color(40, 40, 40),
                              (w * self.cell_width, 0),
                              (w * self.cell_width, self.sim_height),
                              self.border_thickness)
                # Draw horizontal lines
                for h in range(self.model.height):
                    draw.line(self.display, color.Color(40, 40, 40),
                              (0, h * self.cell_height),
                              (self.sim_width, h * self.cell_height),
                              self.border_thickness)

                display.update()
            finally:
                self.display.unlock()
                return True
Пример #5
0
    def callback(self, ch, method, properties, body):
        raw = json.loads(body.decode('ascii'))

        # Open window if necessary
        if not self.opened:
            self.height = len(raw)
            self.width = len(raw[0]) if self.height > 0 else 0
            self.open()
        else:
            with self.lock:
                for row in range(self.height):
                    for col in range(self.width):
                        r, g, b = map(lambda x: min(255, max(0, int(x * 256))),
                                      raw[row][col])
                        self.display.fill(
                            color.Color(r, g, b),
                            Rect(col * self.CELL_WIDTH, row * self.CELL_HEIGHT,
                                 self.CELL_WIDTH, self.CELL_HEIGHT))
                # Draw vertical lines
                for w in range(self.width):
                    draw.line(self.display, color.Color(40, 40, 40),
                              (w * self.CELL_WIDTH, 0),
                              (w * self.CELL_WIDTH, self.sim_height),
                              self.border_thickness)
                # Draw horizontal lines
                for h in range(self.height):
                    draw.line(self.display, color.Color(40, 40, 40),
                              (0, h * self.CELL_HEIGHT),
                              (self.sim_width, h * self.CELL_HEIGHT),
                              self.border_thickness)
                display.update()

            for e in event.get():
                if e.type == QUIT:
                    self.close()
Пример #6
0
 def __init__(self):
     # PG.font.init()
     PM.music.load("music/highscores.mod")
     PM.music.play(-1)
     self.color = PC.Color("black")
     self.time = 0.0
     Globals.SCREEN.fill(PC.Color("black"))
     self.text_surface = self.get_text_surface()
     addScoretoText()
     self.text_surface = self.get_text_surface()
Пример #7
0
 def __init__(self, renderer, text, scr_w, bottom, top, default, step):
     self.message = renderer
     self.bottom = bottom
     self.top = top
     self.step = step
     self.text = text
     self.width = scr_w
     self.xindex = default
     self.has_focus = False
     self.color = color.Color("brown")
     self.chosen = color.Color("pink")
     self.option_c = color.Color(255,255,0)
     self.unoption_c = color.Color(127,64,0)
Пример #8
0
 def update(self):
     self.time += self.time
     #Fade in code, linear fade based on time
     if self.time < Locals.FADEINTIME:
         ratio = self.time / Locals.FADEINTIME
         value = int(ratio * 255)
         self.color = PC.Color(value, value, value)
Пример #9
0
def input_callback(channel):
    global cur_pos
    print "{}, {}".format("Pin triggered", channel)

    if (channel == next_img):
        cur_pos = (cur_pos + 1) % len(img_files)

    if (channel == prev_img):
        cur_pos = (cur_pos - 1) % len(img_files)

    i_surf = img.load(img_files[cur_pos])
    d_surf.fill(color.Color(0, 0, 0))
    d_surf.blit(i_surf, (0, 0))

    disp.update()

    #check if its an output pin
    if (channel in controls):
        #get the current state of the pin and invert it
        state = GPIO.input(controls[channel][0])
        GPIO.output(controls[channel][0], not (state))
        if (controls[channel][1] > 0):
            #check if the pin isn't a toggle
            Timer(controls[channel][1] / 1000.0, reset_pin,
                  [controls[channel][0], state]).start()
Пример #10
0
class Obstacle():
    """
    I'm a obstacle for "light rays".
    I have two edges (start and end),
    that are my boundaries.

    My responsabilities are:
        - Draw myself in the drawing canvas
        - Act as a boudary for light rays
    """
    COLOR = color.Color(0, 50, 255)

    def __init__(self, starting_edge: Point2D, ending_edge: Point2D):
        self.starting_edge = starting_edge
        self.ending_edge = ending_edge
        self.diff = self.starting_edge - self.ending_edge
        self.opposite_diff = self.diff * -1

    @staticmethod
    def preview(canvas, starting_edge: Point2D, ending_edge: Point2D):
        line(canvas, Obstacle.COLOR, starting_edge.to_tuple(),
             ending_edge.to_tuple(), 5)

    def draw(self, canvas):
        line(canvas, self.COLOR, self.starting_edge.to_tuple(),
             self.ending_edge.to_tuple(), 5)
Пример #11
0
 def __init__(self):
     self.color = PC.Color("blue")
     self.time = 0.1
     PM.music.load("music/highscores.mod")
     PM.music.play(-1)
     if not Menu.BACKGROUND:
         Menu.BACKGROUND = self.load_background()
Пример #12
0
    def draw(self, __display_surface):
        '''
        Draws table, balls, pockets
        '''
        __display_surface.fill(pygame.Color("black"))

        self.ball_surf.fill((0, 220, 100))

        coordinates = self.generate_bumper_coords(
            self.play_surface
        )  #Generate new coordinates in case window resized (Resize not implemented)

        for key, item in coordinates.items():

            drw.polygon(self.ball_surf, cl.Color('black'), item, 1)

        self.pockets.draw(self.ball_surf)
        self.balls.draw(self.ball_surf)
        __display_surface.blit(self.ball_surf, self.ball_surf_origin)
        #__display_surface.blit(self.scratch, (220,170))

        self.score.draw(__display_surface,
                        (__display_surface.get_width() -
                         2 * self.score_size[0], self.score_size[1]))
        self.scratch.draw(__display_surface, (220, 170))

        #Draw stick last so it is drawn above the ball surface
        if not self.balls_still_moving():
            self.stick.draw(__display_surface, self.play_stick_animation,
                            self.cue_ball.get_pos())
Пример #13
0
    def update(self):
        self.surface.fill(self.color)
        x, y = self.surface.get_size()
        pygame.draw.rect(self.surface, (204, 0, 51), ((5, 5), (x - 10, 30)))
        self.surface.blit(
            self.playerfont.render(self.player, True, color.Color('White')),
            (10, 10))
        self.surface.blit(
            self.rfont.render('Round %s' % str(self.round), True,
                              color.Color('White')), (10, 40))

        ypos = 60
        for throw, ring, point in self.points:
            self.surface.blit(
                self.pfont.render(self.ringpttostr(ring, point), True,
                                  color.Color('White')), (10, ypos))
            ypos += 20
Пример #14
0
 def update(self):
     self.time = 0.1
     fadein = 2.0
     self.time += self.time
     if self.time < fadein:
         ratio = self.time / fadein
         value = int(ratio * 255)
         self.color = PC.Color(value, value, value)
Пример #15
0
 def update(self):
     self.time = 0.1
     self.move_player()
     self.move_enemy()
     self.time += self.time
     if self.time < Locals.FADEINTIME:
         ratio = self.time / Locals.FADEINTIME
         value = int(ratio * 255)
         self.color = PC.Color(value, value, value)
Пример #16
0
 def __init__(self, renderer, text, scr_w, retfunc, *choices):
     self.message = renderer
     self.text = text
     self.width = scr_w
     self.choices = [" "]
     for c in choices:
         for d in c:
             self.choices.append(d)
     if (len(self.choices)>1):
         self.choices.pop(0)
     self.option_c = color.Color(255,255,0)
     self.unoption_c = color.Color(127,64,0)
     self.xindex = 0
     self.active_option = self.choices[0]
     self.has_focus = False
     self.color = color.Color("brown")
     self.chosen = color.Color("pink")
     self.retfunc = retfunc
Пример #17
0
 def get_text_surface(self):
     rect = Rect(100, 100, 300, 300)
     surface = PG.Surface(rect.size)
     text_color = PC.Color("white")
     font = PG.font.Font(None, 30)
     surface.fill(self.color)
     with open('scores.txt', 'r') as f:
         scores = f.read()
         surface = render_text(scores, font, rect, text_color, self.color)
     return surface
Пример #18
0
    def __call__(self, start, end, percent):
        r = int(self.function(start.r, end.r, percent))
        g = int(self.function(start.g, end.g, percent))
        b = int(self.function(start.b, end.b, percent))
        if self.useAlpha:
            a = int(self.function(start.a, end.a, percent))
        else:
            a = 255

        return color.Color(r, g, b, a)
Пример #19
0
    def render(self):
        Globals.SCREEN.fill(PC.Color('black'))
        #put background in
        Globals.SCREEN.blit(Menu.BACKGROUND, (0, 0))

        drawtextbox("Title", PC.Color("red"), PC.Color("blue"), 10, 20, 60, 30,
                    "title")
        drawtextbox("Scores", PC.Color("red"), PC.Color("blue"), 10, 50, 85,
                    30, "scores")
        drawtextbox("Game", PC.Color("red"), PC.Color("blue"), 10, 80, 75, 30,
                    "game")
        drawtextbox("Quit", PC.Color("red"), PC.Color("blue"), 10, 110, 60, 40,
                    "quit")
        #        drawtextbox("Brightness", (37, 200,100), PC.Color("blue"), 10,140,130,30, "brightness")
        #        drawtextbox("Volume", (37, 200, 100), PC.Color("blue"), 10,170,90, 30, 'volume')
        PDI.flip()
Пример #20
0
class Color:
    WHITE = color.Color(200, 200, 200)
    BLACK = color.Color(0, 0, 0)
    GREEN = color.Color(0, 200, 0)
    RED = color.Color(230, 0, 0)
    GREY = color.Color(50, 50, 50)
    LIGHT_GREY = color.Color(60, 60, 60)
Пример #21
0
    def __init__(self, screen, title, menuitems):

        self.rect = screen.get_rect()        
        self.screen = screen.subsurface(self.rect)
        self.width = self.rect.width
        self.height = self.rect.height
        font.init()
        self.fontsize = int(self.height/15)
        self.color = color.Color("brown")
        self.chosen = color.Color("pink")
        self.message = font.Font(None, self.fontsize)
        self.pos = (self.fontsize,self.fontsize)
        self.title = self.message.render(title, False, self.chosen, None)
        self.untitle = self.message.render(title, False, self.color, None)
        self.menuitems = menuitems
        self.index = 1
        self.has_joystick = False
        pygame.joystick.init()
        if (pygame.joystick.get_count() > 0):
            self.joypad = pygame.joystick.Joystick(0)
            self.joypad.init()
            self.has_joystick = True
Пример #22
0
    def __init__(self):
        PM.music.load("music/highscores.mod")
        PM.music.play(-1)

        self.color = PC.Color("white")
        self.time = 0.0
        if not Title.IMAGES:
            Title.IMAGES = self.load_images()
        Globals.SCREEN = PDI.set_mode((800, 600), PG.DOUBLEBUF | PG.HWSURFACE)
        Globals.WIDTH = Globals.SCREEN.get_width()
        Globals.HEIGHT = Globals.SCREEN.get_height()
        self.images = Title.IMAGES
        # enemy image position
        self.enemyx = Globals.WIDTH
        self.enemyy = Globals.HEIGHT - self.images[0].get_height()
        # player image position
        self.playerx = 0 - self.images[1].get_width()
        self.playery = Globals.HEIGHT - self.images[1].get_height()
        Globals.SCREEN.fill(PC.Color("white"))
        # Animation for tile text
        bigfont = PG.font.Font(None, 60)
        self.renderer = textWavey(bigfont, "Frying Pan", (252, 222, 128), 4)
        self.inst_surf = PF.Font(None, 35)
Пример #23
0
 def render(self):
     G.Globals.SCREEN.fill(PC.Color("black"))
     width, height = self.title_surf.get_size()
     G.Globals.SCREEN.blit(self.title_surf,
                           (G.Globals.WIDTH / 2 - width / 2, height))
     G.Globals.SCREEN.blit(self.back_surf, (0, 0))
     c_height = 3 * height
     for score in self.score_surf:
         width, height = score.get_size()
         G.Globals.SCREEN.blit(score,
                               (G.Globals.WIDTH / 2 - width / 2, c_height))
         c_height += height * 1.5
         if c_height > G.Globals.HEIGHT:
             break
Пример #24
0
 def __init__(self):
     State.State.__init__(self)
     title_font = PF.Font("fonts/red_october.ttf", 42)
     main_font = PF.Font(None, 22)
     scores = []
     with open('scores.txt') as open_file:
         for line in open_file:
             scores.append(line)
     color = PC.Color("white")
     self.title_surf = title_font.render("High Scores", True, color)
     self.back_surf = title_font.render("Back", True, (255, 0, 0))
     self.back_x, self.back_y = self.back_surf.get_size()
     self.score_surf = []
     for score in scores:
         self.score_surf.append(
             main_font.render(score.rstrip(), True, color))
Пример #25
0
    def draw(self):
        super(TextEntry, self).draw()

        # Display the cursor
        if self.state:
            # Get text width
            offset = loaders.text(
                self.get_text()[0:self.cursor],
                font.fonts["sans"]['normal']).get_width() + self.indent

            # Draw cursor
            color_value = int(abs(sin(self.cursor_state)) * 255) / 2
            #print color_value
            color_cursor = color.Color(color_value, color_value, color_value)
            draw.line(self.screen, color_cursor,
                      (self.parentpos[0] + self.x + offset,
                       self.parentpos[1] + self.y),
                      (self.parentpos[0] + self.x + offset,
                       self.parentpos[1] + self.y + self.height), 2)
        self.start_anim()
Пример #26
0
    def __init__(self):
        #This is were colors and unique ids are assigned to players
        # blue=col.Color(0, 0, 244, 244)

        white = col.Color(244, 244, 244, 244)
        # test= Player(13,10,blue)
        # test2=Player(13,25,red)

        self.color_map[Players.BLANK] = white

        # self.add_player(test)
        # self.add_player(test2)

        self.move_map = {
            Direction.UP: self.move_player_up,
            Direction.DOWN: self.move_player_down,
            Direction.LEFT: self.move_player_left,
            Direction.RIGHT: self.move_player_right,
            Direction.SIT: self.no_move
        }

        self.load()
Пример #27
0
class Bullet:
    g = 10
    r = 10
    fgcolor = color.Color('purple')
    bgcolor = color.Color('white')
    speedrate = 0.01
    vrate = 0.01
    angle_base_len = 150.0
    angle_range = 20.0
    angle_positive_max = 30.0

    def __init__(self, start_pos, end_pos, start_t, end_t):
        start_x, start_y = start_pos
        end_x, end_y = end_pos
        takentime = end_t - start_t
        self.discharge_t = end_t
        self.ini_pos = start_pos

        length = math.sqrt((start_x - end_x)**2 + (start_y - end_y)**2)
        if length > self.angle_base_len:
            yz_angle = self.angle_range - self.angle_positive_max
        else:
            yz_angle = self.angle_range / self.angle_base_len * length - \
              (self.angle_range - self.angle_positive_max)
        yz_angle *= math.pi / 180
        xy_angle = math.atan2(end_y - start_y, end_x - start_x)

        if length <= 0:
            self.velocity = 0
        else:
            self.velocity = length / takentime * self.speedrate
        self.x_move = math.cos(xy_angle) * self.velocity
        self.y_move = math.sin(-1 * math.pi / 180) * self.velocity
        self.z = 0
        self.z_move = abs(math.cos(yz_angle) * self.velocity)
        self.sizerate = 1
        self.sizerate_change = self.velocity * self.vrate

        # calculate center position of bullet.
        self.center = start_x, start_y
        self.pos = start_x - self.r, start_y - self.r

        # create and draw surface.
        self.surface = pygame.Surface((self.r * 2, self.r * 2)).convert()
        self.surface.fill(self.bgcolor)
        self.surface.set_colorkey(self.bgcolor)
        self.rect = pygame.draw.circle(self.surface, self.fgcolor,
                                       (self.r, self.r), self.r)

    def __move_x(self):
        return self.x_move

    def __move_y(self):
        return (self.g * (time.time() - self.discharge_t)**2) / 2 + self.y_move

    def __move_z(self):
        return self.z_move

    def __move_size(self):
        return self.sizerate / (1 + self.sizerate_change)

    def move(self):
        self.sizerate = self.__move_size()
        self.pos = (self.pos[0] + self.__move_x(),
                    self.pos[1] + self.__move_y())
        self.center = (self.center[0] + self.__move_x(),
                       self.center[1] + self.__move_y())
        self.z += self.__move_z()
        self.surface.fill(self.bgcolor)
        r = int(round(self.r * self.sizerate))
        if r < 0:
            return None
        return pygame.draw.circle(self.surface, self.fgcolor, (self.r, self.r),
                                  r)

    def get_rect(self):
        return self.surface.get_rect()
Пример #28
0
 def brighten(color):
     r = Board.clamp_color(color.r + 140)
     g = Board.clamp_color(color.g + 140)
     b = Board.clamp_color(color.b + 140)
     return col.Color(r, g, b, color.a)
Пример #29
0
class Wall(Obstacle):
    COLOR = color.Color(200, 200, 200)

    def __init__(self, starting_edge, ending_edge):
        super().__init__(starting_edge, ending_edge)
Пример #30
0
while run:
    pyg.time.delay(100)

    for event in pyg.event.get():
        if event.type == pyg.QUIT:
            run = False
        elif event.type == pyg.MOUSEBUTTONDOWN:
            mouse_down = True
        elif event.type == pyg.MOUSEBUTTONUP:
            mouse_down = False

    if mouse_down:
        x1, y1 = pyg.mouse.get_pos()

    keys = pyg.key.get_pressed()

    BG1.draw(win)
    rek1 = Rect(['rect', (x1,y1), (height, width), c.Color('blue')])
    rek1.draw(win)
    string = 'Hello World!'
    myfont = pyg.font.SysFont('Comic Sans MS', 30)
    box1_vars = ['textbox', (x1+width*2, y1), ((30*0.75)*1.25, (30*0.75)*len(string)), c.Color('Red'),
                 string, (myfont, (255, 255, 255))]
    box1 = TextBox(box1_vars)
    box1.rect.width *= 2
    box1.draw(win)
    pyg.display.update()

pyg.quit()