REVIEWED: examples: Replace TABS and Remove trailing spaces

This commit is contained in:
Ray
2025-11-19 13:18:10 +01:00
parent bd21d74914
commit 0b9f463e64
36 changed files with 440 additions and 447 deletions

View File

@@ -7,7 +7,7 @@
* Example originally created with raylib 2.5, last time updated with raylib 2.5
*
* Example contributed by Ramon Santamaria (@raysan5), reviewed by Jopestpe (@jopestpe)
*
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
@@ -49,14 +49,14 @@ int main(void)
//-----------------------------------------------------
if (IsKeyPressed(KEY_G)) useGravity = !useGravity;
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
if (!pause)
{
ballPosition.x += ballSpeed.x;
ballPosition.y += ballSpeed.y;
if (useGravity) ballSpeed.y += gravity;
// Check walls collision for bouncing
if ((ballPosition.x >= (GetScreenWidth() - ballRadius)) || (ballPosition.x <= ballRadius)) ballSpeed.x *= -1.0f;
if ((ballPosition.y >= (GetScreenHeight() - ballRadius)) || (ballPosition.y <= ballRadius)) ballSpeed.y *= -0.95f;
@@ -72,7 +72,7 @@ int main(void)
DrawCircleV(ballPosition, (float)ballRadius, MAROON);
DrawText("PRESS SPACE to PAUSE BALL MOVEMENT", 10, GetScreenHeight() - 25, 20, LIGHTGRAY);
if (useGravity) DrawText("GRAVITY: ON (Press G to disable)", 10, GetScreenHeight() - 50, 20, DARKGREEN);
else DrawText("GRAVITY: OFF (Press G to enable)", 10, GetScreenHeight() - 50, 20, RED);
@@ -80,7 +80,7 @@ int main(void)
if (pause && ((framesCounter/30)%2)) DrawText("PAUSED", 350, 200, 30, GRAY);
DrawFPS(10, 10);
EndDrawing();
//-----------------------------------------------------
}

View File

@@ -35,14 +35,14 @@ int main(void)
SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - clock of clocks");
const Color bgColor = ColorLerp(DARKBLUE, BLACK, 0.75f);
const Color handsColor = ColorLerp(YELLOW, RAYWHITE, .25f);
const float clockFaceSize = 24;
const float clockFaceSpacing = 8.0f;
const float sectionSpacing = 16.0f;
const Vector2 TL = (Vector2){ 0.0f, 90.0f }; // Top-left corner
const Vector2 TR = (Vector2){ 90.0f, 180.0f }; // Top-right corner
const Vector2 BR = (Vector2){ 180.0f, 270.0f }; // Bottom-right corner
@@ -50,7 +50,7 @@ int main(void)
const Vector2 HH = (Vector2){ 0.0f, 180.0f }; // Horizontal line
const Vector2 VV = (Vector2){ 90.0f, 270.0f }; // Vertical line
const Vector2 ZZ = (Vector2){ 135.0f, 135.0f }; // Not relevant
const Vector2 digitAngles[10][24] = {
/* 0 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,VV,VV,VV,/* */ VV,VV,VV,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,HH,BR },
/* 1 */ { TL,HH,TR,ZZ, /* */ BL,TR,VV,ZZ,/* */ ZZ,VV,VV,ZZ,/* */ ZZ,VV,VV,ZZ,/* */ TL,BR,BL,TR,/* */ BL,HH,HH,BR },
@@ -65,21 +65,21 @@ int main(void)
};
// Time for the hands to move to the new position (in seconds); this must be <1s
const float handsMoveDuration = .5f;
// We store the previous seconds value so we can see if the time has changed
int prevSeconds = -1;
// This represents the real position where the hands are right now
Vector2 currentAngles[6][24] = { 0 };
// This is the position where the hands were moving from
Vector2 srcAngles[6][24] = { 0 };
// This is the position where the hands are moving to
Vector2 dstAngles[6][24] = { 0 };
// Current animation timer
float handsMoveTimer = 0.0f;
// 12 or 24 hour mode
int hourMode = 24;
@@ -91,32 +91,32 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
// Get the current time
time_t rawtime;
struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
if (timeinfo->tm_sec != prevSeconds) {
// The time has changed, so we need to move the hands to the new positions
prevSeconds = timeinfo->tm_sec;
// Format the current time so we can access the individual digits
const char *clockDigits = TextFormat("%02d%02d%02d", timeinfo->tm_hour % hourMode, timeinfo->tm_min, timeinfo->tm_sec);
// Fetch where we want all the hands to be
for (int digit = 0; digit < 6; digit++) {
for (int cell = 0; cell < 24; cell++) {
srcAngles[digit][cell] = currentAngles[digit][cell];
dstAngles[digit][cell] = digitAngles[ clockDigits[digit] - '0' ][cell];
// Quick exception for 12h mode
if (digit == 0 && hourMode == 12 && clockDigits[0] == '0') {
dstAngles[digit][cell] = ZZ;
}
if (srcAngles[digit][cell].x > dstAngles[digit][cell].x) {
srcAngles[digit][cell].x -= 360.0f;
}
@@ -125,43 +125,43 @@ int main(void)
}
}
}
// Reset the timer
handsMoveTimer = -GetFrameTime();
}
// Now let's animate all the hands if we need to
if (handsMoveTimer < handsMoveDuration) {
// Increase the timer but don't go above the maximum
handsMoveTimer = Clamp(handsMoveTimer + GetFrameTime(), 0, handsMoveDuration);
// Calculate the % completion of the animation
float t = handsMoveTimer / handsMoveDuration;
// A little cheeky smoothstep
t = t * t * (3.0f - 2.0f * t);
for (int digit = 0; digit < 6; digit++) {
for (int cell = 0; cell < 24; cell++) {
currentAngles[digit][cell].x = Lerp(srcAngles[digit][cell].x, dstAngles[digit][cell].x, t);
currentAngles[digit][cell].y = Lerp(srcAngles[digit][cell].y, dstAngles[digit][cell].y, t);
}
}
if (handsMoveTimer == handsMoveDuration) {
// The animation has now finished
}
}
// Handle input
// Toggle between 12 and 24 hour mode with space
if (IsKeyPressed(KEY_SPACE)) {
hourMode = 36 - hourMode;
}
//----------------------------------------------------------------------------------
// Draw
@@ -169,13 +169,13 @@ int main(void)
BeginDrawing();
ClearBackground(bgColor);
DrawText(TextFormat("%d-h mode, space to change", hourMode), 10, 30, 20, RAYWHITE);
float xOffset = 4.0f;
for (int digit = 0; digit < 6; digit++) {
for (int row = 0; row < 6; row++) {
for (int col = 0; col < 4; col++) {
Vector2 centre = (Vector2){
@@ -183,7 +183,7 @@ int main(void)
100 + row*(clockFaceSize+clockFaceSpacing) + clockFaceSize * .5f
};
DrawRing(centre, clockFaceSize * 0.5f - 2.0f, clockFaceSize * 0.5f, 0, 360, 24, DARKGRAY);
// Big hand
DrawRectanglePro(
(Rectangle){centre.x, centre.y, clockFaceSize*.5f+4.0f, 4.0f},
@@ -191,7 +191,7 @@ int main(void)
currentAngles[digit][row*4+col].x,
handsColor
);
// Little hand
DrawRectanglePro(
(Rectangle){centre.x, centre.y, clockFaceSize*.5f+2.0f, 4.0f},
@@ -201,20 +201,20 @@ int main(void)
);
}
}
xOffset += (clockFaceSize+clockFaceSpacing) * 4;
if (digit % 2 == 1) {
DrawRing((Vector2){xOffset + 4.0f, 160.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
DrawRing((Vector2){xOffset + 4.0f, 225.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
xOffset += sectionSpacing;
}
}
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------

View File

@@ -116,7 +116,7 @@ int main(void)
ClearBackground(RAYWHITE);
// Draw clock in selected mode
if (clockMode == CLOCK_ANALOG) DrawClockAnalog(clock, (Vector2){ 400, 240 });
if (clockMode == CLOCK_ANALOG) DrawClockAnalog(clock, (Vector2){ 400, 240 });
else if (clockMode == CLOCK_DIGITAL)
{
DrawClockDigital(clock, (Vector2){ 30, 60 });
@@ -128,7 +128,7 @@ int main(void)
DrawText(clockTime, GetScreenWidth()/2 - MeasureText(clockTime, 150)/2, 300, 150, BLACK);
}
DrawText(TextFormat("Press [SPACE] to switch clock mode: %s",
DrawText(TextFormat("Press [SPACE] to switch clock mode: %s",
(clockMode == CLOCK_DIGITAL)? "DIGITAL CLOCK" : "ANALOGUE CLOCK"), 10, 10, 20, DARKGRAY);
EndDrawing();
@@ -183,13 +183,13 @@ static void DrawClockAnalog(Clock clock, Vector2 position)
// Draw clock minutes/seconds lines
for (int i = 0; i < 60; i++)
{
DrawLineEx((Vector2){ position.x + (clock.second.length + ((i%5)? 10 : 6))*cosf((6.0f*i - 90.0f)*DEG2RAD),
position.y + (clock.second.length + ((i%5)? 10 : 6))*sinf((6.0f*i - 90.0f)*DEG2RAD) },
(Vector2){ position.x + (clock.second.length + 20)*cosf((6.0f*i - 90.0f)*DEG2RAD),
DrawLineEx((Vector2){ position.x + (clock.second.length + ((i%5)? 10 : 6))*cosf((6.0f*i - 90.0f)*DEG2RAD),
position.y + (clock.second.length + ((i%5)? 10 : 6))*sinf((6.0f*i - 90.0f)*DEG2RAD) },
(Vector2){ position.x + (clock.second.length + 20)*cosf((6.0f*i - 90.0f)*DEG2RAD),
position.y + (clock.second.length + 20)*sinf((6.0f*i - 90.0f)*DEG2RAD) }, ((i%5)? 1.0f : 3.0f), DARKGRAY);
// Draw seconds numbers
//DrawText(TextFormat("%02i", i), centerPosition.x + (clock.second.length + 50)*cosf((6.0f*i - 90.0f)*DEG2RAD) - 10/2,
//DrawText(TextFormat("%02i", i), centerPosition.x + (clock.second.length + 50)*cosf((6.0f*i - 90.0f)*DEG2RAD) - 10/2,
// centerPosition.y + (clock.second.length + 50)*sinf((6.0f*i - 90.0f)*DEG2RAD) - 10/2, 10, GRAY);
}
@@ -256,25 +256,25 @@ static void Draw7SDisplay(Vector2 position, char segments, Color colorOn, Color
float offsetYAdjust = segmentThick*0.3f; // HACK: Adjust gap space between segment limits
// Segment A
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + segmentThick },
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + segmentThick },
segmentLen, segmentThick, false, (segments & 0b00000001)? colorOn : colorOff);
// Segment B
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen + segmentThick/2.0f, position.y + 2*segmentThick + segmentLen/2.0f - offsetYAdjust },
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen + segmentThick/2.0f, position.y + 2*segmentThick + segmentLen/2.0f - offsetYAdjust },
segmentLen, segmentThick, true, (segments & 0b00000010)? colorOn : colorOff);
// Segment C
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen + segmentThick/2.0f, position.y + 4*segmentThick + segmentLen + segmentLen/2.0f - 3*offsetYAdjust },
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen + segmentThick/2.0f, position.y + 4*segmentThick + segmentLen + segmentLen/2.0f - 3*offsetYAdjust },
segmentLen, segmentThick, true, (segments & 0b00000100)? colorOn : colorOff);
// Segment D
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + 5*segmentThick + 2*segmentLen - 4*offsetYAdjust },
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + 5*segmentThick + 2*segmentLen - 4*offsetYAdjust },
segmentLen, segmentThick, false, (segments & 0b00001000)? colorOn : colorOff);
// Segment E
DrawDisplaySegment((Vector2){ position.x + segmentThick/2.0f, position.y + 4*segmentThick + segmentLen + segmentLen/2.0f - 3*offsetYAdjust },
DrawDisplaySegment((Vector2){ position.x + segmentThick/2.0f, position.y + 4*segmentThick + segmentLen + segmentLen/2.0f - 3*offsetYAdjust },
segmentLen, segmentThick, true, (segments & 0b00010000)? colorOn : colorOff);
// Segment F
DrawDisplaySegment((Vector2){ position.x + segmentThick/2.0f, position.y + 2*segmentThick + segmentLen/2.0f - offsetYAdjust },
DrawDisplaySegment((Vector2){ position.x + segmentThick/2.0f, position.y + 2*segmentThick + segmentLen/2.0f - offsetYAdjust },
segmentLen, segmentThick, true, (segments & 0b00100000)? colorOn : colorOff);
// Segment G
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + 3*segmentThick + segmentLen - 2*offsetYAdjust },
DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + 3*segmentThick + segmentLen - 2*offsetYAdjust },
segmentLen, segmentThick, false, (segments & 0b01000000)? colorOn : colorOff);
}

View File

@@ -51,13 +51,13 @@ int main(void)
Vector2 prevMousePos = { 0 };
Vector2 scaleVector = { 1.0f, -1.0f };
Vector2 offset = { (float)screenWidth/2.0f, (float)screenHeight/2.0f };
Camera2D camera = { 0 };
camera.target = (Vector2){ 0 };
camera.offset = offset;
camera.rotation = 0.0f;
camera.zoom = 1.0f;
int lineCounter = 0;
SetTargetFPS(20);
@@ -70,10 +70,10 @@ int main(void)
//----------------------------------------------------------------------------------
prevMousePos = mousePos;
mousePos = GetMousePosition();
Vector2 lineStart = Vector2Subtract(mousePos, offset);
Vector2 lineEnd = Vector2Subtract(prevMousePos, offset);
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
{
for (int s = 0; (s < symmetry) && (lineCounter < (MAX_DRAW_LINES - 1)); s++)
@@ -88,7 +88,7 @@ int main(void)
// Store reflective line
lines[lineCounter + 1].start = Vector2Multiply(lineStart, scaleVector);
lines[lineCounter + 1].end = Vector2Multiply(lineEnd, scaleVector);
lineCounter += 2;
}
}
@@ -97,9 +97,9 @@ int main(void)
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode2D(camera);
for (int s = 0; s < symmetry; s++)
{
@@ -110,10 +110,10 @@ int main(void)
}
}
EndMode2D();
DrawText(TextFormat("LINES: %i/%i", lineCounter, MAX_DRAW_LINES), 10, screenHeight - 30, 20, MAROON);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}

View File

@@ -16,6 +16,7 @@
********************************************************************************************/
#include "raylib.h"
#include "raymath.h"
//------------------------------------------------------------------------------------
@@ -23,122 +24,114 @@
//------------------------------------------------------------------------------------
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - lines drawing");
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - lines drawing");
// Hint text that shows before you click the screen
bool startText = true;
// Hint text that shows before you click the screen
bool startText = true;
// The mouse's position on the previous frame
Vector2 mousePositionPrevious = GetMousePosition();
// The mouse's position on the previous frame
Vector2 mousePositionPrevious = GetMousePosition();
// The canvas to draw lines on
RenderTexture canvas = LoadRenderTexture(screenWidth, screenHeight);
// The canvas to draw lines on
RenderTexture canvas = LoadRenderTexture(screenWidth, screenHeight);
// The background color of the canvas
const Color backgroundColor = RAYWHITE;
// The line's thickness
float lineThickness = 8.0f;
// The lines hue (in HSV, from 0-360)
float lineHue = 0.0f;
// The line's thickness
float lineThickness = 8.0f;
// The lines hue (in HSV, from 0-360)
float lineHue = 0.0f;
// Clear the canvas to the background color
BeginTextureMode(canvas);
ClearBackground(RAYWHITE);
EndTextureMode();
// Clear the canvas to the background color
BeginTextureMode(canvas);
ClearBackground(backgroundColor);
EndTextureMode();
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Disable the hint text once the user clicks
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && startText) startText = false;
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Disable the hint text once the user clicks
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && startText) startText = false;
// Clear the canvas when the user middle-clicks
if (IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE))
{
BeginTextureMode(canvas);
ClearBackground(backgroundColor);
EndTextureMode();
}
// Clear the canvas when the user middle-clicks
if (IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE))
{
BeginTextureMode(canvas);
ClearBackground(RAYWHITE);
EndTextureMode();
}
// Store whether the left and right buttons are down
bool leftButtonDown = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
bool rightButtonDown = IsMouseButtonDown(MOUSE_BUTTON_RIGHT);
// Store whether the left and right buttons are down
bool leftButtonDown = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
bool rightButtonDown = IsMouseButtonDown(MOUSE_BUTTON_RIGHT);
if (leftButtonDown || rightButtonDown)
{
// The color for the line
Color drawColor = WHITE;
if (leftButtonDown || rightButtonDown)
{
// The color for the line
Color drawColor = WHITE;
if (leftButtonDown)
{
// Increase the hue value by the distance our cursor has moved since the last frame (divided by 3)
lineHue += Vector2Distance(mousePositionPrevious, GetMousePosition())/3.0f;
if (leftButtonDown)
{
// Increase the hue value by the distance our cursor has moved since the last frame (divided by 3)
lineHue += Vector2Distance(mousePositionPrevious, GetMousePosition())/3.0f;
// While the hue is >=360, subtract it to bring it down into the range 0-360
// This is more visually accurate than resetting to zero
while (lineHue >= 360.0f) lineHue -= 360.0f;
// While the hue is >=360, subtract it to bring it down into the range 0-360
// This is more visually accurate than resetting to zero
while (lineHue >= 360.0f) lineHue -= 360.0f;
// Create the final color
drawColor = ColorFromHSV(lineHue, 1.0f, 1.0f);
}
else if (rightButtonDown)
{
// Use the background color as an "eraser"
drawColor = backgroundColor;
}
// Create the final color
drawColor = ColorFromHSV(lineHue, 1.0f, 1.0f);
}
else if (rightButtonDown) drawColor = RAYWHITE; // Use the background color as an "eraser"
// Draw the line onto the canvas
BeginTextureMode(canvas);
// Circles act as "caps", smoothing corners
DrawCircleV(mousePositionPrevious, lineThickness/2.0f, drawColor);
DrawCircleV(GetMousePosition(), lineThickness/2.0f, drawColor);
DrawLineEx(mousePositionPrevious, GetMousePosition(), lineThickness, drawColor);
EndTextureMode();
}
// Draw the line onto the canvas
BeginTextureMode(canvas);
// Circles act as "caps", smoothing corners
DrawCircleV(mousePositionPrevious, lineThickness/2.0f, drawColor);
DrawCircleV(GetMousePosition(), lineThickness/2.0f, drawColor);
DrawLineEx(mousePositionPrevious, GetMousePosition(), lineThickness, drawColor);
EndTextureMode();
}
// Update line thickness based on mousewheel
lineThickness += GetMouseWheelMove();
lineThickness = Clamp(lineThickness, 1.0, 500.0f);
// Update line thickness based on mousewheel
lineThickness += GetMouseWheelMove();
lineThickness = Clamp(lineThickness, 1.0, 500.0f);
// Update mouse's previous position
mousePositionPrevious = GetMousePosition();
//----------------------------------------------------------------------------------
// Update mouse's previous position
mousePositionPrevious = GetMousePosition();
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
// Draw the render texture to the screen, flipped vertically to make it appear top-side up
DrawTextureRec(canvas.texture, (Rectangle){ 0.0f, 0.0f, (float)canvas.texture.width,(float)-canvas.texture.height }, Vector2Zero(), WHITE);
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
// Draw the preview circle
if (!leftButtonDown) DrawCircleLinesV(GetMousePosition(), lineThickness/2.0f, (Color){ 127, 127, 127, 127 });
// Draw the render texture to the screen, flipped vertically to make it appear top-side up
DrawTextureRec(canvas.texture, (Rectangle){ 0.0f, 0.0f, (float)canvas.texture.width,(float)-canvas.texture.height }, Vector2Zero(), WHITE);
// Draw the hint text
if (startText) DrawText("try clicking and dragging!", 275, 215, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// Draw the preview circle
if (!leftButtonDown) DrawCircleLinesV(GetMousePosition(), lineThickness/2.0f, (Color){ 127, 127, 127, 127 });
// De-Initialization
//--------------------------------------------------------------------------------------
// Unload the canvas render texture
UnloadRenderTexture(canvas);
// Draw the hint text
if (startText) DrawText("try clicking and dragging!", 275, 215, 20, LIGHTGRAY);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadRenderTexture(canvas); // Unload the canvas render texture
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

View File

@@ -35,7 +35,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT);
SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - math sine cosine");
Vector2 sinePoints[WAVE_POINTS];
@@ -97,7 +97,7 @@ int main(void)
// Base circle and axes
DrawCircleLinesV(center, radius, GRAY);
DrawLineEx((Vector2){ center.x, limitMin.y }, (Vector2){ center.x, limitMax.y }, 1.0f, GRAY);
DrawLineEx((Vector2){ center.x, limitMin.y }, (Vector2){ center.x, limitMax.y }, 1.0f, GRAY);
DrawLineEx((Vector2){ limitMin.x, center.y }, (Vector2){ limitMax.x, center.y }, 1.f, GRAY);
// Wave graph axes
@@ -110,17 +110,17 @@ int main(void)
DrawText("0", start.x - 8, start.y + start.height/2 - 6, 6, GRAY);
DrawText("-1", start.x - 12, start.y + start.height - 8, 6, GRAY);
DrawText("0", start.x - 2, start.y + start.height + 4, 6, GRAY);
DrawText("360", start.x + start.width - 8, start.y + start.height + 4, 6, GRAY);
DrawText("360", start.x + start.width - 8, start.y + start.height + 4, 6, GRAY);
// Sine (red - vertical)
DrawLineEx((Vector2){ center.x, center.y }, (Vector2){ center.x, point.y }, 2.0f, RED);
DrawLineEx((Vector2){ center.x, center.y }, (Vector2){ center.x, point.y }, 2.0f, RED);
DrawLineDashed((Vector2){ point.x, center.y }, (Vector2){ point.x, point.y }, 10.0f, 4.0f, RED);
DrawText(TextFormat("Sine %.2f", sinRad), 640, 190, 6, RED);
DrawCircleV((Vector2){ start.x + (angle/360.0f)*start.width, start.y + ((-sinRad + 1)*start.height/2.0f) }, 4.0f, RED);
DrawSplineLinear(sinePoints, WAVE_POINTS, 1.0f, RED);
// Cosine (blue - horizontal)
DrawLineEx((Vector2){ center.x, center.y }, (Vector2){ point.x, center.y }, 2.0f, BLUE);
DrawLineEx((Vector2){ center.x, center.y }, (Vector2){ point.x, center.y }, 2.0f, BLUE);
DrawLineDashed((Vector2){ center.x , point.y }, (Vector2){ point.x, point.y }, 10.0f, 4.0f, BLUE);
DrawText(TextFormat("Cosine %.2f", cosRad), 640, 210, 6, BLUE);
DrawCircleV((Vector2){ start.x + (angle/360.0f)*start.width, start.y + ((-cosRad + 1)*start.height/2.0f) }, 4.0f, BLUE);
@@ -135,7 +135,7 @@ int main(void)
DrawText(TextFormat("Cotangent %.2f", cotangent), 640, 250, 6, ORANGE);
// Complementary angle (beige)
DrawCircleSectorLines(center, radius*0.6f , -angle, -90.f , 36.0f, BEIGE);
DrawCircleSectorLines(center, radius*0.6f , -angle, -90.f , 36.0f, BEIGE);
DrawText(TextFormat("Complementary %0.f°",complementary), 640, 150, 6, BEIGE);
// Supplementary angle (darkblue)
@@ -147,19 +147,19 @@ int main(void)
DrawText(TextFormat("Explementary %0.f°",explementary), 640, 170, 6, PINK);
// Current angle - arc (lime), radius (black), endpoint (black)
DrawCircleSectorLines(center, radius*0.7f , -angle, 0.f, 36.0f, LIME);
DrawCircleSectorLines(center, radius*0.7f , -angle, 0.f, 36.0f, LIME);
DrawLineEx((Vector2){ center.x , center.y }, point, 2.0f, BLACK);
DrawCircleV(point, 4.0f, BLACK);
// Draw GUI controls
//------------------------------------------------------------------------------
GuiSetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(GRAY));
GuiToggle((Rectangle){ 640, 70, 120, 20}, TextFormat("Pause"), &pause);
GuiToggle((Rectangle){ 640, 70, 120, 20}, TextFormat("Pause"), &pause);
GuiSetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(LIME));
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.0f°", angle), &angle, 0.0f, 360.f);
// Angle values panel
GuiGroupBox((Rectangle){ 620, 110, 140, 170}, "Angle Values");
GuiGroupBox((Rectangle){ 620, 110, 140, 170}, "Angle Values");
//------------------------------------------------------------------------------
DrawFPS(10, 10);

View File

@@ -35,7 +35,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - mouse trail");
// Array to store the history of mouse positions (our fixed-size queue)
Vector2 trailPositions[MAX_TRAIL_LENGTH] = { 0 };
Vector2 trailPositions[MAX_TRAIL_LENGTH] = { 0 };
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -62,8 +62,8 @@ int main(void)
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(BLACK);
ClearBackground(BLACK);
// Draw the trail by looping through the history array
for (int i = 0; i < MAX_TRAIL_LENGTH; i++)
{
@@ -71,22 +71,22 @@ int main(void)
if ((trailPositions[i].x != 0.0f) || (trailPositions[i].y != 0.0f))
{
// Calculate relative trail strength (ratio is near 1.0 for new, near 0.0 for old)
float ratio = (float)(MAX_TRAIL_LENGTH - i) / MAX_TRAIL_LENGTH;
float ratio = (float)(MAX_TRAIL_LENGTH - i) / MAX_TRAIL_LENGTH;
// Fade effect: oldest positions are more transparent
// Fade (color, alpha) - alpha is 0.5 to 1.0 based on ratio
Color trailColor = Fade(SKYBLUE, ratio*0.5f + 0.5f);
Color trailColor = Fade(SKYBLUE, ratio*0.5f + 0.5f);
// Size effect: oldest positions are smaller
float trailRadius = 15.0f*ratio;
float trailRadius = 15.0f*ratio;
DrawCircleV(trailPositions[i], trailRadius, trailColor);
}
}
// Draw a distinct white circle for the current mouse position (Index 0)
DrawCircleV(mousePosition, 15.0f, WHITE);
DrawText("Move the mouse to see the trail effect!", 10, screenHeight - 30, 20, LIGHTGRAY);
EndDrawing();

View File

@@ -67,7 +67,7 @@ int main(void)
const Rectangle panelRect = {
panelPos.x, panelPos.y,
(float)panelWidth,
(float)screenHeight - 2.0f*panelMargin
(float)screenHeight - 2.0f*panelMargin
};
// Pie chart geometry
@@ -108,13 +108,13 @@ int main(void)
for (int i = 0; i < sliceCount; i++)
{
float sweep = (totalValue > 0)? (values[i]/totalValue)*360.0f : 0.0f;
if ((angle >= currentAngle) && (angle < (currentAngle + sweep)))
{
hoveredSlice = i;
break;
}
currentAngle += sweep;
}
}
@@ -182,11 +182,11 @@ int main(void)
GuiLine((Rectangle){ panelPos.x + 10, (float)panelPos.y + 12 + 170, panelRect.width - 20, 1 }, NULL);
// Scrollable area for slice editors
scrollPanelBounds = (Rectangle){
panelPos.x + panelMargin,
(float)panelPos.y + 12 + 190,
panelRect.width - panelMargin*2,
panelRect.y + panelRect.height - panelPos.y + 12 + 190 - panelMargin
scrollPanelBounds = (Rectangle){
panelPos.x + panelMargin,
(float)panelPos.y + 12 + 190,
panelRect.width - panelMargin*2,
panelRect.y + panelRect.height - panelPos.y + 12 + 190 - panelMargin
};
int contentHeight = sliceCount*35;

View File

@@ -45,7 +45,7 @@ int main(void)
Vector2 start = { (screenWidth/2.0f) - 125.0f, (float)screenHeight };
float angle = 40.0f;
float thick = 1.0f;
float thick = 1.0f;
float treeDepth = 10.0f;
float branchDecay = 0.66f;
float length = 120.0f;
@@ -67,21 +67,21 @@ int main(void)
Vector2 initialEnd = { start.x + length*sinf(0.0f), start.y - length*cosf(0.0f) };
branches[count++] = (Branch){start, initialEnd, 0.0f, length};
for (int i = 0; i < count; i++)
for (int i = 0; i < count; i++)
{
Branch branch = branches[i];
if (branch.length < 2) continue;
float nextLength = branch.length*branchDecay;
if (count < maxBranches && nextLength >= 2)
if (count < maxBranches && nextLength >= 2)
{
Vector2 branchStart = branch.end;
float angle1 = branch.angle + theta;
Vector2 branchEnd1 = { branchStart.x + nextLength*sinf(angle1), branchStart.y - nextLength*cosf(angle1) };
branches[count++] = (Branch){branchStart, branchEnd1, angle1, nextLength};
float angle2 = branch.angle - theta;
Vector2 branchEnd2 = { branchStart.x + nextLength*sinf(angle2), branchStart.y - nextLength*cosf(angle2) };
branches[count++] = (Branch){branchStart, branchEnd2, angle2, nextLength};
@@ -94,10 +94,10 @@ int main(void)
ClearBackground(RAYWHITE);
for (int i = 0; i < count; i++)
for (int i = 0; i < count; i++)
{
Branch branch = branches[i];
if (branch.length >= 2)
if (branch.length >= 2)
{
if (bezier) DrawLineBezier(branch.start, branch.end, thick, RED);
else DrawLineEx(branch.start, branch.end, thick, RED);

View File

@@ -50,7 +50,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) linesMode = !linesMode;
// Check selected vertex
for (unsigned int i = 0; i < 3; i++)
{
@@ -72,7 +72,7 @@ int main(void)
position->x += mouseDelta.x;
position->y += mouseDelta.y;
}
// Reset index on release
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) triangleIndex = -1;
@@ -139,15 +139,15 @@ int main(void)
// Render the vertex handles, reacting to mouse movement/input
for (unsigned int i = 0; i < 3; i++)
{
// Draw handle fill focused by mouse
// Draw handle fill focused by mouse
if (CheckCollisionPointCircle(GetMousePosition(), trianglePositions[i], handleRadius))
DrawCircleV(trianglePositions[i], handleRadius, ColorAlpha(DARKGRAY, 0.5f));
// Draw handle fill selected
if (i == triangleIndex) DrawCircleV(trianglePositions[i], handleRadius, DARKGRAY);
// Draw handle outline
DrawCircleLinesV(trianglePositions[i], handleRadius, BLACK);
DrawCircleLinesV(trianglePositions[i], handleRadius, BLACK);
}
// Draw controls

View File

@@ -36,7 +36,7 @@ static const char particleTypeNames[3][10] = { "WATER", "SMOKE", "FIRE" };
typedef struct Particle {
ParticleType type; // Particle type (WATER, SMOKE, FIRE)
Vector2 position; // Particle position on screen
Vector2 velocity; // Particle current speed and direction
Vector2 velocity; // Particle current speed and direction
float radius; // Particle radius
Color color; // Particle color
@@ -45,9 +45,9 @@ typedef struct Particle {
} Particle;
typedef struct CircularBuffer {
int head; // Index for the next write
int tail; // Index for the next read
Particle *buffer; // Particle buffer array
int head; // Index for the next write
int tail; // Index for the next read
Particle *buffer; // Particle buffer array
} CircularBuffer;
//----------------------------------------------------------------------------------
@@ -73,12 +73,12 @@ int main(void)
// Definition of particles
Particle *particles = (Particle*)RL_CALLOC(MAX_PARTICLES, sizeof(Particle)); // Particle array
CircularBuffer circularBuffer = { 0, 0, particles };
CircularBuffer circularBuffer = { 0, 0, particles };
// Particle emitter parameters
// Particle emitter parameters
int emissionRate = -2; // Negative: on average every -X frames. Positive: particles per frame
ParticleType currentType = WATER;
Vector2 emitterPosition = { screenWidth/2.0f, screenHeight/2.0f };
ParticleType currentType = WATER;
Vector2 emitterPosition = { screenWidth/2.0f, screenHeight/2.0f };
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -88,7 +88,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
// Emit new particles: when emissionRate is 1, emit every frame
// Emit new particles: when emissionRate is 1, emit every frame
if (emissionRate < 0)
{
if (rand()%(-emissionRate) == 0) EmitParticle(&circularBuffer, emitterPosition, currentType);
@@ -96,9 +96,9 @@ int main(void)
else
{
for (int i = 0; i <= emissionRate; ++i) EmitParticle(&circularBuffer, emitterPosition, currentType);
}
}
// Update the parameters of each particle
// Update the parameters of each particle
UpdateParticles(&circularBuffer, screenWidth, screenHeight);
// Remove dead particles from the circular buffer
@@ -112,7 +112,7 @@ int main(void)
if (IsKeyPressed(KEY_RIGHT)) (currentType == FIRE)? (currentType = WATER) : currentType++;
if (IsKeyPressed(KEY_LEFT)) (currentType == WATER)? (currentType = FIRE) : currentType--;
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) emitterPosition = GetMousePosition();
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) emitterPosition = GetMousePosition();
//----------------------------------------------------------------------------------
// Draw
@@ -121,7 +121,7 @@ int main(void)
ClearBackground(RAYWHITE);
// Call the function with a loop to draw all particles
// Call the function with a loop to draw all particles
DrawParticles(&circularBuffer);
// Draw UI and Instructions
@@ -133,7 +133,7 @@ int main(void)
DrawText("LEFT/RIGHT: Change Particle Type (Water, Smoke, Fire)", 15, 55, 10, BLACK);
if (emissionRate < 0) DrawText(TextFormat("Particles every %d frames | Type: %s", -emissionRate, particleTypeNames[currentType]), 15, 95, 10, DARKGRAY);
else DrawText(TextFormat("%d Particles per frame | Type: %s", emissionRate + 1, particleTypeNames[currentType]), 15, 95, 10, DARKGRAY);
else DrawText(TextFormat("%d Particles per frame | Type: %s", emissionRate + 1, particleTypeNames[currentType]), 15, 95, 10, DARKGRAY);
DrawFPS(screenWidth - 80, 10);
@@ -200,12 +200,12 @@ static Particle *AddToCircularBuffer(CircularBuffer *circularBuffer)
// Check if buffer full
if (((circularBuffer->head + 1)%MAX_PARTICLES) != circularBuffer->tail)
{
// Add new particle to the head position and advance head
// Add new particle to the head position and advance head
particle = &circularBuffer->buffer[circularBuffer->head];
circularBuffer->head = (circularBuffer->head + 1)%MAX_PARTICLES;
}
return particle;
return particle;
}
static void UpdateParticles(CircularBuffer *circularBuffer, int screenWidth, int screenHeight)
@@ -213,7 +213,7 @@ static void UpdateParticles(CircularBuffer *circularBuffer, int screenWidth, int
for (int i = circularBuffer->tail; i != circularBuffer->head; i = (i + 1)%MAX_PARTICLES)
{
// Update particle life and positions
circularBuffer->buffer[i].lifeTime += 1.0f/60.0f; // 60 FPS -> 1/60 seconds per frame
circularBuffer->buffer[i].lifeTime += 1.0f/60.0f; // 60 FPS -> 1/60 seconds per frame
switch (circularBuffer->buffer[i].type)
{
@@ -226,32 +226,32 @@ static void UpdateParticles(CircularBuffer *circularBuffer, int screenWidth, int
case SMOKE:
{
circularBuffer->buffer[i].position.x += circularBuffer->buffer[i].velocity.x;
circularBuffer->buffer[i].velocity.y -= 0.05f; // Upwards
circularBuffer->buffer[i].velocity.y -= 0.05f; // Upwards
circularBuffer->buffer[i].position.y += circularBuffer->buffer[i].velocity.y;
circularBuffer->buffer[i].radius += 0.5f; // Increment radius: smoke expands
circularBuffer->buffer[i].color.a -= 4; // Decrement alpha: smoke fades
circularBuffer->buffer[i].color.a -= 4; // Decrement alpha: smoke fades
// If alpha transparent, particle dies
if (circularBuffer->buffer[i].color.a < 4) circularBuffer->buffer[i].alive = false;
} break;
case FIRE:
{
// Add a little horizontal oscillation to fire particles
// Add a little horizontal oscillation to fire particles
circularBuffer->buffer[i].position.x += circularBuffer->buffer[i].velocity.x + cosf(circularBuffer->buffer[i].lifeTime*215.0f);
circularBuffer->buffer[i].velocity.y -= 0.05f; // Upwards
circularBuffer->buffer[i].position.y += circularBuffer->buffer[i].velocity.y;
circularBuffer->buffer[i].radius -= 0.15f; // Decrement radius: fire shrinks
circularBuffer->buffer[i].color.g -= 3; // Decrement green: fire turns reddish starting from yellow
circularBuffer->buffer[i].radius -= 0.15f; // Decrement radius: fire shrinks
circularBuffer->buffer[i].color.g -= 3; // Decrement green: fire turns reddish starting from yellow
// If radius too small, particle dies
if (circularBuffer->buffer[i].radius <= 0.02f) circularBuffer->buffer[i].alive = false;
} break;
default: break;
}
// Disable particle when out of screen
// Disable particle when out of screen
Vector2 center = circularBuffer->buffer[i].position;
float radius = circularBuffer->buffer[i].radius;
float radius = circularBuffer->buffer[i].radius;
if ((center.x < -radius) || (center.x > (screenWidth + radius)) ||
(center.y < -radius) || (center.y > (screenHeight + radius)))
@@ -267,7 +267,7 @@ static void UpdateCircularBuffer(CircularBuffer *circularBuffer)
while ((circularBuffer->tail != circularBuffer->head) && !circularBuffer->buffer[circularBuffer->tail].alive)
{
circularBuffer->tail = (circularBuffer->tail + 1)%MAX_PARTICLES;
}
}
}
static void DrawParticles(CircularBuffer *circularBuffer)

View File

@@ -39,7 +39,7 @@ int main(void)
float insideRadius = 100.0f;
float outsideRadius = 150.0f;
bool outline = true;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -79,14 +79,14 @@ int main(void)
float angle1 = i*angleStep;
DrawTriangle(c, b, a, ColorFromHSV(angle1*RAD2DEG, 1.0f, 1.0f));
DrawTriangle(d, b, c, ColorFromHSV((angle1 + angleStep/2)*RAD2DEG, 1.0f, 1.0f));
if (outline)
{
DrawTriangleLines(a, b, c, BLACK);
DrawTriangleLines(c, b, d, BLACK);
}
}
DrawLine(580, 0, 580, GetScreenHeight(), (Color){ 218, 218, 218, 255 });
DrawRectangle(580, 0, GetScreenWidth(), GetScreenHeight(), (Color){ 232, 232, 232, 255 });

View File

@@ -25,7 +25,7 @@ int main(void)
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - vector angle");