Guest User

Untitled

a guest
May 30th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | Source Code | 0 0
  1. #include <raylib.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. int main() {
  6.     const int ScreenW = 800;
  7.     const int ScreenH = 600;
  8.     float radius = 200.0f;
  9.     float visAngle = 0;//Visual representaiton of angle
  10.     float angle = -260.0f;
  11.     float smoothing = 0.1f;
  12.     int gear = 1;
  13.  
  14.     SetConfigFlags(FLAG_WINDOW_HIGHDPI);
  15.     InitWindow(ScreenW, ScreenH, "engine rev");
  16.     SetTargetFPS(60);
  17.  
  18.     while (!WindowShouldClose()) {
  19.         if (IsKeyDown(KEY_W)) {
  20.             if (angle < -15.0f) angle += 1.0f; // Limit to 7500 RPM
  21.             if (angle > 10.0f) angle = angle; // Clamp
  22.         }
  23.         if (IsKeyDown(KEY_S)) {
  24.             if (angle > -270.0f) angle -= 1.0f;
  25.             if (angle < -260.0f) angle = -260.0f;
  26.         }
  27.         if (IsKeyPressed(KEY_E)) {
  28.             if (gear < 7) {
  29.                 gear ++;
  30.                 if (angle < -225.0f ) angle = angle;
  31.                 if (angle >= -225.0f )
  32.                 {
  33.                     angle -= 30.0f;
  34.                 }
  35.                
  36.             }
  37.             if (gear > 7) gear = 7;
  38.         }
  39.         if (IsKeyPressed(KEY_Q)) {
  40.             if (gear < 1) gear = 1;
  41.             if (gear > 1)
  42.             {
  43.                 gear --;
  44.                 if (angle <= -45.0f)
  45.                 {
  46.                     angle += 30.0f;
  47.                 }
  48.                  
  49.                 if (angle > -45.0f) angle = angle;
  50.             }
  51.         }
  52.         // Convert angle to radians
  53.         float radians = angle * DEG2RAD;
  54.  
  55.         // Calculate tip of line using trig
  56.         float tipX = ScreenW / 2 + radius * cosf(radians);
  57.         float tipY = ScreenH / 2 + radius * sinf(radians);
  58.         Vector2 center = { ScreenW / 2.0f, ScreenH / 2.0f };
  59.         BeginDrawing();
  60.         DrawCircleV((Vector2){ScreenW/2, ScreenH/2}, radius, BLACK);
  61.         // rev segments
  62.         for (int i = -270; i <= 0; i += 15) {
  63.             float rad = i * DEG2RAD;
  64.             float innerX = center.x + (radius - 20) * cosf(rad);
  65.             float innerY = center.y + (radius - 20) * sinf(rad);
  66.             float outerX = center.x + radius * cosf(rad);
  67.             float outerY = center.y + radius * sinf(rad);
  68.  
  69.             DrawLineEx((Vector2){innerX, innerY}, (Vector2){outerX, outerY}, 2.0f, WHITE);
  70.         }
  71.         // Optional: colored zones (redline)
  72.         for (float i = -30; i <= 0; i += 5)
  73.         {
  74.             float rad = i * DEG2RAD;
  75.             float x1 = center.x + (radius - 20) * cosf(rad);
  76.             float y1 = center.y + (radius - 20) * sinf(rad);
  77.             float x2 = center.x + radius * cosf(rad);
  78.             float y2 = center.y + radius * sinf(rad);
  79.  
  80.             DrawLineEx((Vector2){x1, y1}, (Vector2){x2, y2}, 2.0f, RED);
  81.         }
  82.  
  83.         // Draw needle (angle from center)
  84.         visAngle += (angle-visAngle)*GetFrameTime()*10;//Adjust visible angle
  85.         float needleRad = visAngle * DEG2RAD;
  86.         float needleX = center.x + (radius - 30) * cosf(needleRad);
  87.         float needleY = center.y + (radius - 30) * sinf(needleRad);
  88.         DrawLineEx(center, (Vector2){needleX, needleY}, 4.0f, RED);
  89.        
  90.         // Center dot
  91.         DrawCircleV(center, 6, RED);
  92.  
  93.         // Optional: Draw labels (1 to 8)
  94.         int labelCount = 10;
  95.         for (int i = 0; i < labelCount; i++)
  96.         {
  97.             float labelAngle = -270 + (270.0f / (labelCount - 1)) * i;
  98.             float rad = labelAngle * DEG2RAD;
  99.             float tx = center.x + (radius - 40) * cosf(rad);
  100.             float ty = center.y + (radius - 40) * sinf(rad);
  101.  
  102.             char label[3];
  103.             sprintf(label, "%d", i + 1);
  104.             DrawText(label, tx - 10, ty - 10, 20, RAYWHITE);
  105.         }
  106.         //gearing
  107.         char Gear[8];
  108.         sprintf(Gear, "%d", gear);
  109.         DrawText(Gear, ScreenW/2 + 87, ScreenH/2 + 87, 20, WHITE);
  110.         ClearBackground(BLACK);
  111.         EndDrawing();
  112.     }
  113.  
  114.     CloseWindow();
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment