Skip to content
Check out how to use the Geometry functions!

Geometry

Simple Usage Examples

Point At Origin

Red Dot At Origin

The following code shows an example of using Point At Origin to show the location of the origin point with a small red dot.

#include "splashkit.h"
int main()
{
open_window("Point At Origin", 800, 600);
// Create a point at origin
point_2d point = point_at_origin();
// Create red circle at the origin point
clear_screen();
fill_circle(COLOR_RED, point.x, point.y, 4);
refresh_screen();
delay(4000);
close_all_windows();
}

Output:

point_at_origin-1-simple example


Hot Summer Sun

The following code shows an example of using Point At Origin to create a “sun” at the origin point.

#include "splashkit.h"
int main()
{
open_window("Point At Origin", 800, 600);
// Create a point at origin
point_2d point = point_at_origin();
// Create "sun" at the origin point
clear_screen();
for (int i = 200; i > 10; i--)
{
fill_circle(rgb_color(255, i + 50, i % 30), point.x, point.y, i);
}
refresh_screen();
delay(4000);
close_all_windows();
}

Output:

point_at_origin-2-extended example


Point To String

Mouse Click Location

The following code shows examples of using Point To String to show the coordinates of a mouse click.

#include "splashkit.h"
int main()
{
string mouse_position_text = "Click to see coordinates...";
open_window("Mouse Clicked Location", 600, 600);
while (!quit_requested())
{
process_events();
// Check for mouse click
if (mouse_clicked(LEFT_BUTTON))
{
mouse_position_text = "Mouse clicked at " + point_to_string(mouse_position());
}
// Print mouse position to screen
clear_screen(COLOR_GHOST_WHITE);
draw_text(mouse_position_text, COLOR_BLACK, 100, 300);
refresh_screen();
}
close_all_windows();
return 0;
}

Output:

point_to_string-1-simple example