Exemplo n.º 1
0
 def _make_mark(self):
     ''' Make a mark to show the fraction position on the bar. '''
     mark = svg_header(self._ball_size / 2.,
                       BAR_HEIGHT * self._scale + 4, 1.0)
     mark += svg_rect(self._ball_size / 2.,
                      BAR_HEIGHT * self._scale + 4, 0, 0, 0, 0,
                      '#FF0000', '#FF0000')
     mark += svg_rect(1, BAR_HEIGHT * self._scale + 4, 0, 0,
                      self._ball_size / 4., 0, '#000000', '#000000')
     mark += svg_footer()
     self.mark = Sprite(self._sprites, 0,
                        self._height,  # hide off bottom of screen
                        svg_str_to_pixbuf(mark))
     self.mark.set_layer(1)
Exemplo n.º 2
0
 def _make_mark(self):
     ''' Make a mark to show the fraction position on the bar. '''
     mark = svg_header(self._ball_size / 2.,
                       BAR_HEIGHT * self._scale + 4, 1.0)
     mark += svg_rect(self._ball_size / 2.,
                      BAR_HEIGHT * self._scale + 4, 0, 0, 0, 0,
                      '#FF0000', '#FF0000')
     mark += svg_rect(1, BAR_HEIGHT * self._scale + 4, 0, 0,
                      self._ball_size / 4., 0, '#000000', '#000000')
     mark += svg_footer()
     self.mark = Sprite(self._sprites, 0,
                        self._height,  # hide off bottom of screen
                        svg_str_to_pixbuf(mark))
     self.mark.set_layer(1)
Exemplo n.º 3
0
    def _create_sprites(self, path):
        ''' Create all of the sprites we'll need '''
        self.smiley_graphic = svg_str_to_pixbuf(
            svg_from_file(os.path.join(path, 'smiley.svg')))

        self.frown_graphic = svg_str_to_pixbuf(
            svg_from_file(os.path.join(path, 'frown.svg')))

        self.egg_graphic = svg_str_to_pixbuf(
            svg_from_file(os.path.join(path, 'Easter_egg.svg')))

        self.blank_graphic = svg_str_to_pixbuf(
            svg_header(REWARD_HEIGHT, REWARD_HEIGHT, 1.0) + \
            svg_rect(REWARD_HEIGHT, REWARD_HEIGHT, 5, 5, 0, 0,
                     '#C0C0C0', '#282828') + \
            svg_footer())

        self.ball = Ball(self.sprites, os.path.join(path, 'basketball.svg'))
        self.current_frame = 0

        self.bar = Bar(self.sprites, self.width, self.height, self.scale,
                       self.ball.width())
        self.current_bar = self.bar.get_bar(2)

        self.ball_y_max = self.bar.bar_y() - self.ball.height()
        self.ball.move_ball((int(
            (self.width - self.ball.width()) / 2), self.ball_y_max))
Exemplo n.º 4
0
    def make_bar(self, nsegments):
        ''' Create a bar with n segments '''
        svg = svg_header(self.screen_width - self.ball_size, BAR_HEIGHT, 1.0)
        dx = (self.screen_width - self.ball_size) / float(nsegments)
        for i in range(int(nsegments) / 2):
            svg += svg_rect(dx, BAR_HEIGHT * self.scale, 0, 0, i * 2 * dx, 0,
                            '#FFFFFF', '#FFFFFF')
            svg += svg_rect(dx, BAR_HEIGHT * self.scale, 0, 0,
                            (i * 2 + 1) * dx, 0, '#AAAAAA', '#AAAAAA')
        if int(nsegments) % 2 == 1:  # odd
            svg += svg_rect(dx, BAR_HEIGHT * self.scale, 0, 0,
                            (i * 2 + 2) * dx, 0, '#FFFFFF', '#FFFFFF')
        svg += svg_footer()

        self.bars[nsegments] = Sprite(self.sprites, 0, 0,
                                      svg_str_to_pixbuf(svg))
        self.bars[nsegments].move(
            (int(self.ball_size / 2), self.screen_height - \
                 int((self.ball_size + self.height()) / 2)))
Exemplo n.º 5
0
 def new_ball_from_fraction(self, fraction):
     ''' Create a ball with a section of size fraction. '''
     r = SIZE[0] / 2.0
     self.ball.set_shape(svg_str_to_pixbuf(
         svg_header(SIZE[0], SIZE[1], 1.0) +
         svg_sector(r, r + BOX[1], r - 1, 1.999 * pi,
                    COLORS[0], COLORS[1]) +
         svg_sector(r, r + BOX[1], r - 1, fraction * 2 * pi,
                    COLORS[1], COLORS[0]) +
         svg_rect(BOX[0], BOX[1], 4, 4, 0, 0, '#FFFFFF', 'none') +
         svg_footer()))
Exemplo n.º 6
0
 def new_ball_from_fraction(self, fraction):
     ''' Create a ball with a section of size fraction. '''
     r = SIZE[0] / 2.0
     self.ball.set_shape(
         svg_str_to_pixbuf(
             svg_header(SIZE[0], SIZE[1], 1.0) +
             svg_sector(r, r + BOX[1], r - 1, 1.999 *
                        pi, COLORS[0], COLORS[1]) +
             svg_sector(r, r + BOX[1], r - 1, fraction * 2 *
                        pi, COLORS[1], COLORS[0]) +
             svg_rect(BOX[0], BOX[1], 4, 4, 0, 0, '#FFFFFF', 'none') +
             svg_footer()))
Exemplo n.º 7
0
    def _make_rect_bar(self, nsegments):
        ''' Create a bar with n segments '''
        svg = svg_header(self._width - self._ball_size,
                         BAR_HEIGHT * self._scale, 1.0)
        dx = self._width / float(nsegments)
        for i in range(int(nsegments) / 2):
            svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0, i * 2 * dx, 0,
                            self._colors[0], self._colors[0])
            svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0,
                            (i * 2 + 1) * dx, 0, self._colors[1],
                            self._colors[1])
        if int(nsegments) % 2 == 1:  # odd
            svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0,
                            (i * 2 + 2) * dx, 0, self._colors[0],
                            self._colors[0])
        svg += svg_footer()

        self.bars[nsegments] = Sprite(self._sprites, 0, 0,
                                      svg_str_to_pixbuf(svg))
        self.bars[nsegments].move((0, self._height - int(
            (self._ball_size + self._height()) / 2)))
Exemplo n.º 8
0
    def _make_rect_bar(self, nsegments):
        ''' Create a bar with n segments '''
        svg = svg_header(self._width - self._ball_size,
                         BAR_HEIGHT * self._scale, 1.0)
        dx = self._width / float(nsegments)
        for i in range(int(nsegments) / 2):
            svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0,
                            i * 2 * dx, 0, self._colors[0], self._colors[0])
            svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0,
                            (i * 2 + 1) * dx, 0,
                            self._colors[1], self._colors[1])
        if int(nsegments) % 2 == 1:  # odd
            svg += svg_rect(dx, BAR_HEIGHT * self._scale, 0, 0,
                            (i * 2 + 2) * dx, 0, self._colors[0],
                            self._colors[0])
        svg += svg_footer()

        self.bars[nsegments] = Sprite(self._sprites, 0, 0,
                                      svg_str_to_pixbuf(svg))
        self.bars[nsegments].move(
            (0, self._height -
             int((self._ball_size + self._height()) / 2)))
Exemplo n.º 9
0
 def make_labels(self):
     ''' Label the bar '''
     num = svg_header(BAR_HEIGHT * self.scale, BAR_HEIGHT * self.scale,
                      1.0) + \
           svg_rect(BAR_HEIGHT * self.scale, BAR_HEIGHT * self.scale,
                    0, 0, 0, 0, 'none', 'none') + \
           svg_footer()
     self.left = Sprite(self.sprites, int(self.ball_size / 4), self.bar_y(),
                        svg_str_to_pixbuf(num))
     self.left.set_label(_('0'))
     self.right = Sprite(self.sprites,
                         self.screen_width - int(self.ball_size / 2),
                         self.bar_y(), svg_str_to_pixbuf(num))
     self.right.set_label(_('1'))
Exemplo n.º 10
0
    def _create_sprites(self, path):
        ''' Create all of the sprites we'll need '''
        self.smiley_graphic = svg_str_to_pixbuf(svg_from_file(
            os.path.join(path, 'images', 'smiley.svg')))

        self.frown_graphic = svg_str_to_pixbuf(svg_from_file(
            os.path.join(path, 'images', 'frown.svg')))

        self.blank_graphic = svg_str_to_pixbuf(
            svg_header(REWARD_HEIGHT, REWARD_HEIGHT, 1.0) +
            svg_rect(REWARD_HEIGHT, REWARD_HEIGHT, 5, 5, 0, 0,
                     'none', 'none') +
            svg_footer())

        self.ball = Ball(self._sprites,
                         os.path.join(path, 'images', 'soccerball.svg'))
        self._current_frame = 0

        self.bar = Bar(self._sprites, self.ball.width(), COLORS)
        self._current_bar = self.bar.get_bar(2)

        self.ball_y_max = self.bar.bar_y() - self.ball.height() + \
                          int(BAR_HEIGHT / 2.)
        self.ball.move_ball((int((self._width - self.ball.width()) / 2),
                             self.ball_y_max))

        self._backgrounds = {}
        width, height = self._calc_background_size()
        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
            os.path.join(path, 'images', 'grass_background.png'),
            width, height)
        if Gdk.Screen.height() > Gdk.Screen.width():
            pixbuf = self._crop_to_portrait(pixbuf)

        self._backgrounds['grass_background.png'] = pixbuf

        self._background = Sprite(self._sprites, 0, 0, pixbuf)
        self._background.set_layer(-100)
        self._background.type = 'background'
        self._current_bg = 'grass_background.png'