Waves creation using Raylib

Arun UdayakumarArun Udayakumar
1 min read

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project(ex1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Find the library
find_library(RAYLIB_LIBRARY NAMES raylib PATHS /usr/local/lib /usr/lib)
include_directories(${RAYLIB_INCLUDE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
add_executable(ex1 main.cpp)
target_link_libraries(ex1 ${RAYLIB_LIBRARY})

include(GNUInstallDirs)
install(TARGETS ex1
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
#include "raylib.h"
#include <math.h>

#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 450
#define AMPLITUDE 50.0f
#define FREQUENCY 0.1f
#define SPEED 0.02f
#define THICKNESS 3

int main(void)
{
    // Initialization
    InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - animated sine wave");

    float time = 0.0f;

    SetTargetFPS(60); // Set our game to run at 60 frames-per-second

    // Main game loop
    while (!WindowShouldClose()) // Detect window close button or ESC key
    {
        // Update
        time += SPEED*1;

        // Draw
        BeginDrawing();
        ClearBackground({63, 162, 246});

        // Draw the sine wave with thicker lines
        for (int x = 0; x < SCREEN_WIDTH; x++)
        {
            float y = SCREEN_HEIGHT / 2.0f + AMPLITUDE * sinf(FREQUENCY * x*0.5 + time);
            if(x%5==0)
            {
                DrawCircle(x, (int)y*1.1, THICKNESS, {0,255,255,255});
            }
            if(x%10==0)
            {
                y = SCREEN_HEIGHT / 2.0f + AMPLITUDE * cosf(FREQUENCY * x*0.5 + time);
                DrawCircle(x, (int)y*1.2, 8, SKYBLUE);
            }
            if(x%12==0)
            {
                DrawCircle(x, (int)y*1.3, 5, BLUE);
            }
            else
            {
                DrawCircle(x, (int)y, 1, BLUE);
            }
        }

        EndDrawing();
    }

    // De-Initialization
    CloseWindow(); // Close window and OpenGL context

    return 0;
}
0
Subscribe to my newsletter

Read articles from Arun Udayakumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arun Udayakumar
Arun Udayakumar