Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <raylib.h>
- #include <math.h>
- #include <stdio.h>
- int main() {
- const int ScreenW = 800;
- const int ScreenH = 600;
- float radius = 200.0f;
- float visAngle = 0;//Visual representaiton of angle
- float angle = -260.0f;
- float smoothing = 0.1f;
- int gear = 1;
- SetConfigFlags(FLAG_WINDOW_HIGHDPI);
- InitWindow(ScreenW, ScreenH, "engine rev");
- SetTargetFPS(60);
- while (!WindowShouldClose()) {
- if (IsKeyDown(KEY_W)) {
- if (angle < -15.0f) angle += 1.0f; // Limit to 7500 RPM
- if (angle > 10.0f) angle = angle; // Clamp
- }
- if (IsKeyDown(KEY_S)) {
- if (angle > -270.0f) angle -= 1.0f;
- if (angle < -260.0f) angle = -260.0f;
- }
- if (IsKeyPressed(KEY_E)) {
- if (gear < 7) {
- gear ++;
- if (angle < -225.0f ) angle = angle;
- if (angle >= -225.0f )
- {
- angle -= 30.0f;
- }
- }
- if (gear > 7) gear = 7;
- }
- if (IsKeyPressed(KEY_Q)) {
- if (gear < 1) gear = 1;
- if (gear > 1)
- {
- gear --;
- if (angle <= -45.0f)
- {
- angle += 30.0f;
- }
- if (angle > -45.0f) angle = angle;
- }
- }
- // Convert angle to radians
- float radians = angle * DEG2RAD;
- // Calculate tip of line using trig
- float tipX = ScreenW / 2 + radius * cosf(radians);
- float tipY = ScreenH / 2 + radius * sinf(radians);
- Vector2 center = { ScreenW / 2.0f, ScreenH / 2.0f };
- BeginDrawing();
- DrawCircleV((Vector2){ScreenW/2, ScreenH/2}, radius, BLACK);
- // rev segments
- for (int i = -270; i <= 0; i += 15) {
- float rad = i * DEG2RAD;
- float innerX = center.x + (radius - 20) * cosf(rad);
- float innerY = center.y + (radius - 20) * sinf(rad);
- float outerX = center.x + radius * cosf(rad);
- float outerY = center.y + radius * sinf(rad);
- DrawLineEx((Vector2){innerX, innerY}, (Vector2){outerX, outerY}, 2.0f, WHITE);
- }
- // Optional: colored zones (redline)
- for (float i = -30; i <= 0; i += 5)
- {
- float rad = i * DEG2RAD;
- float x1 = center.x + (radius - 20) * cosf(rad);
- float y1 = center.y + (radius - 20) * sinf(rad);
- float x2 = center.x + radius * cosf(rad);
- float y2 = center.y + radius * sinf(rad);
- DrawLineEx((Vector2){x1, y1}, (Vector2){x2, y2}, 2.0f, RED);
- }
- // Draw needle (angle from center)
- visAngle += (angle-visAngle)*.1;//Move towards actual angle
- float needleRad = visAngle * DEG2RAD;
- float needleX = center.x + (radius - 30) * cosf(needleRad);
- float needleY = center.y + (radius - 30) * sinf(needleRad);
- DrawLineEx(center, (Vector2){needleX, needleY}, 4.0f, RED);
- // Center dot
- DrawCircleV(center, 6, RED);
- // Optional: Draw labels (1 to 8)
- int labelCount = 10;
- for (int i = 0; i < labelCount; i++)
- {
- float labelAngle = -270 + (270.0f / (labelCount - 1)) * i;
- float rad = labelAngle * DEG2RAD;
- float tx = center.x + (radius - 40) * cosf(rad);
- float ty = center.y + (radius - 40) * sinf(rad);
- char label[3];
- sprintf(label, "%d", i + 1);
- DrawText(label, tx - 10, ty - 10, 20, RAYWHITE);
- }
- //gearing
- char Gear[8];
- sprintf(Gear, "%d", gear);
- DrawText(Gear, ScreenW/2 + 87, ScreenH/2 + 87, 20, WHITE);
- ClearBackground(BLACK);
- EndDrawing();
- }
- CloseWindow();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment