예제 #1
0
By Jordan Sorokin, 3/13/2017
"""

# imports
import thread, time, winsound
from PulsePal import PulsePalObject  # Import PulsePalObject

# Initializing PulsePal
pp = PulsePalObject()  # Create a new instance of a PulsePal object
pp.connect(
    'COM3'
)  # Connect to PulsePal on port COM3 (open port, handshake and receive firmware version)
pp.setDisplay("Connected to:", "Python")
print('Connected to PulsePal, version ' + str(pp.firmwareVersion))
winsound.PlaySound('SystemExclamation', winsound.SND_ALIAS)
time.sleep(2)

# set up the pulse train for ch. 1
pulsewidth = input("pulse width (s): ")
pp.programOutputChannelParam("phase1Voltage", 1, 5.0)  # 5V pulse
pp.programOutputChannelParam("isBiphasic", 1, 0)  # only positive, monophasic


# function for checking keypress
def input_thread(key):
    raw_input()
    key.append(None)


# initialize loop
예제 #2
0
 def close(self, event=None):
     winsound.PlaySound(None, winsound.SND_FILENAME)
     self.num_beats = None
     self.top.destroy()
예제 #3
0
파일: pong.py 프로젝트: mute019/PONG-2D
def game_loop():
    user32 = ctypes.windll.user32
    height = user32.GetSystemMetrics(1)
    width = user32.GetSystemMetrics(0)
    wn = turtle.Screen()
    wn.title("Pong")
    wn.bgcolor("black")

    wn.setup(width=width, height=height - 90, starty=0, startx=0)
    wn.tracer(0)

    paddle_a = turtle.Turtle()
    paddle_b = turtle.Turtle()
    ball = turtle.Turtle()
    pen = turtle.Turtle()
    cred = turtle.Turtle()

    # Paddle A

    paddle_a.speed(0)
    paddle_a.shape("square")
    paddle_a.color("white")
    paddle_a.shapesize(stretch_wid=5, stretch_len=1)
    paddle_a.penup()
    paddle_a.goto(-(user32.GetSystemMetrics(0) / 2) + 90, 0)

    # Paddle B

    paddle_b.speed(0)
    paddle_b.shape("square")
    paddle_b.color("white")
    paddle_b.shapesize(stretch_wid=5, stretch_len=1)
    paddle_b.penup()
    paddle_b.goto((user32.GetSystemMetrics(0) / 2) - 90, 0)

    # Ball

    ball.speed(0)
    ball.shape("circle")
    ball.color("white")
    ball.penup()
    ball.goto(0, 0)
    ball.dx = 1.5
    ball.dy = 1.5

    # Pen

    pen.speed(0)
    pen.shape("square")
    pen.color("white")
    pen.penup()
    pen.hideturtle()
    pen.goto(0, ((user32.GetSystemMetrics(1) / 2) - 130))
    pen.write("SCORE: 0 - SCORE: 0", align="center", font=("Courier", 24, "bold"))

    # Players IDs

    cred.speed(0)
    cred.shape("square")
    cred.color("white")
    cred.penup()
    cred.hideturtle()
    cred.goto(0, ((user32.GetSystemMetrics(1) / 2) - 90))
    cred.write("{}      Vs      {}".format(player1, player2), align="center", font=("Courier", 24, "bold"))

    # Score
    score_a = 0
    score_b = 0

    # paddle movement fuction
    def pad_a_u():
        paddle_a_up(paddle_a)

    def pad_a_d():
        paddle_a_down(paddle_a)

    def pad_b_u():
        paddle_b_up(paddle_b)

    def pad_b_d():
        paddle_b_down(paddle_b)

    while True:
        wn.update()
        # Keyboard bindings

        wn.listen()
        wn.onkeypress(pad_a_u, "w")
        wn.onkeypress(pad_a_d, "s")
        wn.onkeypress(pad_b_u, "Up")
        wn.onkeypress(pad_b_d, "Down")

        # Move the ball
        ball.setx(ball.xcor() + ball.dx)
        ball.sety(ball.ycor() + ball.dy)

        # Border checking
        # paddle_a
        if paddle_a.ycor() > ((height / 2) - 190):
            paddle_a.sety((height / 2) - 190)

        if paddle_a.ycor() - 100 < (-(height / 2)):
            paddle_a.sety(-(height / 2) + 100)
        # paddle_b

        if paddle_b.ycor() > ((height / 2) - 190):
            paddle_b.sety((height / 2) - 190)

        if paddle_b.ycor() - 100 < (-(height / 2)):
            paddle_b.sety((-(height / 2)) + 100)

        # Top and bottom
        if ball.ycor() > ((height / 2) - 150):
            ball.sety((height / 2) - 150)
            ball.dy *= -1
            winsound.PlaySound("Resources\Sound\sfx.wav", winsound.SND_ASYNC)

        elif ball.ycor() < (-(height / 2) + 50):
            ball.sety(-(height / 2) + 50)
            ball.dy *= -1
            winsound.PlaySound("Resources\Sound\sfx.wav", winsound.SND_ASYNC)

        # Left and right
        if ball.xcor() > ((width / 2) - 55):
            score_a += 1
            pen.clear()
            pen.write("SCORE: {} - SCORE: {}".format(score_a, score_b), align="center", font=("Courier", 24, "bold"))
            ball.goto(450, 0)
            ball.dx *= -1

        elif ball.xcor() < (-(width / 2) + 55):
            score_b += 1
            pen.clear()
            pen.write("SCORE: {} - SCORE: {}".format(score_a, score_b), align="center", font=("Courier", 24, "bold"))
            ball.goto(-450, 0)
            ball.dx *= -1

        # Paddle and ball collisions

        # paddle_a right side collision

        if ball.xcor() < -((width / 2) - 110) and ball.ycor() < paddle_a.ycor() + 50 and ball.ycor() > paddle_a.ycor() - 50:
            ball.dx *= -1
            winsound.PlaySound("Resources\Sound\sfx.wav", winsound.SND_ASYNC)

        # paddle_b left side collision

        elif ball.xcor() > ((width / 2) - 110) and ball.ycor() < paddle_b.ycor() + 50 and ball.ycor() > paddle_b.ycor() - 50:
            ball.dx *= -1
            winsound.PlaySound("Resources\Sound\sfx.wav", winsound.SND_ASYNC)

        # result screen

        if score_a is 10 and score_a > score_b:
            return score_a, score_b, wn

        elif score_b is 10 and score_b > score_a:
            return score_a, score_b, wn
예제 #4
0
turtle.listen()
turtle.onkey(turnleft, "Left")
turtle.onkey(turnright, "Right")
turtle.onkey(inscreasespeed, "Up")




while True:
    player.forward(speed)
    comp.forward(12)

    #Boundary Player Checking x coordinate
    if player.xcor() > 290 or player.xcor() <-290:
        player.right(180)
        winsound.PlaySound('bounce.wav', winsound.SND_ASYNC)

    #Boundary Player Checking y coordinate
    if player.ycor() > 290 or player.ycor() <-290:
        player.right(180)
        winsound.PlaySound('bounce.wav', winsound.SND_ASYNC)

    #Boundary Comp Checking x coordinate
    if comp.xcor() > 290 or comp.xcor() <-290:
        comp.right(random.randint(10,170))
        winsound.PlaySound('bounce.wav', winsound.SND_ASYNC)

    #Boundary Comp Checking y coordinate
    if comp.ycor() > 290 or comp.ycor() <-290:
        comp.right(random.randint(10,170))
        winsound.PlaySound('bounce.wav', winsound.SND_ASYNC)
예제 #5
0
win.listen()
win.onkeypress(paddle_a_up, "w")
win.onkeypress(paddle_a_down, "s")
win.onkeypress(paddle_b_up, "Up")
win.onkeypress(paddle_b_down, "Down")

while True:
    win.update()
    ball.sety(ball.ycor() + ball.dy)
    ball.setx(ball.xcor() + ball.dx)

    if ball.ycor() > 290:
        ball.sety(290)
        ball.dy *= -1
        winsound.PlaySound("boing.wav", winsound.SND_ASYNC)

    if ball.ycor() < -290:
        ball.sety(-290)
        ball.dy *= -1
        winsound.PlaySound("boing.wav", winsound.SND_ASYNC)

    if ball.xcor() > 390:
        ball.goto(0, 0)
        ball.dx *= -1
        score_a += 1
        pen.clear()
        pen.write("Player 1 : {} | Player 2 : {}".format(score_a, score_b),
                  align="center",
                  font=("Arial", 18, "normal"))
예제 #6
0
 def alarm_check(self):
     time_now = datetime.now()
     if f'{str(time_now.hour)}:{str(time_now.minute)}' in (
             self.alarm.list_alarms.toPlainText().split()):
         winsound.PlaySound('alarm_clock.wav', winsound.SND_FILENAME)
     QTimer().singleShot(3000, self.alarm_check)
예제 #7
0
def playmusic():
    time.sleep(sleeptime)
    winsound.PlaySound(soundFile, winsound.SND_ASYNC)
예제 #8
0
model.compile(optimizer=adam,
              loss='categorical_crossentropy',
              metrics=['accuracy'])

start = time.time()
model.fit(x_train,
          y_train,
          validation_data=(x_test, y_test),
          epochs=5,
          batch_size=64)

# save the model
# model.save("model.hdf5")

loss, accuracy = model.evaluate(x_test, y_test, batch_size=32)
print('Loss', loss, "Accuaracy", accuracy)

print("--- %s seconds ---" % (time.time() - start))

y_pred = model.predict(x_test)
y_pred = [np.round(x) for x in y_pred]
y_pred = np.array(y_pred)
print('Confusion Matrix')
#binary
# print(confusion_matrix(y_test, y_pred))
#multiclass
print(confusion_matrix(y_test.argmax(axis=1), y_pred.argmax(axis=1)))
print('Classification Report')
print(classification_report(y_test, y_pred))
winsound.PlaySound("SystemHand", winsound.SND_ALIAS)
예제 #9
0
    random.shuffle(words)
    q = random.choice(words)

    print()

    print("*Question # {}".format(n))
    print(q)  # 문제 출력

    x = input()  # 타이핑 입력

    print()

    if str(q).strip() == str(x).strip():
        print("Pass!")
        # 정답 소리 재생
        winsound.PlaySound("./sound/good.wav", winsound.SND_FILENAME)
        cor_cnt += 1
    else:
        # 오답 소리 재생
        winsound.PlaySound("./sound/bad.wav", winsound.SND_FILENAME)
        print("Wrong!")

    n += 1  # 다음 문제 전환

end = time.time()  # End Time
et = end - start  # 총 게임시간
et = format(et, ".3f")  # 소수 셋째 자리 출력(총 게임시간)

if cor_cnt >= 3:
    print("합격")
else:
예제 #10
0
# -*- coding: utf-8 -*-
import winsound
import MySQLdb
import time

while True:
    db = MySQLdb.connect("127.0.0.1", "root", "root", "app", charset='utf8')
    cursor = db.cursor()
    cursor.execute("SELECT alert FROM notice")
    results = cursor.fetchone()

    if results[0] == 0:
        print('ok')
    elif results[0] == 1:
        print('got you!')
        winsound.PlaySound('alert.wav', flags=1)
        time.sleep(5)
    db.close
    time.sleep(2)
 def playSound(self, ring):
     try:
         winsound.PlaySound(ring, winsound.SND_ASYNC)
     except:
         pass
예제 #12
0
 def stop_sound(self):
     winsound.PlaySound(None, winsound.SND_FILENAME)
예제 #13
0
 def play_sound(self):
     """Function working only for Windows"""
     try:
         winsound.PlaySound(self.menubar.filename, winsound.SND_ASYNC)
     except NameError:
         tk.messagebox.showerror("File not found", "File path is wrong. Please try again.")
예제 #14
0
def reminder():
    for x in range(5):
        winsound.Beep(500, 500)
    winsound.PlaySound("HydrationSound.wav", winsound.SND_ASYNC)
예제 #15
0
wn.onkeypress(paddle_a_up, "w")
wn.onkeypress(paddle_a_down, "s")
wn.onkeypress(paddle_b_up, "Up")
wn.onkeypress(paddle_b_down, "Down")


while True:
    
    wn.update()
    
    ball.setx(ball.xcor() + ball.dx)
    ball.sety(ball.ycor() + ball.dy)
    if ball.ycor() > 290:
        ball.sety(290)
        ball.dy *= -0.5
        winsound.PlaySound("bounce,wav", winsound.SND_ASYNC)
        
    if ball.ycor() < -290:
        ball.sety(-290)
        ball.dy *= -0.5
        winsound.PlaySound("bounce,wav", winsound.SND_ASYNC)
    
    if ball.xcor() > 350:
        ball.goto(0, 0)
        ball.dx *= -0.5      
        score_a += 1
        pen.clear()
        pen.write("Player A: {}  Player B: {}".format(score_a, score_b), align="center", font=("Courier", 24, "normal"))