Beispiel #1
0
def main():

    stddraw.createWindow()

    # Create keyboardDict, a dictionary relating each keyboard key
    # to a guitar string.
    keyboardDict = {}
    i = 0
    for key in _KEYBOARD:
        factor = 2**((i - 24) / 12.0)
        guitarString = guitarstring.GuitarString(_CONCERT_A * factor)
        keyboardDict[key] = guitarString
        i += 1

    # pluckedGuitarStrings is the set of all guitar strings that have
    # been plucked.
    pluckedGuitarStrings = set()

    # loopCount is used to control the frequency of calls of
    # stddraw.show().
    loopCount = 1023

    # The main input loop.
    while True:

        # Call stddraw.show() occasionally to capture keyboard events.
        if loopCount == 1023:
            stddraw.show()
            loopCount = 0
        loopCount += 1

        if stddraw.hasNextKeyTyped():

            # Fetch the key that the user just typed.
            key = stddraw.nextKeyTyped()

            # Figure out which guitar string to pluck, and pluck it.
            try:
                guitarString = keyboardDict[key]
                guitarString.pluck()
                pluckedGuitarStrings.add(guitarString)
            except KeyError:
                pass

        # Add up the samples from each plucked guitar string. Also
        # advance the simulation of each plucked guitar string by
        # one step.
        sample = 0.0
        for guitarString in pluckedGuitarStrings:
            sample += guitarString.sample()
            guitarString.tic()

        # Play the total.
        stdaudio.playSample(sample)
        if e.text == 'Quit':
            quit()


while True:
    #--menu stuff--
    pygame.display.flip()
    for e in pygame.event.get():
        if e.type == MOUSEBUTTONUP:
            ## Blocking popup menu.
            PopupMenu(menu_data)
        elif e.type == USEREVENT:
            if e.code == 'MENU':
                handle_menu(e)
    # Update ball position and draw it there.
    if abs(rx + vx) + radius > 1.0:
        vx = -vx
    if abs(ry + vy) + radius > 1.0:
        vy = -vy
    rx = rx + vx
    ry = ry + vy
    #stddraw.clear()

    stddraw.setPenColor(stddraw.GRAY)
    stddraw.filledSquare(0, 0, 1.0)

    stddraw.setPenColor(stddraw.BLACK)
    stddraw.filledCircle(rx, ry, radius)

    stddraw.show(dt)
Beispiel #3
0
import stddrawpygame
import pygame

#-------------------------------------------
# testing client
stddrawpygame.createWindow()
stddrawpygame.setFontFamily("calibri")
stddrawpygame.setFontSize(20)

stddrawpygame._pixel(0.5, 0.5)
stddrawpygame.circle(0.5, 0.5, 0.25)
stddrawpygame.square(0.5, 0.5, 0.5)
stddrawpygame.rectangle(0.3, 0.2, 0.2, 0.2)

stddrawpygame.text(0.75, 0.75, "hello my name is kuni")

stddrawpygame.save()
while True:
    stddrawpygame.show()
Beispiel #4
0
    'Quit',
)
def handle_menu(e):
    print 'Menu event: %s.%d: %s' % (e.name,e.item_id,e.text)
    if e.name == 'Main':
        if e.text == 'Save':
            stddraw.save(_surface)
        if e.text == 'Quit':
            quit()

## Main loop.
stddraw.createWindow()
stddraw.setXscale(-1.0, 1.0)
stddraw.setYscale(-1.0, 1.0)
stddraw.circle(0, 0, 0.5)
stddraw.show()
_surface = pygame.Surface.copy(stddraw._surface)

while 1:
    stddraw.clear()
    stddraw.circle(0, 0, 0.5)

    for e in pygame.event.get():
        if e.type == MOUSEBUTTONUP:
            ## Blocking popup menu.
            PopupMenu(menu_data)
        elif e.type == USEREVENT:
            if e.code == 'MENU':
                handle_menu(e)
    
    
        if e.text == 'Quit':
            quit()

while True:
    #--menu stuff--
    pygame.display.flip()
    for e in pygame.event.get():
        if e.type == MOUSEBUTTONUP:
            ## Blocking popup menu.
            PopupMenu(menu_data)
        elif e.type == USEREVENT:
            if e.code == 'MENU':
                handle_menu(e)
    # Update ball position and draw it there.
    if abs(rx + vx) + radius > 1.0:
        vx = -vx
    if abs(ry + vy) + radius > 1.0:
        vy = -vy
    rx = rx + vx
    ry = ry + vy
    #stddraw.clear()

    stddraw.setPenColor(stddraw.GRAY)
    stddraw.filledSquare(0, 0, 1.0)

    stddraw.setPenColor(stddraw.BLACK)
    stddraw.filledCircle(rx, ry, radius)

    stddraw.show(dt)

Beispiel #6
0
import stddrawpygame
import pygame

#-------------------------------------------
# testing client
stddrawpygame.createWindow()
stddrawpygame.setFontFamily("calibri")
stddrawpygame.setFontSize(20)

stddrawpygame._pixel(0.5, 0.5)
stddrawpygame.circle(0.5, 0.5, 0.25)
stddrawpygame.square(0.5, 0.5, 0.5)
stddrawpygame.rectangle(0.3, 0.2, 0.2, 0.2)

stddrawpygame.text(0.75, 0.75, "hello my name is kuni")

stddrawpygame.save()
while True:
	stddrawpygame.show()