Beispiel #1
0
 def __init__(self):
     pygame.init()
     pygame.display.set_caption(config.window_caption)
     event.set_allowed_events()
     zope.event.subscribers.append(self.game_event_handler)
     self.canvas = graphics.Canvas()
     self.fps_clock = pygame.time.Clock()
 def __init__(self):
     pygame.init()
     pygame.display.set_caption("Бильярд")
     pygame.event.set_allowed([pygame.KEYDOWN, pygame.QUIT])
     zope.event.subscribers.append(self.game_event_handler)
     self.canvas = graphics.Canvas()
     self.fps_clock = pygame.time.Clock()
Beispiel #3
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()
Beispiel #4
0
    def initialize_colony_graphics(self, colony):
        """Create canvas, control panel, places, and labels."""
        self.initialized = True
        self.canvas = graphics.Canvas()
        self.food_text = self.canvas.draw_text('Food: 1  Time: 0', (20, 20))
        self.ant_text = self.canvas.draw_text('Ant selected: None', (20, 140))
        self._click_rectangles = list()
        self._init_control_panel(colony)
        self._init_places(colony)

        start_text = self.canvas.draw_text('CLICK TO START', MESSAGE_POS)
        self.canvas.wait_for_click()
        self.canvas.clear(start_text)
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)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #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)
Beispiel #9
0
    def initialize_colony_graphics(self, gamestate):
        """Create canvas, control panel, places, and labels."""
        self.initialized = True
        self.canvas = graphics.Canvas()
        #
        # from PIL import ImageTk
        # image = ImageTk.PhotoImage(file="/Users/rahul/cal/CS61A/projects/ants/assets/main-background.png")
        #
        self.food_text = self.canvas.draw_text('Food: 1  Time: 0', (20, 20))
        self.ant_text = self.canvas.draw_text('Ant selected: None', (20, 140))
        self._click_rectangles = list()
        self._init_control_panel(gamestate)
        self._init_places(gamestate)

        start_text = self.canvas.draw_text('CLICK TO START', MESSAGE_POS)
        self.canvas.wait_for_click()
        self.canvas.clear(start_text)
Beispiel #10
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)))
Beispiel #11
0
 def __init__(self):
     self.image = graphics.Canvas(150, 450)
     thermometer = 'therm.gif'
     self.image.draw_image((0, 0), thermometer)
Beispiel #12
0
 def __init__(self):
     pygame.init()
     pygame.display.set_caption(config.window_caption)
     zope.event.subscribers.append(self.game_event_handler)
     self.canvas = graphics.Canvas()
Beispiel #13
0
    def __init__(self, app, channel: audio.Channel, y_off=0):
        self.app = app
        self.channel = channel
        self.channel.update()
        self.color = channel.color
        y_off *= self.SPACING
        self.y = y_off
        self.scroll_y = 0

        # DIVS
        self.channel_view = graphics.Canvas(app,
                                            0.7,
                                            0.2,
                                            0.1,
                                            0.0 + y_off,
                                            bg=self.BG,
                                            border_width=1,
                                            border_color=self.color,
                                            xoffset=-1,
                                            yoffset=0 + self.y,
                                            hoffset=-2)
        self.presets = graphics.Div(app,
                                    0.1,
                                    0.2,
                                    0.0,
                                    0.0 + y_off,
                                    bg=self.BG,
                                    border_width=1,
                                    border_color=self.color)
        self.buttons = graphics.Div(app,
                                    0.2,
                                    0.2,
                                    0.8,
                                    0.0 + y_off,
                                    bg=self.BG,
                                    border_width=1,
                                    border_color=self.color)

        # PRESETS
        #self.compression_label = graphics.Label(app, '', y=0.01 + y_off, fg=self.FG_1, bg=self.BG)
        #self.compression_label.define_pre_label('COMP ')
        self.mono_label = graphics.Label(app,
                                         '',
                                         y=0.01 + y_off,
                                         fg=self.FG_1,
                                         bg=self.BG,
                                         fontscale=1.0)
        self.track_count_label = graphics.Label(app,
                                                '',
                                                y=0.06 + y_off,
                                                fg=self.FG_1,
                                                bg=self.BG)

        # TRACK NAME
        self.track_name_label = graphics.Label(app,
                                               '',
                                               x=0.1,
                                               y=0.002 + y_off,
                                               fontscale=1.3,
                                               fg=self.FG_2,
                                               bg=self.BG)

        # TIME
        self.elapsed_label = graphics.Label(app,
                                            '',
                                            x=0.12,
                                            y=0.16 + y_off,
                                            yoffset=-10,
                                            fontscale=0.9,
                                            fg=self.FG_2,
                                            bg=self.BG)
        self.total_label = graphics.Label(app,
                                          '',
                                          x=0.7,
                                          y=0.16 + y_off,
                                          yoffset=-10,
                                          fontscale=0.9,
                                          fg=self.FG_2,
                                          bg=self.BG)

        # NEXT PREV
        self.prev_label = graphics.Label(app,
                                         '',
                                         x=0.13,
                                         y=0.067 + y_off,
                                         fontscale=1,
                                         fg=self.FG_1,
                                         bg=self.BG)
        self.prev_label.define_pre_label('Prev: ')
        self.next_label = graphics.Label(app,
                                         '',
                                         x=0.45,
                                         y=0.067 + y_off,
                                         fontscale=1,
                                         fg=self.FG_1,
                                         bg=self.BG)
        self.next_label.define_pre_label('Next: ')

        # BAR
        self.timebar = graphics.ProgressBar(app,
                                            self.channel_view,
                                            x=0.18,
                                            y=0.8,
                                            w=0.65,
                                            h=0.1,
                                            xoffset=10,
                                            yoffset=-5,
                                            fill_color=self.color,
                                            border_color=self.color)

        # CHANNEL
        self.channel_label = graphics.RightAlignLabel(app,
                                                      self.channel.name,
                                                      x=0.817,
                                                      y=0.005 + y_off,
                                                      fontscale=1.5,
                                                      fg=self.color,
                                                      bg=self.BG)

        # PAUSED
        self.paused_label = graphics.Label(app,
                                           '',
                                           x=0.7,
                                           y=0.065 + y_off,
                                           fontscale=1.3,
                                           fg='white',
                                           bg=self.BG)

        # BUTTONS
        LINE1Y = 0.03
        LINE2Y = 0.11
        CENTERX = 0.8875
        SIZE = 0.02

        self.pause_button = graphics.Button(app,
                                            SIZE,
                                            SIZE,
                                            CENTERX + 0.0,
                                            LINE1Y + y_off,
                                            img_name=app.IMG + 'play.png',
                                            img_scale=0.9,
                                            background=self.BUTTONBG,
                                            cmd=self.cmd_play)
        self.next_button = graphics.Button(app,
                                           SIZE,
                                           SIZE,
                                           CENTERX + 0.03,
                                           LINE1Y + y_off,
                                           img_name=app.IMG + 'next.png',
                                           background=self.BUTTONBG,
                                           cmd=self.cmd_next)
        self.last_button = graphics.Button(app,
                                           SIZE,
                                           SIZE,
                                           CENTERX + 0.06,
                                           LINE1Y + y_off,
                                           img_name=app.IMG + 'last.png',
                                           background=self.BUTTONBG,
                                           cmd=self.cmd_last)
        self.prev_button = graphics.Button(app,
                                           SIZE,
                                           SIZE,
                                           CENTERX - 0.03,
                                           LINE1Y + y_off,
                                           img_name=app.IMG + 'prev.png',
                                           background=self.BUTTONBG,
                                           cmd=self.cmd_back)
        self.first_button = graphics.Button(app,
                                            SIZE,
                                            SIZE,
                                            CENTERX - 0.06,
                                            LINE1Y + y_off,
                                            img_name=app.IMG + 'first.png',
                                            background=self.BUTTONBG,
                                            cmd=self.cmd_first)

        self.stop_button = graphics.Button(app,
                                           SIZE,
                                           SIZE,
                                           CENTERX,
                                           LINE2Y + y_off,
                                           img_name=app.IMG + 'stop.png',
                                           img_scale=0.8,
                                           background=self.BUTTONBG,
                                           cmd=self.cmd_stop)

        self.ch_gain_label = graphics.Label(app,
                                            'CH GAIN',
                                            x=0.9275,
                                            y=0.15 + y_off,
                                            fontscale=0.6,
                                            fg=self.FG_1,
                                            bg=self.BG)
        self.tr_gain_label = graphics.Label(app,
                                            'TR GAIN',
                                            x=0.82,
                                            y=0.15 + y_off,
                                            fontscale=0.6,
                                            fg=self.FG_1,
                                            bg=self.BG)

        self.ch_gain_inc = graphics.Incrementor(app,
                                                min=self.GAIN_MIN,
                                                max=self.GAIN_MAX,
                                                step=self.GAIN_STEP_INC,
                                                x=0.92,
                                                y=0.111 + y_off,
                                                w=5,
                                                yoffset=0,
                                                bg='#000',
                                                fg=self.color,
                                                buttonbg=self.BUTTONBG,
                                                fontscale=1)
        self.tr_gain_inc = graphics.Incrementor(app,
                                                min=self.GAIN_MIN,
                                                max=self.GAIN_MAX,
                                                step=self.GAIN_STEP_INC,
                                                x=0.8125,
                                                y=0.111 + y_off,
                                                w=5,
                                                yoffset=0,
                                                bg='#000',
                                                fg=self.color,
                                                buttonbg=self.BUTTONBG,
                                                fontscale=1)

        self.parts = (
            self.channel_view,
            self.presets,
            self.buttons,
            self.mono_label,
            self.track_count_label,  # Removed gain and comp labels
            self.track_name_label,
            self.elapsed_label,
            self.total_label,
            self.next_label,
            self.prev_label,
            self.channel_label,
            self.paused_label,  # no timebar
            self.pause_button,
            self.next_button,
            self.last_button,
            self.prev_button,
            self.first_button,
            self.stop_button,
            self.ch_gain_label,
            self.tr_gain_label,
            self.ch_gain_inc,
            self.tr_gain_inc)

        app.track(self)
        self.update_labels()
        self.update_times()
        self.ch_gain_inc.set(str(self.channel.gain))
        self.tr_gain_inc.set(str(self.current.gain))
Beispiel #14
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)
Beispiel #15
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)