diff --git a/public/usage-examples/camera/move_camera_to-1-example-oop.cs b/public/usage-examples/camera/move_camera_to-1-example-oop.cs new file mode 100644 index 000000000..3d5863f17 --- /dev/null +++ b/public/usage-examples/camera/move_camera_to-1-example-oop.cs @@ -0,0 +1,74 @@ +using SplashKitSDK; + +namespace MoveCameraToExample +{ + public class Program + { + public static void Main() + { + // Open a window + Window window = SplashKit.OpenWindow("Move Camera To Example", 800, 600); + + // Create a player bitmap and sprite + Bitmap playerBmp = SplashKit.CreateBitmap("player", 40, 40); + playerBmp.Clear(Color.BrightGreen); + Sprite player = SplashKit.CreateSprite(playerBmp); + + // Position the player further out in the game world + player.X = 1000; + player.Y = 1000; + + while (!window.CloseRequested) + { + // Handle input to move the player + SplashKit.ProcessEvents(); + + if (SplashKit.KeyDown(KeyCode.LeftKey)) player.X -= 5; + if (SplashKit.KeyDown(KeyCode.RightKey)) player.X += 5; + if (SplashKit.KeyDown(KeyCode.UpKey)) player.Y -= 5; + if (SplashKit.KeyDown(KeyCode.DownKey)) player.Y += 5; + + // Center camera on player when SPACE is pressed + if (SplashKit.KeyTyped(KeyCode.SpaceKey)) + { + // Calculate the top-left position for the camera to center the player + double targetX = player.X + player.Width / 2 - SplashKit.ScreenWidth() / 2; + double targetY = player.Y + player.Height / 2 - SplashKit.ScreenHeight() / 2; + + // Move the camera to the calculated point + SplashKit.MoveCameraTo(targetX, targetY); + } + + // Reset camera to origin when M is pressed + if (SplashKit.KeyTyped(KeyCode.MKey)) + { + SplashKit.MoveCameraTo(0, 0); + } + + // Clear the screen + window.Clear(Color.Black); + + // Draw some world markers to visualize the camera move + window.FillRectangle(Color.White, 0, 0, 20, 20); + window.DrawText("World (0,0)", Color.White, 5, 25); + + window.FillRectangle(Color.Red, 1000, 1000, 20, 20); + window.DrawText("World (1000,1000)", Color.Red, 1000, 1025); + + // Draw the sprite (automatically uses camera offset) + player.Draw(); + + // Draw HUD (Heads-Up Display) directly to the screen + window.FillRectangle(Color.DimGray, 0, 0, 260, 80, SplashKit.OptionToScreen()); + window.DrawText($"Camera Position: {SplashKit.PointToString(Camera.Position)}", Color.White, 10, 10, SplashKit.OptionToScreen()); + window.DrawText($"Player World Pos: ({(int)player.X}, {(int)player.Y})", Color.White, 10, 30, SplashKit.OptionToScreen()); + window.DrawText("Press SPACE to center on player", Color.White, 10, 50, SplashKit.OptionToScreen()); + window.DrawText("Press M to move camera to (0,0)", Color.White, 10, 65, SplashKit.OptionToScreen()); + + window.Refresh(60); + } + + SplashKit.CloseAllWindows(); + } + } +} diff --git a/public/usage-examples/camera/move_camera_to-1-example-top-level.cs b/public/usage-examples/camera/move_camera_to-1-example-top-level.cs new file mode 100644 index 000000000..f191924ef --- /dev/null +++ b/public/usage-examples/camera/move_camera_to-1-example-top-level.cs @@ -0,0 +1,66 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Open a window +OpenWindow("Move Camera To Example", 800, 600); + +// Create a player bitmap and sprite +Bitmap playerBmp = CreateBitmap("player", 40, 40); +ClearBitmap(playerBmp, ColorBrightGreen()); +Sprite player = CreateSprite(playerBmp); + +// Position the player further out in the game world +SpriteSetX(player, 1000); +SpriteSetY(player, 1000); + +while (!QuitRequested()) +{ + // Handle input to move the player + ProcessEvents(); + + if (KeyDown(KeyCode.LeftKey)) SpriteSetX(player, SpriteX(player) - 5); + if (KeyDown(KeyCode.RightKey)) SpriteSetX(player, SpriteX(player) + 5); + if (KeyDown(KeyCode.UpKey)) SpriteSetY(player, SpriteY(player) - 5); + if (KeyDown(KeyCode.DownKey)) SpriteSetY(player, SpriteY(player) + 5); + + // Center camera on player when SPACE is pressed + if (KeyTyped(KeyCode.SpaceKey)) + { + // Calculate the top-left position for the camera to center the player + double targetX = SpriteX(player) + SpriteWidth(player) / 2 - ScreenWidth() / 2; + double targetY = SpriteY(player) + SpriteHeight(player) / 2 - ScreenHeight() / 2; + + // Move the camera to the calculated point + MoveCameraTo(targetX, targetY); + } + + // Reset camera to origin when M is pressed + if (KeyTyped(KeyCode.MKey)) + { + MoveCameraTo(0, 0); + } + + // Clear the screen + ClearScreen(ColorBlack()); + + // Draw some world markers to visualize the camera move + FillRectangle(ColorWhite(), 0, 0, 20, 20); + DrawText("World (0,0)", ColorWhite(), 5, 25); + + FillRectangle(ColorRed(), 1000, 1000, 20, 20); + DrawText("World (1000,1000)", ColorRed(), 1000, 1025); + + // Draw the sprite (automatically uses camera offset) + DrawSprite(player); + + // Draw HUD (Heads-Up Display) directly to the screen + FillRectangle(ColorDimGray(), 0, 0, 260, 80, OptionToScreen()); + DrawText($"Camera Position: {PointToString(CameraPosition())}", ColorWhite(), 10, 10, OptionToScreen()); + DrawText($"Player World Pos: ({(int)SpriteX(player)}, {(int)SpriteY(player)})", ColorWhite(), 10, 30, OptionToScreen()); + DrawText("Press SPACE to center on player", ColorWhite(), 10, 50, OptionToScreen()); + DrawText("Press M to move camera to (0,0)", ColorWhite(), 10, 65, OptionToScreen()); + + RefreshScreen(60); +} + +CloseAllWindows(); diff --git a/public/usage-examples/camera/move_camera_to-1-example.cpp b/public/usage-examples/camera/move_camera_to-1-example.cpp new file mode 100644 index 000000000..be017494c --- /dev/null +++ b/public/usage-examples/camera/move_camera_to-1-example.cpp @@ -0,0 +1,70 @@ +#include "splashkit.h" + +int main() +{ + // Open a window + open_window("Move Camera To Example", 800, 600); + + // Create a player bitmap and sprite + // This allows us to have an object to follow in the world + bitmap player_bmp = create_bitmap("player", 40, 40); + clear_bitmap(player_bmp, COLOR_BRIGHT_GREEN); + sprite player = create_sprite(player_bmp); + + // Position the player further out in the game world + sprite_set_x(player, 1000); + sprite_set_y(player, 1000); + + while (!quit_requested()) + { + // Handle input to move the player + process_events(); + + if (key_down(LEFT_KEY)) sprite_set_x(player, sprite_x(player) - 5); + if (key_down(RIGHT_KEY)) sprite_set_x(player, sprite_x(player) + 5); + if (key_down(UP_KEY)) sprite_set_y(player, sprite_y(player) - 5); + if (key_down(DOWN_KEY)) sprite_set_y(player, sprite_y(player) + 5); + + // Center camera on player when SPACE is pressed + if (key_typed(SPACE_KEY)) + { + // Calculate the top-left position for the camera to center the player + double target_x = sprite_x(player) + sprite_width(player) / 2 - screen_width() / 2; + double target_y = sprite_y(player) + sprite_height(player) / 2 - screen_height() / 2; + + // Move the camera to the calculated point + move_camera_to(target_x, target_y); + } + + // Reset camera to origin when M is pressed + if (key_typed(M_KEY)) + { + move_camera_to(0, 0); + } + + // Clear the screen + clear_screen(COLOR_BLACK); + + // Draw some world markers to visualize the camera move + fill_rectangle(COLOR_WHITE, 0, 0, 20, 20); + draw_text("World (0,0)", COLOR_WHITE, 5, 25); + + fill_rectangle(COLOR_RED, 1000, 1000, 20, 20); + draw_text("World (1000,1000)", COLOR_RED, 1000, 1025); + + // Draw the sprite (automatically uses camera offset) + draw_sprite(player); + + // Draw HUD (Heads-Up Display) directly to the screen + fill_rectangle(COLOR_DIM_GRAY, 0, 0, 260, 80, option_to_screen()); + draw_text("Camera Position: " + point_to_string(camera_position()), COLOR_WHITE, 10, 10, option_to_screen()); + draw_text("Player World Pos: (" + std::to_string((int)sprite_x(player)) + ", " + std::to_string((int)sprite_y(player)) + ")", COLOR_WHITE, 10, 30, option_to_screen()); + draw_text("Press SPACE to center on player", COLOR_WHITE, 10, 50, option_to_screen()); + draw_text("Press M to move camera to (0,0)", COLOR_WHITE, 10, 65, option_to_screen()); + + refresh_screen(60); + } + + close_all_windows(); + return 0; +} diff --git a/public/usage-examples/camera/move_camera_to-1-example.pas b/public/usage-examples/camera/move_camera_to-1-example.pas new file mode 100644 index 000000000..96eca33d0 --- /dev/null +++ b/public/usage-examples/camera/move_camera_to-1-example.pas @@ -0,0 +1,74 @@ +program MoveCameraToExample; +uses + SplashKit; + +var + PlayerBmp: Bitmap; + Player: Sprite; + TargetX, TargetY: Double; + +begin + // Open a window + OpenWindow('Move Camera To Example', 800, 600); + + // Create a player bitmap and sprite + PlayerBmp := CreateBitmap('player', 40, 40); + ClearBitmap(PlayerBmp, ColorBrightGreen()); + Player := CreateSprite(PlayerBmp); + + // Position the player further out in the game world + SpriteSetX(Player, 1000); + SpriteSetY(Player, 1000); + + while not QuitRequested() do + begin + // Handle input to move the player + ProcessEvents(); + + if KeyDown(LeftKey) then SpriteSetX(Player, SpriteX(Player) - 5); + if KeyDown(RightKey) then SpriteSetX(Player, SpriteX(Player) + 5); + if KeyDown(UpKey) then SpriteSetY(Player, SpriteY(Player) - 5); + if KeyDown(DownKey) then SpriteSetY(Player, SpriteY(Player) + 5); + + // Center camera on player when SPACE is pressed + if KeyTyped(SpaceKey) then + begin + // Calculate the top-left position for the camera to center the player + TargetX := SpriteX(Player) + SpriteWidth(Player) / 2 - ScreenWidth() / 2; + TargetY := SpriteY(Player) + SpriteHeight(Player) / 2 - ScreenHeight() / 2; + + // Move the camera to the calculated point + MoveCameraTo(TargetX, TargetY); + end; + + // Reset camera to origin when M is pressed + if KeyTyped(MKey) then + begin + MoveCameraTo(0, 0); + end; + + // Clear the screen + ClearScreen(ColorBlack()); + + // Draw some world markers to visualize the camera move + FillRectangle(ColorWhite(), 0, 0, 20, 20); + DrawText('World (0,0)', ColorWhite(), 5, 25); + + FillRectangle(ColorRed(), 1000, 1000, 20, 20); + DrawText('World (1000,1000)', ColorRed(), 1000, 1025); + + // Draw the sprite (automatically uses camera offset) + DrawSprite(Player); + + // Draw HUD (Heads-Up Display) directly to the screen + FillRectangle(ColorDimGray(), 0, 0, 260, 80, OptionToScreen()); + DrawText('Camera Position: ' + PointToString(CameraPosition()), ColorWhite(), 10, 10, OptionToScreen()); + DrawText('Player World Pos: (' + FloatToStr(SpriteX(Player)) + ', ' + FloatToStr(SpriteY(Player)) + ')', ColorWhite(), 10, 30, OptionToScreen()); + DrawText('Press SPACE to center on player', ColorWhite(), 10, 50, OptionToScreen()); + DrawText('Press M to move camera to (0,0)', ColorWhite(), 10, 65, OptionToScreen()); + + RefreshScreen(60); + end; + + CloseAllWindows(); +end. diff --git a/public/usage-examples/camera/move_camera_to-1-example.png b/public/usage-examples/camera/move_camera_to-1-example.png new file mode 100644 index 000000000..c5202e892 Binary files /dev/null and b/public/usage-examples/camera/move_camera_to-1-example.png differ diff --git a/public/usage-examples/camera/move_camera_to-1-example.py b/public/usage-examples/camera/move_camera_to-1-example.py new file mode 100644 index 000000000..9cc83442f --- /dev/null +++ b/public/usage-examples/camera/move_camera_to-1-example.py @@ -0,0 +1,63 @@ +from splashkit import * + +# Open a window +open_window("Move Camera To Example", 800, 600) + +# Create a player bitmap and sprite +player_bmp = create_bitmap("player", 40, 40) +clear_bitmap(player_bmp, color_bright_green()) +player = create_sprite(player_bmp) + +# Position the player further out in the game world +sprite_set_x(player, 1000) +sprite_set_y(player, 1000) + +while not quit_requested(): + # Handle input to move the player + process_events() + + if key_down(KeyCode.left_key): + sprite_set_x(player, sprite_x(player) - 5) + if key_down(KeyCode.right_key): + sprite_set_x(player, sprite_x(player) + 5) + if key_down(KeyCode.up_key): + sprite_set_y(player, sprite_y(player) - 5) + if key_down(KeyCode.down_key): + sprite_set_y(player, sprite_y(player) + 5) + + # Center camera on player when SPACE is pressed + if key_typed(KeyCode.space_key): + # Calculate the top-left position for the camera to center the player + target_x = sprite_x(player) + sprite_width(player) / 2 - screen_width() / 2 + target_y = sprite_y(player) + sprite_height(player) / 2 - screen_height() / 2 + + # Move the camera to the calculated point + move_camera_to(target_x, target_y) + + # Reset camera to origin when M is pressed + if key_typed(KeyCode.m_key): + move_camera_to(0, 0) + + # Clear the screen + clear_screen(color_black()) + + # Draw some world markers to visualize the camera move + fill_rectangle(color_white(), 0, 0, 20, 20) + draw_text_no_font_no_size("World (0,0)", color_white(), 5, 25) + + fill_rectangle(color_red(), 1000, 1000, 20, 20) + draw_text_no_font_no_size("World (1000,1000)", color_red(), 1000, 1025) + + # Draw the sprite (automatically uses camera offset) + draw_sprite(player) + + # Draw HUD (Heads-Up Display) directly to the screen + fill_rectangle(color_dim_gray(), 0, 0, 260, 80, option_to_screen()) + draw_text_no_font_no_size_with_options(f"Camera Position: {point_to_string(camera_position())}", color_white(), 10, 10, option_to_screen()) + draw_text_no_font_no_size_with_options(f"Player World Pos: ({int(sprite_x(player))}, {int(sprite_y(player))})", color_white(), 10, 30, option_to_screen()) + draw_text_no_font_no_size_with_options("Press SPACE to center on player", color_white(), 10, 50, option_to_screen()) + draw_text_no_font_no_size_with_options("Press M to move camera to (0,0)", color_white(), 10, 65, option_to_screen()) + + refresh_screen_with_target_fps(60) + +close_all_windows() diff --git a/public/usage-examples/camera/move_camera_to-1-example.txt b/public/usage-examples/camera/move_camera_to-1-example.txt new file mode 100644 index 000000000..8987fbc0b --- /dev/null +++ b/public/usage-examples/camera/move_camera_to-1-example.txt @@ -0,0 +1 @@ +This example demonstrates how to move the camera to a specific point using SplashKit. The camera centers on a player sprite when the spacebar is pressed, showing the camera's position on screen. diff --git a/public/usage-examples/geometry/rectangle_around-1-example-oop.cs b/public/usage-examples/geometry/rectangle_around_circle-1-example-oop.cs similarity index 97% rename from public/usage-examples/geometry/rectangle_around-1-example-oop.cs rename to public/usage-examples/geometry/rectangle_around_circle-1-example-oop.cs index 91d32b902..299e99613 100644 --- a/public/usage-examples/geometry/rectangle_around-1-example-oop.cs +++ b/public/usage-examples/geometry/rectangle_around_circle-1-example-oop.cs @@ -1,59 +1,59 @@ -using SplashKitSDK; - -namespace RectangleAroundExample -{ - public class Program - { - public static void Main() - { - SplashKit.OpenWindow("Boring Screensaver", 800, 600); - - Circle circle; - int circleSize = 30; - float rotationDegrees = 0; - Point2D circleCoordinates; - bool growing = true; - SplashKitSDK.Timer mainTimer = SplashKit.CreateTimer("mainTimer"); - SplashKit.StartTimer(mainTimer); - SplashKitSDK.Timer reverseTimer = SplashKit.CreateTimer("reverseTimer"); - SplashKit.StartTimer(reverseTimer); - - while (!SplashKit.QuitRequested()) - { - rotationDegrees += 0.005f; - circleCoordinates = SplashKit.PointAt(300 + 150 * SplashKit.Cosine(rotationDegrees), 300 + 150 * SplashKit.Sine(rotationDegrees)); - circle = SplashKit.CircleAt(circleCoordinates, circleSize); - - if (SplashKit.TimerTicks(mainTimer) >= 40 && growing == true) - { - circleSize += 1; - SplashKit.ResetTimer(mainTimer); - } - else if (SplashKit.TimerTicks(reverseTimer) >= 3000) - { - growing = false; - } - - if (SplashKit.TimerTicks(mainTimer) >= 40 && growing == false) - { - circleSize -= 1; - SplashKit.ResetTimer(mainTimer); - } - else if (SplashKit.TimerTicks(reverseTimer) >= 6000) - { - growing = true; - SplashKit.ResetTimer(reverseTimer); - } - - SplashKit.ProcessEvents(); - - SplashKit.ClearScreen(Color.White); - // A rectangle is drawn which encompasses the circle. It shares the same height, width and position - SplashKit.DrawRectangle(Color.Black, SplashKit.RectangleAround(circle)); - SplashKit.FillCircle(Color.Red, circle); - SplashKit.RefreshScreen(); - } - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace RectangleAroundExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Boring Screensaver", 800, 600); + + Circle circle; + int circleSize = 30; + float rotationDegrees = 0; + Point2D circleCoordinates; + bool growing = true; + SplashKitSDK.Timer mainTimer = SplashKit.CreateTimer("mainTimer"); + SplashKit.StartTimer(mainTimer); + SplashKitSDK.Timer reverseTimer = SplashKit.CreateTimer("reverseTimer"); + SplashKit.StartTimer(reverseTimer); + + while (!SplashKit.QuitRequested()) + { + rotationDegrees += 0.005f; + circleCoordinates = SplashKit.PointAt(300 + 150 * SplashKit.Cosine(rotationDegrees), 300 + 150 * SplashKit.Sine(rotationDegrees)); + circle = SplashKit.CircleAt(circleCoordinates, circleSize); + + if (SplashKit.TimerTicks(mainTimer) >= 40 && growing == true) + { + circleSize += 1; + SplashKit.ResetTimer(mainTimer); + } + else if (SplashKit.TimerTicks(reverseTimer) >= 3000) + { + growing = false; + } + + if (SplashKit.TimerTicks(mainTimer) >= 40 && growing == false) + { + circleSize -= 1; + SplashKit.ResetTimer(mainTimer); + } + else if (SplashKit.TimerTicks(reverseTimer) >= 6000) + { + growing = true; + SplashKit.ResetTimer(reverseTimer); + } + + SplashKit.ProcessEvents(); + + SplashKit.ClearScreen(Color.White); + // A rectangle is drawn which encompasses the circle. It shares the same height, width and position + SplashKit.DrawRectangle(Color.Black, SplashKit.RectangleAround(circle)); + SplashKit.FillCircle(Color.Red, circle); + SplashKit.RefreshScreen(); + } + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/rectangle_around-1-example-top-level.cs b/public/usage-examples/geometry/rectangle_around_circle-1-example-top-level.cs similarity index 96% rename from public/usage-examples/geometry/rectangle_around-1-example-top-level.cs rename to public/usage-examples/geometry/rectangle_around_circle-1-example-top-level.cs index b2108bbcf..5ba524d77 100644 --- a/public/usage-examples/geometry/rectangle_around-1-example-top-level.cs +++ b/public/usage-examples/geometry/rectangle_around_circle-1-example-top-level.cs @@ -1,52 +1,52 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -OpenWindow("Boring Screensaver", 800, 600); - -Circle circle; -int circleSize = 30; -float rotationDegrees = 0; -Point2D circleCoordinates; -bool growing = true; -// SplashKitSDK.Timer needed to distinguish from System.Threading.Timer ↓ -SplashKitSDK.Timer mainTimer = CreateTimer("mainTimer"); -StartTimer(mainTimer); -SplashKitSDK.Timer reverseTimer = CreateTimer("reverseTimer"); -StartTimer(reverseTimer); - -while (!QuitRequested()) -{ - rotationDegrees += 0.005f; - circleCoordinates = PointAt(300 + 150 * Cosine(rotationDegrees), 300 + 150 * Sine(rotationDegrees)); - circle = CircleAt(circleCoordinates, circleSize); - - if (TimerTicks(mainTimer) >= 40 && growing == true) - { - circleSize += 1; - ResetTimer(mainTimer); - } - else if (TimerTicks(reverseTimer) >= 3000) - { - growing = false; - } - - if (TimerTicks(mainTimer) >= 40 && growing == false) - { - circleSize -= 1; - ResetTimer(mainTimer); - } - else if (TimerTicks(reverseTimer) >= 6000) - { - growing = true; - ResetTimer(reverseTimer); - } - - ProcessEvents(); - - ClearScreen(ColorWhite()); - // A rectangle is drawn which encompasses the circle. It shares the same height, width and position - DrawRectangle(ColorBlack(), RectangleAround(circle)); - FillCircle(ColorRed(), circle); - RefreshScreen(); -} +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +OpenWindow("Boring Screensaver", 800, 600); + +Circle circle; +int circleSize = 30; +float rotationDegrees = 0; +Point2D circleCoordinates; +bool growing = true; +// SplashKitSDK.Timer needed to distinguish from System.Threading.Timer ↓ +SplashKitSDK.Timer mainTimer = CreateTimer("mainTimer"); +StartTimer(mainTimer); +SplashKitSDK.Timer reverseTimer = CreateTimer("reverseTimer"); +StartTimer(reverseTimer); + +while (!QuitRequested()) +{ + rotationDegrees += 0.005f; + circleCoordinates = PointAt(300 + 150 * Cosine(rotationDegrees), 300 + 150 * Sine(rotationDegrees)); + circle = CircleAt(circleCoordinates, circleSize); + + if (TimerTicks(mainTimer) >= 40 && growing == true) + { + circleSize += 1; + ResetTimer(mainTimer); + } + else if (TimerTicks(reverseTimer) >= 3000) + { + growing = false; + } + + if (TimerTicks(mainTimer) >= 40 && growing == false) + { + circleSize -= 1; + ResetTimer(mainTimer); + } + else if (TimerTicks(reverseTimer) >= 6000) + { + growing = true; + ResetTimer(reverseTimer); + } + + ProcessEvents(); + + ClearScreen(ColorWhite()); + // A rectangle is drawn which encompasses the circle. It shares the same height, width and position + DrawRectangle(ColorBlack(), RectangleAround(circle)); + FillCircle(ColorRed(), circle); + RefreshScreen(); +} CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/geometry/rectangle_around-1-example.cpp b/public/usage-examples/geometry/rectangle_around_circle-1-example.cpp similarity index 96% rename from public/usage-examples/geometry/rectangle_around-1-example.cpp rename to public/usage-examples/geometry/rectangle_around_circle-1-example.cpp index 36a9f78ab..fd645634d 100644 --- a/public/usage-examples/geometry/rectangle_around-1-example.cpp +++ b/public/usage-examples/geometry/rectangle_around_circle-1-example.cpp @@ -1,54 +1,54 @@ -#include "splashkit.h" - -int main() -{ - open_window("Boring Screensaver", 800, 600); - - circle circle; - int circle_size = 30; - float rotation_degrees = 0; - point_2d circle_coordinates; - bool growing = true; - timer main_timer = create_timer("main_timer"); - start_timer(main_timer); - timer reverse_timer = create_timer("reverse_timer"); - start_timer(reverse_timer); - - while (!quit_requested()) - { - rotation_degrees += 0.005; - circle_coordinates = point_at((300 + 150 * cosine(rotation_degrees)), (300 + 150 * sine(rotation_degrees))); - circle = circle_at(circle_coordinates, circle_size); - - if (timer_ticks(main_timer) >= 40 && growing == true) - { - circle_size += 1; - reset_timer(main_timer); - } - else if (timer_ticks(reverse_timer) >= 3000) - { - growing = false; - } - - if (timer_ticks(main_timer) >= 40 && growing == false) - { - circle_size -= 1; - reset_timer(main_timer); - } - else if (timer_ticks(reverse_timer) >= 6000) - { - growing = true; - reset_timer(reverse_timer); - } - - process_events(); - - clear_screen(); - // A rectangle is drawn which encompasses the circle. It shares the same height, width and position - draw_rectangle(color_black(), rectangle_around(circle)); - fill_circle(color_red(), circle); - refresh_screen(); - } - close_all_windows(); - return 0; +#include "splashkit.h" + +int main() +{ + open_window("Boring Screensaver", 800, 600); + + circle circle; + int circle_size = 30; + float rotation_degrees = 0; + point_2d circle_coordinates; + bool growing = true; + timer main_timer = create_timer("main_timer"); + start_timer(main_timer); + timer reverse_timer = create_timer("reverse_timer"); + start_timer(reverse_timer); + + while (!quit_requested()) + { + rotation_degrees += 0.005; + circle_coordinates = point_at((300 + 150 * cosine(rotation_degrees)), (300 + 150 * sine(rotation_degrees))); + circle = circle_at(circle_coordinates, circle_size); + + if (timer_ticks(main_timer) >= 40 && growing == true) + { + circle_size += 1; + reset_timer(main_timer); + } + else if (timer_ticks(reverse_timer) >= 3000) + { + growing = false; + } + + if (timer_ticks(main_timer) >= 40 && growing == false) + { + circle_size -= 1; + reset_timer(main_timer); + } + else if (timer_ticks(reverse_timer) >= 6000) + { + growing = true; + reset_timer(reverse_timer); + } + + process_events(); + + clear_screen(); + // A rectangle is drawn which encompasses the circle. It shares the same height, width and position + draw_rectangle(color_black(), rectangle_around(circle)); + fill_circle(color_red(), circle); + refresh_screen(); + } + close_all_windows(); + return 0; } \ No newline at end of file diff --git a/public/usage-examples/geometry/rectangle_around-1-example.gif b/public/usage-examples/geometry/rectangle_around_circle-1-example.gif similarity index 100% rename from public/usage-examples/geometry/rectangle_around-1-example.gif rename to public/usage-examples/geometry/rectangle_around_circle-1-example.gif diff --git a/public/usage-examples/geometry/rectangle_around-1-example.py b/public/usage-examples/geometry/rectangle_around_circle-1-example.py similarity index 96% rename from public/usage-examples/geometry/rectangle_around-1-example.py rename to public/usage-examples/geometry/rectangle_around_circle-1-example.py index be32d3f31..1f7ba87aa 100644 --- a/public/usage-examples/geometry/rectangle_around-1-example.py +++ b/public/usage-examples/geometry/rectangle_around_circle-1-example.py @@ -1,41 +1,41 @@ -from splashkit import * - -open_window("Boring Screensaver", 800, 600) - -circle = Circle -circle_size = 30 -rotation_degrees = 0 -circle_coordinates = 0 -growing = True -main_timer = create_timer("main_timer") -start_timer(main_timer) -reverse_timer = create_timer("reverse_timer") -start_timer(reverse_timer) - -while (not quit_requested()): - rotation_degrees = rotation_degrees + 0.005 - circle_coordinates = point_at((300 + 150 * cosine(rotation_degrees)), (300 + 150 * sine(rotation_degrees))) - circle = circle_at(circle_coordinates, circle_size) - - if timer_ticks(main_timer) >= 40 and growing == True: - circle_size += 1 - reset_timer(main_timer) - elif timer_ticks(reverse_timer) >= 3000: - growing = False - - if timer_ticks(main_timer) >= 40 and growing == False: - circle_size -= 1 - reset_timer(main_timer) - elif timer_ticks(reverse_timer) >= 6000: - growing = True - reset_timer(reverse_timer) - - process_events() - - clear_screen_to_white() - # A rectangle is drawn which encompasses the circle. It shares the same height, width and position - draw_rectangle_record(color_black(), rectangle_around_circle(circle)) - fill_circle_record(color_red(), circle) - refresh_screen() - +from splashkit import * + +open_window("Boring Screensaver", 800, 600) + +circle = Circle +circle_size = 30 +rotation_degrees = 0 +circle_coordinates = 0 +growing = True +main_timer = create_timer("main_timer") +start_timer(main_timer) +reverse_timer = create_timer("reverse_timer") +start_timer(reverse_timer) + +while (not quit_requested()): + rotation_degrees = rotation_degrees + 0.005 + circle_coordinates = point_at((300 + 150 * cosine(rotation_degrees)), (300 + 150 * sine(rotation_degrees))) + circle = circle_at(circle_coordinates, circle_size) + + if timer_ticks(main_timer) >= 40 and growing == True: + circle_size += 1 + reset_timer(main_timer) + elif timer_ticks(reverse_timer) >= 3000: + growing = False + + if timer_ticks(main_timer) >= 40 and growing == False: + circle_size -= 1 + reset_timer(main_timer) + elif timer_ticks(reverse_timer) >= 6000: + growing = True + reset_timer(reverse_timer) + + process_events() + + clear_screen_to_white() + # A rectangle is drawn which encompasses the circle. It shares the same height, width and position + draw_rectangle_record(color_black(), rectangle_around_circle(circle)) + fill_circle_record(color_red(), circle) + refresh_screen() + close_all_windows() \ No newline at end of file diff --git a/public/usage-examples/geometry/rectangle_around-1-example.txt b/public/usage-examples/geometry/rectangle_around_circle-1-example.txt similarity index 100% rename from public/usage-examples/geometry/rectangle_around-1-example.txt rename to public/usage-examples/geometry/rectangle_around_circle-1-example.txt diff --git a/scripts/api-pages-script.cjs b/scripts/api-pages-script.cjs index 45dbc63fd..7efc34aac 100644 --- a/scripts/api-pages-script.cjs +++ b/scripts/api-pages-script.cjs @@ -317,6 +317,12 @@ function getGroupName(jsonData, uniqueName) { } }); } + + // Fallback to formatting the uniqueName if no match is found + if (funcGroupName == "") { + funcGroupName = uniqueName.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" "); + } + return funcGroupName; } @@ -667,13 +673,16 @@ for (const categoryKey in jsonData) { mdxContent += "\n\n"; - for (const names of functionNames) { + const uniqueFunctionNames = [...new Set(functionNames)]; + + for (const names of uniqueFunctionNames) { const normalName = names .split("_") .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join(" "); - const formattedLink = normalName.toLowerCase().replace(/\s+/g, "-"); - const link = `[\`${normalName}\`](/api/${input}/#${formattedLink})` + const isOverloadedInside = functionGroups[names].length > 1; + const formattedLinkInside = isOverloadedInside ? `${normalName.toLowerCase().replace(/\s+/g, "-")}-functions` : normalName.toLowerCase().replace(/\s+/g, "-"); + const link = `[\`${normalName}\`](/api/${input}/#${formattedLinkInside})` description = description.replace(new RegExp(`\`\\b${names}\\b\``, "g"), link); description = description.replaceAll("\n", " "); } @@ -704,13 +713,14 @@ for (const categoryKey in jsonData) { ); } - for (const names of functionNames) { + for (const names of uniqueFunctionNames) { const normalName = names .split("_") .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join(" "); - const formattedLink = normalName.toLowerCase().replace(/\s+/g, "-"); - const link = `[\`${normalName}\`](/api/${input}/#${formattedLink})` + const isOverloadedInside = functionGroups[names].length > 1; + const formattedLinkInside = isOverloadedInside ? `${normalName.toLowerCase().replace(/\s+/g, "-")}-functions` : normalName.toLowerCase().replace(/\s+/g, "-"); + const link = `[\`${normalName}\`](/api/${input}/#${formattedLinkInside})` description2 = description2.replace(new RegExp(`\`\\b${names}\\b\``, "g"), link); description2 = description2.replaceAll("\n", " "); } diff --git a/scripts/json-files/usage-example-references.json b/scripts/json-files/usage-example-references.json index c41688ec6..20c4fd872 100644 --- a/scripts/json-files/usage-example-references.json +++ b/scripts/json-files/usage-example-references.json @@ -524,6 +524,33 @@ "close_window" ] }, + { + "funcKey": "rectangle_around_circle", + "title": "A perpetually moving circle which increases and decreases in size, surrounded by a rectangle shape", + "url": "/api/geometry/#rectangle-around-functions", + "functions": [ + "open_window", + "point_at", + "cosine", + "sine", + "circle_at", + "create_timer", + "start_timer", + "quit_requested", + "timer_ticks", + "reset_timer", + "process_events", + "clear_screen", + "draw_rectangle", + "rectangle_around_circle", + "rectangle_around_line", + "rectangle_around_quad", + "rectangle_around_triangle", + "fill_circle", + "refresh_screen", + "close_all_windows" + ] + }, { "funcKey": "same_point", "title": "Point 2D Guessing Game",