Beispiel #1
0
def display_external_audio():
    a = AudioListener()

    import raylibpy

    raylibpy.init_window(1024, 300, 'external audio')
    raylibpy.set_target_fps(60)

    while not raylibpy.window_should_close():

        d = a.get_audio()
        stft = np.abs(librosa.stft(d, n_fft=512, hop_length=1))
        spec = librosa.amplitude_to_db(stft, ref=np.max)

        raylibpy.begin_drawing()
        raylibpy.clear_background(raylibpy.DARKBLUE)

        print(0)
        for i in range(len(spec)):
            val = (spec[i][0] + 80)

            x = i * 4
            y = 300 - val
            w = 4
            h = val

            print(val)

            raylibpy.draw_rectangle(x, y, w, h, raylibpy.GREEN)

        raylibpy.end_drawing()

    a.close()
Beispiel #2
0
def main():
    current_vis_index = 0

    # Init Raylib window
    rl.init_window(config.screen_width, config.screen_height, "Audio Visualizer")
    rl.set_target_fps(config.target_fps)

    def audio_callback(audio_data, frame_count, time_info, status_flags):
        unpacked_audio = struct.unpack(str(config.audio_sample_size) + 'h', audio_data)
        visualizers[current_vis_index].on_recieve_audio_data(unpacked_audio)
    
        return None, pyaudio.paContinue

    # Open the audio stream
    pa = pyaudio.PyAudio()
    audio_stream = pa.open(
        format=pyaudio.paInt16, 
        channels=1, 
        rate=config.audio_sample_rate, 
        input=True, 
        frames_per_buffer=config.audio_sample_size,
        stream_callback=audio_callback
    )

    debug_mode = True

    # Enter the main loop
    while not rl.window_should_close():
        rl.begin_drawing()

        visualizers[current_vis_index].on_draw(debug_mode)

        key = rl.get_key_pressed()
        if key == ord('d'):
            debug_mode = not debug_mode
        elif key == ord('n'):
            current_vis_index += 1
            current_vis_index %= len(visualizers)
        elif key == ord('p'):
            current_vis_index -= 1
            current_vis_index %= len(visualizers)

        if debug_mode:
            rl.draw_text(f"{rl.get_fps()} fps", 5, 5, 20, rl.RAYWHITE)
            
            length = rl.measure_text(visualizers[current_vis_index].name, 20)
            rl.draw_text(visualizers[current_vis_index].name, config.screen_width - length - 5, 5, 20, rl.RAYWHITE)

        rl.end_drawing()

    # Cleanup time
    audio_stream.stop_stream()
    audio_stream.close()
    pa.terminate()
    rl.close_window()
Beispiel #3
0
def ray_disp(wv):
    raylibpy.init_window(1000, 400, 'win')

    raylibpy.begin_drawing()
    raylibpy.clear_background(RAYWHITE)
    for i in range(40000):
        x = i / 40
        y = wv[i] * 400 + 200
        raylibpy.draw_circle(x, y, 1, BLUE)
        #print(x, ", ", y)
    raylibpy.end_drawing()
    while not raylibpy.window_should_close():
        continue
    raylibpy.close_window()
Beispiel #4
0
def main():

    rl.init_window(rl.get_screen_width(), rl.get_screen_height(), "raylib [core] example - basic window")
    rl.toggle_fullscreen()

    camera = rl.Camera(
        rl.Vector3(4.0, 2.0, 4.0),
        rl.Vector3(0.0, 1.0, 0.0),
        rl.Vector3(0.0, 1.0, 0.0),
        60.0,
        rl.CAMERA_PERSPECTIVE)

    rl.set_camera_mode(camera, rl.CAMERA_FREE)
    rl.set_target_fps(60)

    while not rl.window_should_close():
        rl.update_camera(byref(camera))

        rl.begin_drawing()
        rl.clear_background(rl.DARKGRAY)
        rl.begin_mode3d(camera)

        rl.draw_cube(rl.Vector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.BLUE)
        rl.draw_cube(rl.Vector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.LIME)
        rl.draw_cube(rl.Vector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.GOLD)

        rl.draw_sphere(rl.Vector3(0.0, 0.0, 0.0), 5.0, rl.LIME)

        rl.draw_text("Congrats! You created your first window!", 190, 200, 20, rl.WHITE)

        rl.draw_grid(40, 1)

        rl.end_mode3d()
        rl.end_drawing()

    rl.close_window()
Beispiel #5
0
import os

os.environ["RAYLIB_BIN_PATH"] = "raylib-2.0.0-Win64-mingw/lib/"
import raylibpy

raylibpy.init_window(900, 500, "Hello")
ball = raylibpy.Vector2(100, 100)

raylibpy.set_target_fps(60)

while not raylibpy.window_should_close():

    if raylibpy.is_key_down(raylibpy.KEY_RIGHT):
        ball.x += 5
    if raylibpy.is_key_down(raylibpy.KEY_DOWN):
        ball.y += 5

    raylibpy.begin_drawing()
    raylibpy.clear_background(raylibpy.Color(0, 0, 255, 255))
    raylibpy.draw_circle(ball.x, ball.y, 10.0, raylibpy.BLACK)
    raylibpy.end_drawing()

raylibpy.close_window()
def main():

    # Initialization
    # ---------------------------------------------------------------
    screen_width = 800
    screen_height = 450

    rl.init_window(screen_width, screen_height,
                   "raylib [core] example - 3d camera free")

    # Define the camera to look into our 3d world
    camera = rl.Camera(rl.Vector3(4.0, 2.0, 4.0), rl.Vector3(0.0, 0.0, 0.0),
                       rl.Vector3(0.0, 1.0, 0.0), 45.0, rl.CAMERA_PERSPECTIVE)

    cube_position = rl.Vector3(0.0, 0.0, 0.0)

    rl.set_camera_mode(camera, rl.CAMERA_FREE)

    rl.set_target_fps(60)
    # ---------------------------------------------------------------

    # Main game loop
    while not rl.window_should_close():

        # Update
        # -----------------------------------------------------------
        rl.update_camera(byref(camera))
        if rl.is_key_down(rl.KEY_Z):
            camera.target = rl.Vector3(0.0, 0.0, 0.0)
        # -----------------------------------------------------------

        # Draw
        # -----------------------------------------------------------
        rl.begin_drawing()

        rl.clear_background(rl.RAYWHITE)

        rl.begin_mode3d(camera)

        rl.draw_cube(cube_position, 2.0, 2.0, 2.0, rl.RED)
        rl.draw_cube_wires(cube_position, 2.0, 2.0, 2.0, rl.MAROON)

        rl.draw_grid(10, 1.0)

        rl.end_mode3d()

        rl.draw_rectangle(10, 10, 320, 133, rl.fade(rl.SKYBLUE, 0.5))
        rl.draw_rectangle_lines(10, 10, 320, 133, rl.BLUE)

        rl.draw_text("Free camera default controls:", 20, 20, 10, rl.BLACK)
        rl.draw_text("- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.DARKGRAY)
        rl.draw_text("- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.DARKGRAY)
        rl.draw_text("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10,
                     rl.DARKGRAY)
        rl.draw_text("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40,
                     100, 10, rl.DARKGRAY)
        rl.draw_text("- Z to Zoom to (0, 0, 0)", 40, 120, 10, rl.DARKGRAY)

        rl.end_drawing()
        # -----------------------------------------------------------

    # De-Initialization
    # ---------------------------------------------------------------
    rl.close_window()  # Close window and OpenGL context
Beispiel #7
0
def main():

    # Initialization
    # ---------------------------------------------------------------
    screen_width = 800
    screen_height = 450

    rl.init_window(screen_width, screen_height, "raylib [core] example - 3d camera 1st person")

    # Define the camera to look into our 3d world (position, target, up vector)
    camera = rl.Camera(
        rl.Vector3(4.0, 2.0, 4.0),
        rl.Vector3(0.0, 1.8, 0.0),
        rl.Vector3(0.0, 1.0, 0.0),
        60.0,
        rl.CAMERA_PERSPECTIVE
    )

    # Generates some random columns
    heights = []
    positions = []
    colors = []

    for i in range(MAX_COLUMNS):
        heights.append(rl.get_random_value(1, 12))
        positions.append(rl.Vector3(
                rl.get_random_value(-15, 15),
                heights[-1] / 2,
                rl.get_random_value(-15, 15)
            )
        )
        colors.append(rl.Color(
                rl.get_random_value(20, 255),
                rl.get_random_value(10, 55),
                30,
                255
            )
        )

    rl.set_camera_mode(camera, rl.CAMERA_FIRST_PERSON)

    rl.set_target_fps(60)
    # ---------------------------------------------------------------

    # Main game loop
    while not rl.window_should_close():

        # Update
        # -----------------------------------------------------------
        rl.update_camera(byref(camera))
        # -----------------------------------------------------------

        # Draw
        # -----------------------------------------------------------
        rl.begin_drawing()

        rl.clear_background(rl.RAYWHITE)

        rl.begin_mode3d(camera)

        rl.draw_plane(rl.Vector3(0.0, 0.0, 0.0), rl.Vector2(32.0, 32.0), rl.LIGHTGRAY)
        rl.draw_cube(rl.Vector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.BLUE)
        rl.draw_cube(rl.Vector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.LIME)
        rl.draw_cube(rl.Vector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.GOLD)

        # Draw some cubes around
        for i, position in enumerate(positions):
            rl.draw_cube(position, 2.0, heights[i], 2.0, colors[i])
            rl.draw_cube_wires(position, 2.0, heights[i], 2.0, rl.MAROON)

        rl.draw_rectangle(camera.target.x, -500, 1, screen_height * 4, rl.GREEN)
        rl.draw_rectangle(-500, camera.target.y, screen_width * 4, 1, rl.GREEN)

        rl.end_mode3d()

        # rl.draw_text(b"SCREEN AREA", 640, 10, 20, rl.RED)

        rl.draw_rectangle(10, 10, 220, 70, rl.fade(rl.SKYBLUE, 0.5))
        rl.draw_rectangle_lines(10, 10, 220, 70, rl.BLUE)
        
        rl.draw_text("First person camera default controls:", 20, 20, 10, rl.BLACK)
        rl.draw_text("- Move with keys: W, A, S, D", 40, 40, 10, rl.DARKGRAY)
        rl.draw_text("- Mouse move to look around", 40, 60, 10, rl.DARKGRAY)

        rl.end_drawing()
        # -----------------------------------------------------------

    # De-Initialization
    # ---------------------------------------------------------------
    rl.close_window()       # Close window and OpenGL context