Пример #1
0
def print_time(threadName, delay):

    stddraw.createWindow()

    count = 0
    while count < 5:
        time.sleep(delay)
        count += 1
    print "%s: %s" % (threadName, time.ctime(time.time()))
Пример #2
0
def print_time( threadName, delay):

	stddraw.createWindow()

	count = 0
	while count < 5:
		time.sleep(delay)
		count += 1
    	print "%s: %s" % ( threadName, time.ctime(time.time()) )
Пример #3
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)
Пример #4
0
#-----------------------------------------------------------------------
# menubouncingball.py
#-----------------------------------------------------------------------

import os
import sys
import pygame
from pygame.locals import *

import stddrawpygame as stddraw
from popup_menu import PopupMenu

# Draw a bouncing ball.
stddraw.createWindow()
stddraw.setXscale(-1.0, 1.0)
stddraw.setYscale(-1.0, 1.0)

rx = .480
ry = .860
vx = .015
vy = .023

radius = .05
dt = 20

#--menu stuff--
global menu_data
global _surface
menu_data = (
    'Main',
    'Save',
Пример #5
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()
Пример #6
0
global _surface
menu_data = (
    'Main',
    'Save',
    '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:
Пример #7
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()


Пример #8
0
 def run(self):
   now = datetime.datetime.now()
   stddraw.createWindow()
   print "%s says Hello World at time: %s" % (self.getName(), now)