Ejemplo n.º 1
0
    def __init__(self):
        # Initial random palette
        for i in range(len(self.tbl_palette)):
            self.tbl_palette[i] = int(np.random.rand() * 100) & 0xFF

        # Sprites
        self.spr_screen      =   g.Sprite(256, 240)
        self.spr_name_tbl    = [ g.Sprite(256, 240), g.Sprite(256, 240)]
        self.spr_pattern_tbl = [ g.Sprite(128, 128), g.Sprite(128, 128)]

        # Pixels
        self.pal_screen = [
            g.Pixel(84, 84, 84)   , g.Pixel(0, 30, 116)   , g.Pixel(8, 16, 144),
            g.Pixel(48, 0, 136)   , g.Pixel(68, 0, 100)   , g.Pixel(92, 0, 48),
            g.Pixel(84, 4, 0)     , g.Pixel(60, 24, 0)    , g.Pixel(32, 42, 0),
            g.Pixel(8, 58, 0)     , g.Pixel(0, 64, 0)     , g.Pixel(0, 60, 0),
            g.Pixel(0, 50, 60)    , g.Pixel(0, 0, 0)      , g.Pixel(0, 0, 0),
            g.Pixel(0, 0, 0)      , g.Pixel(152, 150, 152), g.Pixel(8, 76, 196),
            g.Pixel(48, 50, 236)  , g.Pixel(92, 30, 228)  , g.Pixel(136, 20, 176),
            g.Pixel(160, 20, 100) , g.Pixel(152, 34, 32)  , g.Pixel(120, 60, 0),
            g.Pixel(84, 90, 0)    , g.Pixel(40, 114, 0)   , g.Pixel(8, 124, 0),
            g.Pixel(0, 118, 40)   , g.Pixel(0, 102, 120)  , g.Pixel(0, 0, 0),
            g.Pixel(0, 0, 0)      , g.Pixel(0, 0, 0)      , g.Pixel(236, 238, 236),
            g.Pixel(76, 154, 236) , g.Pixel(120, 124, 236), g.Pixel(176, 98, 236),
            g.Pixel(228, 84, 236) , g.Pixel(236, 88, 180) , g.Pixel(236, 106, 100),
            g.Pixel(212, 136, 32) , g.Pixel(160, 170, 0)  , g.Pixel(116, 196, 0),
            g.Pixel(76, 208, 32)  , g.Pixel(56, 204, 108) , g.Pixel(56, 180, 204),
            g.Pixel(60, 60, 60)   , g.Pixel(0, 0, 0)      , g.Pixel(0, 0, 0),
            g.Pixel(236, 238, 236), g.Pixel(168, 204, 236), g.Pixel(188, 188, 236),
            g.Pixel(212, 178, 236), g.Pixel(236, 174, 236), g.Pixel(236, 174, 212),
            g.Pixel(236, 180, 176), g.Pixel(228, 196, 144), g.Pixel(204, 210, 120),
            g.Pixel(180, 222, 120), g.Pixel(168, 226, 144), g.Pixel(152, 226, 180),
            g.Pixel(160, 214, 228), g.Pixel(160, 162, 160), g.Pixel(0, 0, 0),
            g.Pixel(0, 0, 0)
        ]
Ejemplo n.º 2
0
def main():
    screen = g.Canvas(fullscreen=True)

    player = g.Sprite(g.shapes.Circle(1), position=(int(screen.width / 2), 1))
    road = g.Sprite(Road(screen.width, screen.height, int(screen.width / 3)))
    score = g.Sprite(g.shapes.Text('Score: 0'))

    screen.sprites.append(player)
    screen.sprites.append(road)
    screen.sprites.append(score)

    lastFrame = time.time()
    with g.NonBlockingInput() as nbi:
        while not player.overlaps(screen, exclude=score):
            ch = nbi.char()
            if ch == ',':
                player.move(g.LEFT)
            if ch == '.':
                player.move(g.RIGHT)

            if time.time() - lastFrame >= .05:

                # Increase Score
                score.image.text = (score.image.text[:7] +
                                    str(int(score.image.text[7:]) + 1))

                road.image.move()

                print(screen, end='')
                lastFrame = time.time()
Ejemplo n.º 3
0
def main():

    FPS = 15
    screen = g.Canvas(size=(36, 20))

    touchMeter = g.Sprite(g.shapes.Text(''), color=g.colors.RED)
    mover = g.Sprite(Car(), color=g.colors.WHITE)

    gridImg = ([[False, True, False, False] * 9] + ([[False] * 36]) * 3) * 5
    grid = g.Sprite(g.shapes.CustImage(gridImg),
                    color=g.colors.GREEN,
                    position=(0, 1))

    screen.sprites.append(touchMeter)
    screen.sprites.append(grid)
    screen.sprites.append(mover)

    frame = 0
    t = time.time()
    with g.NonBlockingInput() as nbi:
        while True:

            ch = nbi.char()
            if ch == '.':
                mover.move(g.RIGHT)
            if ch == ',':
                mover.move(g.LEFT)
            if ch == '/':
                mover.move(g.UP)
            if ch == 'm':
                mover.move(g.DOWN)

            str_ = ''
            if mover.touching(screen, 0):
                str_ += str(0)
            if mover.touching(screen, 1):
                str_ += str(1)
            if mover.touching(screen, 2):
                str_ += str(2)
            if mover.touching(screen, 3):
                str_ += str(3)
            if mover.touching(screen):
                str_ += 'T'

            touchMeter.image.text = str_

            if time.time() >= t + (1 / FPS):
                t = time.time()
                print(screen)
Ejemplo n.º 4
0
def main():

    FPS = 15
    screen = g.Canvas(fullscreen=True, size=(36, 20), wrap=True)

    frameCount = g.Sprite(g.shapes.Text(''), color=g.colors.RED)
    car = g.Sprite(Car(), color=g.colors.WHITE)

    llimit = screen.height
    ulimit = car.image.height
    grndTerrain = genGround(screen.width, screen.height, car.image.height,
                            screen.height)

    ground = g.Sprite(g.shapes.CustImage(grndTerrain), color=g.colors.GREEN)

    screen.sprites.append(frameCount)
    screen.sprites.append(ground)
    screen.sprites.append(car)

    frame = 0
    frame1 = 0
    t = time.time()
    with g.NonBlockingInput() as nbi:
        while True:
            frame += 1
            frameCount.image.text = str(frame) + ':' + str(frame1)

            ch = nbi.char()
            if ch == '.':
                car.move(g.RIGHT)
            if ch == ',':
                car.move(g.LEFT)
            if ch == '/':
                car.image.length += 1
            if ch == '\\':
                car.image.length -= 1

            car.move(g.UP)
            while not car.touching(screen, side=0):
                car.move(g.DOWN)
            while car.touching(screen, side=0):
                car.move(g.UP)
            car.move(g.DOWN)

            if time.time() >= t + (1 / FPS):
                frame1 += 1
                t = time.time()
                print(screen)
Ejemplo n.º 5
0
    def __init__(self, max_bar_width = 20, legend_width = 70, value_format = "%.2f", interactive = True):
        graphics.Scene.__init__(self)

        self.selected_keys = [] # keys of selected bars

        self.bars = []
        self.labels = []
        self.data = None

        self.max_width = max_bar_width
        self.legend_width = legend_width
        self.value_format = value_format
        self.graph_interactive = interactive

        self.plot_area = graphics.Sprite(interactive = False)
        self.add_child(self.plot_area)

        self.bar_color, self.label_color = None, None

        self.connect("on-enter-frame", self.on_enter_frame)

        if self.graph_interactive:
            self.connect("on-mouse-over", self.on_mouse_over)
            self.connect("on-mouse-out", self.on_mouse_out)
            self.connect("on-click", self.on_click)
Ejemplo n.º 6
0
def main():
    print('Please Wait...')
    canvas = g.Canvas(fullscreen=True)

    for circles in range(200):
        size = rand.randint(1, int(min(canvas.width / 4, canvas.height / 2)))
        circle = g.Sprite(g.shapes.Circle(size, filled=True),
                          position=(rand.randint(0, canvas.width - 1),
                                    rand.randint(0, canvas.height - 1)))
        canvas.sprites.append(circle)
        if circle.onEdge(canvas) or circle.touching(canvas):
            canvas.sprites.remove(circle)

    print(canvas)
Ejemplo n.º 7
0
 def __init__(self,
              world,
              layer,
              position,
              shape,
              sprite,
              mass=1.0,
              moment=1.0,
              **kwargs):
     super(Debris, self).__init__(world, shape, mass, moment, **kwargs)
     if sprite:
         graphics.Sprite(sprite, self, layer)
         self.sprite.cocos_sprite.draw = lambda: graphics.draw_thing_shapes(
             self)
     self.position = position
Ejemplo n.º 8
0
def main():
    screen = g.Canvas(size=(20, 20))

    line = g.Sprite(
        g.shapes.Vector(0, 10),
        (5, 5)
    )
    screen.sprites.append(line)

    with g.NonBlockingInput() as nbi:
        while True:

            if nbi.char() == ' ':
                line.image.angle += 5
                print(screen)

            time.sleep(.01)
Ejemplo n.º 9
0
def main():

    termSize = g.console.Size()
    screen = g.Canvas(border=False)

    # Clock Face
    circle = g.Sprite(g.shapes.Circle(0), color=g.colors.CYAN)
    textTime = g.Sprite(g.shapes.Text())
    screen.sprites.append(circle)
    screen.sprites.append(textTime)

    # Hands
    second = g.Sprite(g.shapes.Vector(0, 0),
                      color=g.colors.RED,
                      char=chr(0x25CB))
    minute = g.Sprite(g.shapes.Vector(0, 0), color=g.colors.YELLOW)
    hour = g.Sprite(g.shapes.Vector(0, 0), color=g.colors.YELLOW)
    screen.sprites.append(second)
    screen.sprites.append(minute)
    screen.sprites.append(hour)

    frames = 0
    start = time.time()
    try:
        while True:

            # Update sizes
            termS = termSize.getSize()
            size = int(min(termS[0] / 2, termS[1]) - 1)
            center = size * .5

            screen.width = size
            screen.height = size
            circle.image.radius = center

            # Generate background
            background = [[' ' for x in range(size)] for y in range(size)]

            hours = 12
            for n in range(1, hours + 1):
                angle = n * (2 * math.pi / hours)

                x = 0.8 * center * math.sin(angle)
                y = 0.8 * center * math.cos(angle)

                for offset, char in enumerate(list(str(n))):
                    bac = [
                        slice(int(center - y)),
                        slice(int(center + x + offset))
                    ]
                    background[bac[0]][bac[1]] = g.colors.colorStr(char, n % 8)

            screen.background = background

            # Generate hands
            t = int(time.time())

            h = int((t / 3600) % 12)
            h = 12 if h == 0 else h
            m = int((t / 60) % 60)
            s = int((t / 1) % 60)
            textTime.image.text = '{:2}:{:02}:{:02}'.format(h, m, s)
            textTime.position = (center - (len(textTime.image.text) / 2),
                                 (3 / 4) * size)

            for hand, secPerRev, length in [(second, 60, 0.9),
                                            (minute, 3600, 0.75),
                                            (hour, 43200, 0.5)]:
                hand.image.length = center * length

                # +180 and -angle are to compensate for
                #   flipped upside-down angles.
                angle = (((t * (360 / secPerRev)) + 180) % 360)
                hand.image.angle = -angle

                width, height = hand.image.width, hand.image.height

                if angle > 0 and angle <= 90:
                    hand.position = (center - width, center)

                elif angle > 90 and angle <= 180:
                    hand.position = (center - width, center - height)

                elif angle > 180 and angle <= 270:
                    hand.position = (center, center - height)

                elif angle > 270 and angle <= 360:
                    hand.position = (center, center)

            print(screen, end='')
            time.sleep(0.1)
            frames += 1
    except KeyboardInterrupt:
        print('\nAvg FPS: ' + str(frames / (time.time() - start)))
Ejemplo n.º 10
0
def load_png_sprite(string):
    return graphics.Sprite(png_path(string))
Ejemplo n.º 11
0
import time
import copy

import graphics as g

screen = g.Canvas(size=(21, 21))

circle = g.Sprite(
    g.shapes.Circle(0, filled=True),
    (10, 10)
)
screen.sprites.append(circle)

i = 0

while True:

    radius = circle.image.radius
    if radius == 0:
        radius = 10
        while screen.sprites:
            screen.sprites.pop()
            if len(screen.sprites) > 0:
                print(screen)
                time.sleep(.04)
    else:
        radius -= 1

    circle = copy.deepcopy(circle)
    circle.image.radius = radius
    circle.position = (10 - radius, 10 - radius)
Ejemplo n.º 12
0
import graphics as g

# Create the canvas, 20x20 pixels (characters).
screen = g.Canvas(size=(20, 20))

# Create a circle image, radius 5 pixels.
circleImage = g.shapes.Circle(5)

# Create a green sprite at position (7, 7) with the circle image.
circleSprite = g.Sprite(circleImage, position=(7, 7), color=g.colors.GREEN)

# Add the sprite to the canvas.
screen.sprites.append(circleSprite)

# Output the canvas to the terminal.
print(screen)

# Increase the circles radius by two.
circleSprite.image.radius += 2

# Output the canvas to the terminal.
print(screen)