1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include <raylib.h> #include <math.h> int main() { // Initialization const int screenWidth = 800; const int screenHeight = 800; InitWindow(screenWidth, screenHeight, "3D Sinus Function Plot - raylib" ); // Define the camera Camera camera = { 0 }; camera.position = (Vector3){ 20.0f, 20.0f, 20.0f }; camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; camera.fovy = 45.0f; SetTargetFPS(60); while (!WindowShouldClose()) { BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); for ( float y = -8.0f; y < 8.0f; y += 0.2f) { for ( float x = -8.0f; x < 8.0f; x += 0.2f) { float z = sinf(sqrtf(x*x + y*y)) * 2.0f; // Amplitude increase for better visualization Vector3 pos = { x, z, y }; float colorIntensity = (z + 2.0f) / 4.0f; // Normalize z value to [0, 1] for color Color color = ColorFromHSV(200.0f * colorIntensity, 0.8f, 0.8f); DrawCubeV(pos, (Vector3){0.2f, 0.1f, 0.2f}, color); } } DrawGrid(20, 1.0f); EndMode3D(); DrawFPS(10, 10); EndDrawing(); } CloseWindow(); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#include <raylib.h> #include <math.h> int main() { // Initialization const int screenWidth = 800; const int screenHeight = 800; InitWindow(screenWidth, screenHeight, "3D Sinus Function Rotating - raylib" ); // Define the camera Camera camera = { 0 }; camera.position = (Vector3){ 30.0f, 20.0f, 3.0f }; camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; camera.fovy = 45.0f; SetTargetFPS(60); float angle = 0.0f; while (!WindowShouldClose()) { // Update camera position angle += 0.01f; // Increment angle camera.position.x = cosf(angle) * 30.0f; camera.position.z = sinf(angle) * 30.0f; BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); for ( float y = -8.0f; y < 8.0f; y += 0.2f) { for ( float x = -8.0f; x < 8.0f; x += 0.2f) { float z = sinf(sqrtf(x*x + y*y)) * 2.0f; // Amplitude increase for better visualization Vector3 pos = { x, z, y }; float colorIntensity = (z + 2.0f) / 4.0f; // Normalize z value to [0, 1] for color Color color = ColorFromHSV(200.0f * colorIntensity, 0.8f, 0.8f); DrawCubeV(pos, (Vector3){0.2f, 0.1f, 0.2f}, color); } } DrawGrid(20, 1.0f); EndMode3D(); DrawFPS(10, 10); EndDrawing(); } CloseWindow(); return 0; } |