chore: run dotnet format scoped default (was previously scoped to just 'style')
This commit is contained in:
parent
8799edf99b
commit
c06874f14a
23 changed files with 749 additions and 485 deletions
|
|
@ -62,7 +62,7 @@ public partial class BallPhysics : IExample
|
|||
// Init first ball in the array
|
||||
balls[0] = new Ball
|
||||
{
|
||||
position = new Vector2(GetScreenWidth()/2.0f, GetScreenHeight()/2.0f),
|
||||
position = new Vector2(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f),
|
||||
speed = new Vector2(200, 200),
|
||||
prevPosition = new Vector2(0, 0),
|
||||
radius = 40,
|
||||
|
|
@ -98,7 +98,7 @@ public partial class BallPhysics : IExample
|
|||
|
||||
// If the distance between the ball position and the mouse press position
|
||||
// is less than or equal to the ball radius, the event occurred inside the ball
|
||||
if (MathF.Sqrt(pressOffset.X*pressOffset.X + pressOffset.Y*pressOffset.Y) <= balls[i].radius)
|
||||
if (MathF.Sqrt(pressOffset.X * pressOffset.X + pressOffset.Y * pressOffset.Y) <= balls[i].radius)
|
||||
{
|
||||
balls[i].grabbed = true;
|
||||
grabbedBallIndex = i;
|
||||
|
|
@ -163,7 +163,7 @@ public partial class BallPhysics : IExample
|
|||
}
|
||||
|
||||
// Changes gravity
|
||||
gravity += GetMouseWheelMove()*5;
|
||||
gravity += GetMouseWheelMove() * 5;
|
||||
|
||||
// Updates each ball state
|
||||
for (int i = 0; i < ballCount; i++)
|
||||
|
|
@ -179,31 +179,31 @@ public partial class BallPhysics : IExample
|
|||
if ((balls[i].position.X + balls[i].radius) >= screenWidth)
|
||||
{
|
||||
balls[i].position.X = screenWidth - balls[i].radius; // Ball repositioning
|
||||
balls[i].speed.X = -balls[i].speed.X*balls[i].elasticity; // Elasticity makes the ball lose 10% of its velocity on hit
|
||||
balls[i].speed.X = -balls[i].speed.X * balls[i].elasticity; // Elasticity makes the ball lose 10% of its velocity on hit
|
||||
}
|
||||
// Does the ball hit the screen left boundary?
|
||||
else if ((balls[i].position.X - balls[i].radius) <= 0)
|
||||
{
|
||||
balls[i].position.X = balls[i].radius;
|
||||
balls[i].speed.X = -balls[i].speed.X*balls[i].elasticity;
|
||||
balls[i].speed.X = -balls[i].speed.X * balls[i].elasticity;
|
||||
}
|
||||
|
||||
// The same for y axis
|
||||
if ((balls[i].position.Y + balls[i].radius) >= screenHeight)
|
||||
{
|
||||
balls[i].position.Y = screenHeight - balls[i].radius;
|
||||
balls[i].speed.Y = -balls[i].speed.Y*balls[i].elasticity;
|
||||
balls[i].speed.Y = -balls[i].speed.Y * balls[i].elasticity;
|
||||
}
|
||||
else if ((balls[i].position.Y - balls[i].radius) <= 0)
|
||||
{
|
||||
balls[i].position.Y = balls[i].radius;
|
||||
balls[i].speed.Y = -balls[i].speed.Y*balls[i].elasticity;
|
||||
balls[i].speed.Y = -balls[i].speed.Y * balls[i].elasticity;
|
||||
}
|
||||
|
||||
// Friction makes the ball lose 1% of its velocity each frame
|
||||
balls[i].speed.X = balls[i].speed.X*balls[i].friction;
|
||||
balls[i].speed.X = balls[i].speed.X * balls[i].friction;
|
||||
// Gravity affects only the y axis
|
||||
balls[i].speed.Y = balls[i].speed.Y*balls[i].friction + gravity;
|
||||
balls[i].speed.Y = balls[i].speed.Y * balls[i].friction + gravity;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -212,8 +212,8 @@ public partial class BallPhysics : IExample
|
|||
balls[i].position.Y = mousePos.Y - pressOffset.Y;
|
||||
|
||||
// While the ball is grabbed, recalculates its velocity
|
||||
balls[i].speed.X = (balls[i].position.X - balls[i].prevPosition.X)/delta;
|
||||
balls[i].speed.Y = (balls[i].position.Y - balls[i].prevPosition.Y)/delta;
|
||||
balls[i].speed.X = (balls[i].position.X - balls[i].prevPosition.X) / delta;
|
||||
balls[i].speed.Y = (balls[i].position.Y - balls[i].prevPosition.Y) / delta;
|
||||
balls[i].prevPosition = balls[i].position;
|
||||
}
|
||||
}
|
||||
|
|
@ -225,20 +225,20 @@ public partial class BallPhysics : IExample
|
|||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(Color.RayWhite);
|
||||
ClearBackground(Color.RayWhite);
|
||||
|
||||
for (int i = 0; i < ballCount; i++)
|
||||
{
|
||||
DrawCircleV(balls[i].position, balls[i].radius, balls[i].color);
|
||||
DrawCircleLinesV(balls[i].position, balls[i].radius, Color.Black);
|
||||
}
|
||||
for (int i = 0; i < ballCount; i++)
|
||||
{
|
||||
DrawCircleV(balls[i].position, balls[i].radius, balls[i].color);
|
||||
DrawCircleLinesV(balls[i].position, balls[i].radius, Color.Black);
|
||||
}
|
||||
|
||||
DrawText("grab a ball by pressing with the mouse and throw it by releasing", 10, 10, 10, Color.DarkGray);
|
||||
DrawText("right click to create new balls (keep left control pressed to create a lot)", 10, 30, 10, Color.DarkGray);
|
||||
DrawText("use mouse wheel to change gravity", 10, 50, 10, Color.DarkGray);
|
||||
DrawText("middle click to shake", 10, 70, 10, Color.DarkGray);
|
||||
DrawText($"BALL COUNT: {ballCount}", 10, GetScreenHeight() - 70, 20, Color.Black);
|
||||
DrawText($"GRAVITY: {gravity:F2}", 10, GetScreenHeight() - 40, 20, Color.Black);
|
||||
DrawText("grab a ball by pressing with the mouse and throw it by releasing", 10, 10, 10, Color.DarkGray);
|
||||
DrawText("right click to create new balls (keep left control pressed to create a lot)", 10, 30, 10, Color.DarkGray);
|
||||
DrawText("use mouse wheel to change gravity", 10, 50, 10, Color.DarkGray);
|
||||
DrawText("middle click to shake", 10, 70, 10, Color.DarkGray);
|
||||
DrawText($"BALL COUNT: {ballCount}", 10, GetScreenHeight() - 70, 20, Color.Black);
|
||||
DrawText($"GRAVITY: {gravity:F2}", 10, GetScreenHeight() - 40, 20, Color.Black);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -88,8 +88,8 @@ public partial class BulletHell : IExample
|
|||
// Draw circle to bullet texture, then draw bullet using DrawTexture()
|
||||
// NOTE: This is done to improve the performance, since DrawCircle() is very slow
|
||||
BeginTextureMode(bulletTexture);
|
||||
DrawCircle(12, 12, (float)bulletRadius, Color.White);
|
||||
DrawCircleLines(12, 12, (float)bulletRadius, Color.Black);
|
||||
DrawCircle(12, 12, (float)bulletRadius, Color.White);
|
||||
DrawCircleLines(12, 12, (float)bulletRadius, Color.Black);
|
||||
EndTextureMode();
|
||||
|
||||
drawInPerformanceMode = true;
|
||||
|
|
@ -113,16 +113,16 @@ public partial class BulletHell : IExample
|
|||
spawnCooldownTimer = spawnCooldown;
|
||||
|
||||
// Spawn bullets
|
||||
float degreesPerRow = 360.0f/bulletRows;
|
||||
float degreesPerRow = 360.0f / bulletRows;
|
||||
for (int row = 0; row < bulletRows; row++)
|
||||
{
|
||||
if (bulletCount < MAX_BULLETS)
|
||||
{
|
||||
bullets[bulletCount].position = new Vector2((float)screenWidth/2, (float)screenHeight/2);
|
||||
bullets[bulletCount].position = new Vector2((float)screenWidth / 2, (float)screenHeight / 2);
|
||||
bullets[bulletCount].disabled = false;
|
||||
bullets[bulletCount].color = bulletColor[row%2];
|
||||
bullets[bulletCount].color = bulletColor[row % 2];
|
||||
|
||||
float bulletDirection = baseDirection + (degreesPerRow*row);
|
||||
float bulletDirection = baseDirection + (degreesPerRow * row);
|
||||
|
||||
// Bullet speed*bullet direction, this will determine how much pixels will be incremented/decremented
|
||||
// from the bullet position every frame. Since the bullets doesn't change its direction and speed,
|
||||
|
|
@ -130,8 +130,8 @@ public partial class BulletHell : IExample
|
|||
// 0 degrees = right, 90 degrees = down, 180 degrees = left and 270 degrees = up, basically clockwise
|
||||
// Case you want it to be anti-clockwise, add "* -1" at the y acceleration
|
||||
bullets[bulletCount].acceleration = new Vector2(
|
||||
bulletSpeed*MathF.Cos(bulletDirection*DEG2RAD),
|
||||
bulletSpeed*MathF.Sin(bulletDirection*DEG2RAD)
|
||||
bulletSpeed * MathF.Cos(bulletDirection * DEG2RAD),
|
||||
bulletSpeed * MathF.Sin(bulletDirection * DEG2RAD)
|
||||
);
|
||||
|
||||
bulletCount++;
|
||||
|
|
@ -151,10 +151,10 @@ public partial class BulletHell : IExample
|
|||
bullets[i].position.Y += bullets[i].acceleration.Y;
|
||||
|
||||
// Disable bullet if out of screen
|
||||
if ((bullets[i].position.X < -bulletRadius*2) ||
|
||||
(bullets[i].position.X > screenWidth + bulletRadius*2) ||
|
||||
(bullets[i].position.Y < -bulletRadius*2) ||
|
||||
(bullets[i].position.Y > screenHeight + bulletRadius*2))
|
||||
if ((bullets[i].position.X < -bulletRadius * 2) ||
|
||||
(bullets[i].position.X > screenWidth + bulletRadius * 2) ||
|
||||
(bullets[i].position.Y < -bulletRadius * 2) ||
|
||||
(bullets[i].position.Y > screenHeight + bulletRadius * 2))
|
||||
{
|
||||
bullets[i].disabled = true;
|
||||
bulletDisabledCount++;
|
||||
|
|
@ -214,60 +214,60 @@ public partial class BulletHell : IExample
|
|||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.RayWhite);
|
||||
ClearBackground(Color.RayWhite);
|
||||
|
||||
// Draw magic circle
|
||||
magicCircleRotation++;
|
||||
DrawRectanglePro(new Rectangle((float)screenWidth/2, (float)screenHeight/2, 120, 120),
|
||||
new Vector2(60.0f, 60.0f), magicCircleRotation, Color.Purple);
|
||||
DrawRectanglePro(new Rectangle((float)screenWidth/2, (float)screenHeight/2, 120, 120),
|
||||
new Vector2(60.0f, 60.0f), magicCircleRotation + 45, Color.Purple);
|
||||
DrawCircleLines(screenWidth/2, screenHeight/2, 70, Color.Black);
|
||||
DrawCircleLines(screenWidth/2, screenHeight/2, 50, Color.Black);
|
||||
DrawCircleLines(screenWidth/2, screenHeight/2, 30, Color.Black);
|
||||
// Draw magic circle
|
||||
magicCircleRotation++;
|
||||
DrawRectanglePro(new Rectangle((float)screenWidth / 2, (float)screenHeight / 2, 120, 120),
|
||||
new Vector2(60.0f, 60.0f), magicCircleRotation, Color.Purple);
|
||||
DrawRectanglePro(new Rectangle((float)screenWidth / 2, (float)screenHeight / 2, 120, 120),
|
||||
new Vector2(60.0f, 60.0f), magicCircleRotation + 45, Color.Purple);
|
||||
DrawCircleLines(screenWidth / 2, screenHeight / 2, 70, Color.Black);
|
||||
DrawCircleLines(screenWidth / 2, screenHeight / 2, 50, Color.Black);
|
||||
DrawCircleLines(screenWidth / 2, screenHeight / 2, 30, Color.Black);
|
||||
|
||||
// Draw bullets
|
||||
if (drawInPerformanceMode)
|
||||
// Draw bullets
|
||||
if (drawInPerformanceMode)
|
||||
{
|
||||
// Draw bullets using pre-rendered texture containing circle
|
||||
for (int i = 0; i < bulletCount; i++)
|
||||
{
|
||||
// Draw bullets using pre-rendered texture containing circle
|
||||
for (int i = 0; i < bulletCount; i++)
|
||||
// Do not draw disabled bullets (out of screen)
|
||||
if (!bullets[i].disabled)
|
||||
{
|
||||
// Do not draw disabled bullets (out of screen)
|
||||
if (!bullets[i].disabled)
|
||||
{
|
||||
DrawTexture(bulletTexture.Texture,
|
||||
(int)(bullets[i].position.X - bulletTexture.Texture.Width*0.5f),
|
||||
(int)(bullets[i].position.Y - bulletTexture.Texture.Height*0.5f),
|
||||
bullets[i].color);
|
||||
}
|
||||
DrawTexture(bulletTexture.Texture,
|
||||
(int)(bullets[i].position.X - bulletTexture.Texture.Width * 0.5f),
|
||||
(int)(bullets[i].position.Y - bulletTexture.Texture.Height * 0.5f),
|
||||
bullets[i].color);
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw bullets using DrawCircle(), less performant
|
||||
for (int i = 0; i < bulletCount; i++)
|
||||
{
|
||||
// Draw bullets using DrawCircle(), less performant
|
||||
for (int i = 0; i < bulletCount; i++)
|
||||
// Do not draw disabled bullets (out of screen)
|
||||
if (!bullets[i].disabled)
|
||||
{
|
||||
// Do not draw disabled bullets (out of screen)
|
||||
if (!bullets[i].disabled)
|
||||
{
|
||||
DrawCircleV(bullets[i].position, (float)bulletRadius, bullets[i].color);
|
||||
DrawCircleLinesV(bullets[i].position, (float)bulletRadius, Color.Black);
|
||||
}
|
||||
DrawCircleV(bullets[i].position, (float)bulletRadius, bullets[i].color);
|
||||
DrawCircleLinesV(bullets[i].position, (float)bulletRadius, Color.Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw UI
|
||||
DrawRectangle(10, 10, 280, 150, new Color(0, 0, 0, 200));
|
||||
DrawText("Controls:", 20, 20, 10, Color.LightGray);
|
||||
DrawText("- Right/Left or A/D: Change rows number", 40, 40, 10, Color.LightGray);
|
||||
DrawText("- Up/Down or W/S: Change bullet speed", 40, 60, 10, Color.LightGray);
|
||||
DrawText("- Z or X: Change spawn cooldown", 40, 80, 10, Color.LightGray);
|
||||
DrawText("- Space (Hold): Change the angle increment", 40, 100, 10, Color.LightGray);
|
||||
DrawText("- Enter: Switch draw method (Performance)", 40, 120, 10, Color.LightGray);
|
||||
DrawText("- C: Clear bullets", 40, 140, 10, Color.LightGray);
|
||||
// Draw UI
|
||||
DrawRectangle(10, 10, 280, 150, new Color(0, 0, 0, 200));
|
||||
DrawText("Controls:", 20, 20, 10, Color.LightGray);
|
||||
DrawText("- Right/Left or A/D: Change rows number", 40, 40, 10, Color.LightGray);
|
||||
DrawText("- Up/Down or W/S: Change bullet speed", 40, 60, 10, Color.LightGray);
|
||||
DrawText("- Z or X: Change spawn cooldown", 40, 80, 10, Color.LightGray);
|
||||
DrawText("- Space (Hold): Change the angle increment", 40, 100, 10, Color.LightGray);
|
||||
DrawText("- Enter: Switch draw method (Performance)", 40, 120, 10, Color.LightGray);
|
||||
DrawText("- C: Clear bullets", 40, 140, 10, Color.LightGray);
|
||||
|
||||
DrawRectangle(610, 10, 170, 30, new Color(0, 0, 0, 200));
|
||||
if (drawInPerformanceMode)
|
||||
DrawRectangle(610, 10, 170, 30, new Color(0, 0, 0, 200));
|
||||
if (drawInPerformanceMode)
|
||||
{
|
||||
DrawText("Draw method: DrawTexture(*)", 620, 20, 10, Color.Green);
|
||||
}
|
||||
|
|
@ -277,8 +277,8 @@ public partial class BulletHell : IExample
|
|||
}
|
||||
|
||||
DrawRectangle(135, 410, 530, 30, new Color(0, 0, 0, 200));
|
||||
DrawText($"[ FPS: {GetFPS()}, Bullets: {bulletCount - bulletDisabledCount}, Rows: {bulletRows}, Bullet speed: {bulletSpeed:F2}, Angle increment per frame: {angleIncrement}, Cooldown: {spawnCooldown:F0} ]",
|
||||
155, 420, 10, Color.Green);
|
||||
DrawText($"[ FPS: {GetFPS()}, Bullets: {bulletCount - bulletDisabledCount}, Rows: {bulletRows}, Bullet speed: {bulletSpeed:F2}, Angle increment per frame: {angleIncrement}, Cooldown: {spawnCooldown:F0} ]",
|
||||
155, 420, 10, Color.Green);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public partial class DashedLine : IExample
|
|||
// Cycle through colors ('C' key)
|
||||
if (IsKeyPressed(KeyboardKey.C))
|
||||
{
|
||||
colorIndex = (colorIndex + 1)%lineColors.Length;
|
||||
colorIndex = (colorIndex + 1) % lineColors.Length;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -88,23 +88,23 @@ public partial class DashedLine : IExample
|
|||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(Color.RayWhite);
|
||||
ClearBackground(Color.RayWhite);
|
||||
|
||||
// Draw the dashed line with the current properties
|
||||
DrawLineDashed(lineStartPosition, lineEndPosition, (int)dashLength, (int)blankLength, lineColors[colorIndex]);
|
||||
// Draw the dashed line with the current properties
|
||||
DrawLineDashed(lineStartPosition, lineEndPosition, (int)dashLength, (int)blankLength, lineColors[colorIndex]);
|
||||
|
||||
// Draw UI and Instructions
|
||||
DrawRectangle(5, 5, 265, 95, Fade(Color.SkyBlue, 0.5f));
|
||||
DrawRectangleLines(5, 5, 265, 95, Color.Blue);
|
||||
// Draw UI and Instructions
|
||||
DrawRectangle(5, 5, 265, 95, Fade(Color.SkyBlue, 0.5f));
|
||||
DrawRectangleLines(5, 5, 265, 95, Color.Blue);
|
||||
|
||||
DrawText("CONTROLS:", 15, 15, 10, Color.Black);
|
||||
DrawText("UP/DOWN: Change Dash Length", 15, 35, 10, Color.Black);
|
||||
DrawText("LEFT/RIGHT: Change Space Length", 15, 55, 10, Color.Black);
|
||||
DrawText("C: Cycle Color", 15, 75, 10, Color.Black);
|
||||
DrawText("CONTROLS:", 15, 15, 10, Color.Black);
|
||||
DrawText("UP/DOWN: Change Dash Length", 15, 35, 10, Color.Black);
|
||||
DrawText("LEFT/RIGHT: Change Space Length", 15, 55, 10, Color.Black);
|
||||
DrawText("C: Cycle Color", 15, 75, 10, Color.Black);
|
||||
|
||||
DrawText($"Dash: {dashLength:F0} | Space: {blankLength:F0}", 15, 115, 10, Color.DarkGray);
|
||||
DrawText($"Dash: {dashLength:F0} | Space: {blankLength:F0}", 15, 115, 10, Color.DarkGray);
|
||||
|
||||
DrawFPS(screenWidth - 80, 10);
|
||||
DrawFPS(screenWidth - 80, 10);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -213,17 +213,38 @@ public partial class DigitalClock : IExample
|
|||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0: Draw7SDisplay(position, 0b00111111, colorOn, colorOff); break;
|
||||
case 1: Draw7SDisplay(position, 0b00000110, colorOn, colorOff); break;
|
||||
case 2: Draw7SDisplay(position, 0b01011011, colorOn, colorOff); break;
|
||||
case 3: Draw7SDisplay(position, 0b01001111, colorOn, colorOff); break;
|
||||
case 4: Draw7SDisplay(position, 0b01100110, colorOn, colorOff); break;
|
||||
case 5: Draw7SDisplay(position, 0b01101101, colorOn, colorOff); break;
|
||||
case 6: Draw7SDisplay(position, 0b01111101, colorOn, colorOff); break;
|
||||
case 7: Draw7SDisplay(position, 0b00000111, colorOn, colorOff); break;
|
||||
case 8: Draw7SDisplay(position, 0b01111111, colorOn, colorOff); break;
|
||||
case 9: Draw7SDisplay(position, 0b01101111, colorOn, colorOff); break;
|
||||
default: break;
|
||||
case 0:
|
||||
Draw7SDisplay(position, 0b00111111, colorOn, colorOff);
|
||||
break;
|
||||
case 1:
|
||||
Draw7SDisplay(position, 0b00000110, colorOn, colorOff);
|
||||
break;
|
||||
case 2:
|
||||
Draw7SDisplay(position, 0b01011011, colorOn, colorOff);
|
||||
break;
|
||||
case 3:
|
||||
Draw7SDisplay(position, 0b01001111, colorOn, colorOff);
|
||||
break;
|
||||
case 4:
|
||||
Draw7SDisplay(position, 0b01100110, colorOn, colorOff);
|
||||
break;
|
||||
case 5:
|
||||
Draw7SDisplay(position, 0b01101101, colorOn, colorOff);
|
||||
break;
|
||||
case 6:
|
||||
Draw7SDisplay(position, 0b01111101, colorOn, colorOff);
|
||||
break;
|
||||
case 7:
|
||||
Draw7SDisplay(position, 0b00000111, colorOn, colorOff);
|
||||
break;
|
||||
case 8:
|
||||
Draw7SDisplay(position, 0b01111111, colorOn, colorOff);
|
||||
break;
|
||||
case 9:
|
||||
Draw7SDisplay(position, 0b01101111, colorOn, colorOff);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,14 @@ public partial class DoublePendulum : IExample
|
|||
public void Init()
|
||||
{
|
||||
// Simulation Parameters
|
||||
l1 = 15.0f; m1 = 0.2f; theta1 = DEG2RAD * 170; w1 = 0;
|
||||
l2 = 15.0f; m2 = 0.1f; theta2 = DEG2RAD * 0; w2 = 0;
|
||||
l1 = 15.0f;
|
||||
m1 = 0.2f;
|
||||
theta1 = DEG2RAD * 170;
|
||||
w1 = 0;
|
||||
l2 = 15.0f;
|
||||
m2 = 0.1f;
|
||||
theta2 = DEG2RAD * 0;
|
||||
w2 = 0;
|
||||
lengthScaler = 0.1f;
|
||||
totalM = m1 + m2;
|
||||
|
||||
|
|
@ -82,7 +88,8 @@ public partial class DoublePendulum : IExample
|
|||
L2 = l2 * lengthScaler;
|
||||
|
||||
// Draw parameters
|
||||
lineThick = 20; trailThick = 2;
|
||||
lineThick = 20;
|
||||
trailThick = 2;
|
||||
fateAlpha = 0.01f;
|
||||
|
||||
// Create framebuffer
|
||||
|
|
|
|||
|
|
@ -162,24 +162,30 @@ public partial class HilbertCurve : IExample
|
|||
switch (hilbertIndex)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
temp = vect.X;
|
||||
vect.X = vect.Y;
|
||||
vect.Y = temp;
|
||||
} break;
|
||||
{
|
||||
temp = vect.X;
|
||||
vect.X = vect.Y;
|
||||
vect.Y = temp;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
vect.X += len;
|
||||
{
|
||||
vect.X += len;
|
||||
vect.Y += len;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
vect.Y += len;
|
||||
} break;
|
||||
case 1: vect.Y += len; break;
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
temp = len - 1 - vect.X;
|
||||
vect.X = 2 * len - 1 - vect.Y;
|
||||
vect.Y = temp;
|
||||
} break;
|
||||
default: break;
|
||||
{
|
||||
temp = len - 1 - vect.X;
|
||||
vect.X = 2 * len - 1 - vect.Y;
|
||||
vect.Y = temp;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public partial class LinesDrawing : IExample
|
|||
|
||||
// Clear the canvas to the background color
|
||||
BeginTextureMode(canvas);
|
||||
ClearBackground(Color.RayWhite);
|
||||
ClearBackground(Color.RayWhite);
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ public partial class LinesDrawing : IExample
|
|||
if (IsMouseButtonPressed(MouseButton.Middle))
|
||||
{
|
||||
BeginTextureMode(canvas);
|
||||
ClearBackground(Color.RayWhite);
|
||||
ClearBackground(Color.RayWhite);
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ public partial class LinesDrawing : IExample
|
|||
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;
|
||||
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
|
||||
|
|
@ -113,10 +113,10 @@ public partial class LinesDrawing : IExample
|
|||
|
||||
// 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);
|
||||
// Circles act as "caps", smoothing corners
|
||||
DrawCircleV(mousePositionPrevious, lineThickness / 2.0f, drawColor);
|
||||
DrawCircleV(GetMousePosition(), lineThickness / 2.0f, drawColor);
|
||||
DrawLineEx(mousePositionPrevious, GetMousePosition(), lineThickness, drawColor);
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
|
|
@ -132,13 +132,13 @@ public partial class LinesDrawing : IExample
|
|||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
// Draw the render texture to the screen, flipped vertically to make it appear top-side up
|
||||
DrawTextureRec(canvas.Texture, new Rectangle(0.0f, 0.0f, (float)canvas.Texture.Width, (float)-canvas.Texture.Height), Vector2Zero(), Color.White);
|
||||
// Draw the render texture to the screen, flipped vertically to make it appear top-side up
|
||||
DrawTextureRec(canvas.Texture, new Rectangle(0.0f, 0.0f, (float)canvas.Texture.Width, (float)-canvas.Texture.Height), Vector2Zero(), Color.White);
|
||||
|
||||
// Draw the preview circle
|
||||
if (!leftButtonDown)
|
||||
// Draw the preview circle
|
||||
if (!leftButtonDown)
|
||||
{
|
||||
DrawCircleLinesV(GetMousePosition(), lineThickness/2.0f, new Color(127, 127, 127, 127));
|
||||
DrawCircleLinesV(GetMousePosition(), lineThickness / 2.0f, new Color(127, 127, 127, 127));
|
||||
}
|
||||
|
||||
// Draw the hint text
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public partial class MathAngleRotation : IExample
|
|||
|
||||
public void Init()
|
||||
{
|
||||
center = new Vector2(screenWidth/2.0f, screenHeight/2.0f);
|
||||
center = new Vector2(screenWidth / 2.0f, screenHeight / 2.0f);
|
||||
|
||||
// Predefined angles for fixed lines
|
||||
angles = new[] { 0, 30, 60, 90 };
|
||||
|
|
@ -64,44 +64,54 @@ public partial class MathAngleRotation : IExample
|
|||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.White);
|
||||
ClearBackground(Color.White);
|
||||
|
||||
DrawText("Fixed angles + rotating line", 10, 10, 20, Color.LightGray);
|
||||
DrawText("Fixed angles + rotating line", 10, 10, 20, Color.LightGray);
|
||||
|
||||
// Draw fixed-angle lines with colorful gradient
|
||||
for (int i = 0; i < numAngles; i++)
|
||||
// Draw fixed-angle lines with colorful gradient
|
||||
for (int i = 0; i < numAngles; i++)
|
||||
{
|
||||
float rad = angles[i] * DEG2RAD;
|
||||
Vector2 end = new Vector2(center.X + MathF.Cos(rad) * lineLength,
|
||||
center.Y + MathF.Sin(rad) * lineLength);
|
||||
|
||||
// Gradient color from green → cyan → blue → magenta
|
||||
Color col;
|
||||
switch (i)
|
||||
{
|
||||
float rad = angles[i]*DEG2RAD;
|
||||
Vector2 end = new Vector2(center.X + MathF.Cos(rad)*lineLength,
|
||||
center.Y + MathF.Sin(rad)*lineLength);
|
||||
|
||||
// Gradient color from green → cyan → blue → magenta
|
||||
Color col;
|
||||
switch(i)
|
||||
{
|
||||
case 0: col = Color.Green; break;
|
||||
case 1: col = Color.Orange; break;
|
||||
case 2: col = Color.Blue; break;
|
||||
case 3: col = Color.Magenta; break;
|
||||
default: col = Color.White; break;
|
||||
}
|
||||
|
||||
DrawLineEx(center, end, 5.0f, col);
|
||||
|
||||
// Draw angle label slightly offset along the line
|
||||
Vector2 textPos = new Vector2(center.X + MathF.Cos(rad)*(lineLength + 20),
|
||||
center.Y + MathF.Sin(rad)*(lineLength + 20));
|
||||
DrawText($"{angles[i]}°", (int)textPos.X, (int)textPos.Y, 20, col);
|
||||
case 0:
|
||||
col = Color.Green;
|
||||
break;
|
||||
case 1:
|
||||
col = Color.Orange;
|
||||
break;
|
||||
case 2:
|
||||
col = Color.Blue;
|
||||
break;
|
||||
case 3:
|
||||
col = Color.Magenta;
|
||||
break;
|
||||
default:
|
||||
col = Color.White;
|
||||
break;
|
||||
}
|
||||
|
||||
// Draw animated rotating line with changing color
|
||||
float animRad = totalAngle*DEG2RAD;
|
||||
Vector2 animEnd = new Vector2(center.X + MathF.Cos(animRad)*lineLength,
|
||||
center.Y + MathF.Sin(animRad)*lineLength);
|
||||
DrawLineEx(center, end, 5.0f, col);
|
||||
|
||||
// Cycle through HSV colors for animated line
|
||||
Color animCol = ColorFromHSV(totalAngle % 360.0f, 0.8f, 0.9f);
|
||||
DrawLineEx(center, animEnd, 5.0f, animCol);
|
||||
// Draw angle label slightly offset along the line
|
||||
Vector2 textPos = new Vector2(center.X + MathF.Cos(rad) * (lineLength + 20),
|
||||
center.Y + MathF.Sin(rad) * (lineLength + 20));
|
||||
DrawText($"{angles[i]}°", (int)textPos.X, (int)textPos.Y, 20, col);
|
||||
}
|
||||
|
||||
// Draw animated rotating line with changing color
|
||||
float animRad = totalAngle * DEG2RAD;
|
||||
Vector2 animEnd = new Vector2(center.X + MathF.Cos(animRad) * lineLength,
|
||||
center.Y + MathF.Sin(animRad) * lineLength);
|
||||
|
||||
// Cycle through HSV colors for animated line
|
||||
Color animCol = ColorFromHSV(totalAngle % 360.0f, 0.8f, 0.9f);
|
||||
DrawLineEx(center, animEnd, 5.0f, animCol);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -59,32 +59,32 @@ public partial class MouseTrail : IExample
|
|||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(Color.Black);
|
||||
ClearBackground(Color.Black);
|
||||
|
||||
// Draw the trail by looping through the history array
|
||||
for (int i = 0; i < MAX_TRAIL_LENGTH; i++)
|
||||
// Draw the trail by looping through the history array
|
||||
for (int i = 0; i < MAX_TRAIL_LENGTH; i++)
|
||||
{
|
||||
// Ensure we skip drawing if the array hasn't been fully filled on startup
|
||||
if ((trailPositions[i].X != 0.0f) || (trailPositions[i].Y != 0.0f))
|
||||
{
|
||||
// Ensure we skip drawing if the array hasn't been fully filled on startup
|
||||
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;
|
||||
// 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;
|
||||
|
||||
// Fade effect: oldest positions are more transparent
|
||||
// Fade (color, alpha) - alpha is 0.5 to 1.0 based on ratio
|
||||
Color trailColor = Fade(Color.SkyBlue, ratio*0.5f + 0.5f);
|
||||
// Fade effect: oldest positions are more transparent
|
||||
// Fade (color, alpha) - alpha is 0.5 to 1.0 based on ratio
|
||||
Color trailColor = Fade(Color.SkyBlue, ratio * 0.5f + 0.5f);
|
||||
|
||||
// Size effect: oldest positions are smaller
|
||||
float trailRadius = 15.0f*ratio;
|
||||
// Size effect: oldest positions are smaller
|
||||
float trailRadius = 15.0f * ratio;
|
||||
|
||||
DrawCircleV(trailPositions[i], trailRadius, trailColor);
|
||||
}
|
||||
DrawCircleV(trailPositions[i], trailRadius, trailColor);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a distinct white circle for the current mouse position (Index 0)
|
||||
DrawCircleV(mousePosition, 15.0f, Color.White);
|
||||
// Draw a distinct white circle for the current mouse position (Index 0)
|
||||
DrawCircleV(mousePosition, 15.0f, Color.White);
|
||||
|
||||
DrawText("Move the mouse to see the trail effect!", 10, screenHeight - 30, 20, Color.LightGray);
|
||||
DrawText("Move the mouse to see the trail effect!", 10, screenHeight - 30, 20, Color.LightGray);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -194,17 +194,26 @@ public partial class PenroseTile : IExample
|
|||
char step = production[i];
|
||||
switch (step)
|
||||
{
|
||||
case 'W': newProduction.Append(ls.ruleW); break;
|
||||
case 'X': newProduction.Append(ls.ruleX); break;
|
||||
case 'Y': newProduction.Append(ls.ruleY); break;
|
||||
case 'Z': newProduction.Append(ls.ruleZ); break;
|
||||
case 'W':
|
||||
newProduction.Append(ls.ruleW);
|
||||
break;
|
||||
case 'X':
|
||||
newProduction.Append(ls.ruleX);
|
||||
break;
|
||||
case 'Y':
|
||||
newProduction.Append(ls.ruleY);
|
||||
break;
|
||||
case 'Z':
|
||||
newProduction.Append(ls.ruleZ);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (step != 'F')
|
||||
{
|
||||
if (step != 'F')
|
||||
{
|
||||
newProduction.Append(step);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -162,10 +162,26 @@ public partial class RectangleAdvanced : IExample
|
|||
{
|
||||
Color color = new Color(0, 0, 0, 0);
|
||||
float radius = 0.0f;
|
||||
if (k == 0) { color = left; radius = radiusLeft; } // [1] Upper Left Corner
|
||||
if (k == 1) { color = right; radius = radiusRight; } // [3] Upper Right Corner
|
||||
if (k == 2) { color = right; radius = radiusRight; } // [5] Lower Right Corner
|
||||
if (k == 3) { color = left; radius = radiusLeft; } // [7] Lower Left Corner
|
||||
if (k == 0)
|
||||
{
|
||||
color = left;
|
||||
radius = radiusLeft;
|
||||
} // [1] Upper Left Corner
|
||||
if (k == 1)
|
||||
{
|
||||
color = right;
|
||||
radius = radiusRight;
|
||||
} // [3] Upper Right Corner
|
||||
if (k == 2)
|
||||
{
|
||||
color = right;
|
||||
radius = radiusRight;
|
||||
} // [5] Lower Right Corner
|
||||
if (k == 3)
|
||||
{
|
||||
color = left;
|
||||
radius = radiusLeft;
|
||||
} // [7] Lower Left Corner
|
||||
|
||||
float angle = angles[k];
|
||||
Vector2 center = centers[k];
|
||||
|
|
|
|||
|
|
@ -190,22 +190,26 @@ public partial class SimpleParticles : IExample
|
|||
switch (type)
|
||||
{
|
||||
case ParticleType.Water:
|
||||
{
|
||||
newParticle.radius = 5.0f;
|
||||
newParticle.color = Color.Blue;
|
||||
} break;
|
||||
{
|
||||
newParticle.radius = 5.0f;
|
||||
newParticle.color = Color.Blue;
|
||||
}
|
||||
break;
|
||||
case ParticleType.Smoke:
|
||||
{
|
||||
newParticle.radius = 7.0f;
|
||||
newParticle.color = Color.Gray;
|
||||
} break;
|
||||
{
|
||||
newParticle.radius = 7.0f;
|
||||
newParticle.color = Color.Gray;
|
||||
}
|
||||
break;
|
||||
case ParticleType.Fire:
|
||||
{
|
||||
newParticle.radius = 10.0f;
|
||||
newParticle.color = Color.Yellow;
|
||||
speed /= 10.0f;
|
||||
} break;
|
||||
default: break;
|
||||
{
|
||||
newParticle.radius = 10.0f;
|
||||
newParticle.color = Color.Yellow;
|
||||
speed /= 10.0f;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
float direction = (float)(random.Next(360));
|
||||
|
|
@ -238,41 +242,45 @@ public partial class SimpleParticles : IExample
|
|||
switch (buffer[i].type)
|
||||
{
|
||||
case ParticleType.Water:
|
||||
{
|
||||
buffer[i].position.X += buffer[i].velocity.X;
|
||||
buffer[i].velocity.Y += 0.2f; // Gravity
|
||||
buffer[i].position.Y += buffer[i].velocity.Y;
|
||||
} break;
|
||||
{
|
||||
buffer[i].position.X += buffer[i].velocity.X;
|
||||
buffer[i].velocity.Y += 0.2f; // Gravity
|
||||
buffer[i].position.Y += buffer[i].velocity.Y;
|
||||
}
|
||||
break;
|
||||
case ParticleType.Smoke:
|
||||
{
|
||||
buffer[i].position.X += buffer[i].velocity.X;
|
||||
buffer[i].velocity.Y -= 0.05f; // Upwards
|
||||
buffer[i].position.Y += buffer[i].velocity.Y;
|
||||
buffer[i].radius += 0.5f; // Increment radius: smoke expands
|
||||
buffer[i].color.A -= 4; // Decrement alpha: smoke fades
|
||||
{
|
||||
buffer[i].position.X += buffer[i].velocity.X;
|
||||
buffer[i].velocity.Y -= 0.05f; // Upwards
|
||||
buffer[i].position.Y += buffer[i].velocity.Y;
|
||||
buffer[i].radius += 0.5f; // Increment radius: smoke expands
|
||||
buffer[i].color.A -= 4; // Decrement alpha: smoke fades
|
||||
|
||||
// If alpha transparent, particle dies
|
||||
if (buffer[i].color.A < 4)
|
||||
// If alpha transparent, particle dies
|
||||
if (buffer[i].color.A < 4)
|
||||
{
|
||||
buffer[i].alive = false;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
case ParticleType.Fire:
|
||||
{
|
||||
// Add a little horizontal oscillation to fire particles
|
||||
buffer[i].position.X += buffer[i].velocity.X + MathF.Cos(buffer[i].lifeTime * 215.0f);
|
||||
buffer[i].velocity.Y -= 0.05f; // Upwards
|
||||
buffer[i].position.Y += buffer[i].velocity.Y;
|
||||
buffer[i].radius -= 0.15f; // Decrement radius: fire shrinks
|
||||
buffer[i].color.G -= 3; // Decrement green: fire turns reddish starting from yellow
|
||||
{
|
||||
// Add a little horizontal oscillation to fire particles
|
||||
buffer[i].position.X += buffer[i].velocity.X + MathF.Cos(buffer[i].lifeTime * 215.0f);
|
||||
buffer[i].velocity.Y -= 0.05f; // Upwards
|
||||
buffer[i].position.Y += buffer[i].velocity.Y;
|
||||
buffer[i].radius -= 0.15f; // Decrement radius: fire shrinks
|
||||
buffer[i].color.G -= 3; // Decrement green: fire turns reddish starting from yellow
|
||||
|
||||
// If radius too small, particle dies
|
||||
if (buffer[i].radius <= 0.02f)
|
||||
// If radius too small, particle dies
|
||||
if (buffer[i].radius <= 0.02f)
|
||||
{
|
||||
buffer[i].alive = false;
|
||||
}
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Disable particle when out of screen
|
||||
|
|
|
|||
Loading…
Reference in a new issue