Functions
Returns the center point of the circle.
Parameters:
Name Type Description c Circle
The circle to get the center point
Return Type: Point 2d
Signatures:
point_2d center_point ( const circle & c )
public static Point2D SplashKit . CenterPoint (Circle c);
function CenterPoint ( const c: Circle): Point2D
Usage:
See Code Examples Example 1 : Glowing Circle
open_window ( " Glowing Blue Circle " , 600 , 600 );
int outer_circle_radius = 255 ;
// Create a circle in center of window
circle outer_circle = circle_at ( screen_center (), outer_circle_radius);
// Get center point of circle
point_2d circle_centre = center_point (outer_circle);
while ( ! quit_requested ())
clear_screen ( color_black ());
for ( int i = outer_circle_radius; i > 5 ; i -- )
fill_circle ( rgb_color ( 0 , 0 , 255 - i), circle_at (circle_centre, i));
using static SplashKitSDK . SplashKit;
OpenWindow ( " Glowing Blue Circle " , 600 , 600 );
int outer_circle_radius = 255 ;
// Create a circle in center of window
Circle outer_circle = CircleAt ( ScreenCenter (), outer_circle_radius);
// Get center point of circle
Point2D circle_centre = CenterPoint (outer_circle);
ClearScreen ( ColorBlack ());
for ( int i = outer_circle_radius; i > 5 ; i -- )
FillCircle ( RGBColor ( 0 , 0 , 255 - i), CircleAt (circle_centre, i));
namespace CenterPointExample
public static void Main ()
SplashKit . OpenWindow ( " Glowing Blue Circle " , 600 , 600 );
int outer_circle_radius = 255 ;
// Create a circle in center of window
Circle outer_circle = SplashKit . CircleAt ( SplashKit . ScreenCenter (), outer_circle_radius);
// Get center point of circle
Point2D circle_centre = SplashKit . CenterPoint (outer_circle);
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
SplashKit . ClearScreen ( Color . Black );
for ( int i = outer_circle_radius; i > 5 ; i -- )
SplashKit . FillCircle ( Color . RGBColor ( 0 , 0 , 255 - i), SplashKit . CircleAt (circle_centre, i));
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Glowing Blue Circle " , 600 , 600 )
outer_circle_radius = 255
# Create a circle in center of window
outer_circle = circle_at ( screen_center () , outer_circle_radius )
# Get center point of circle
circle_centre = center_point ( outer_circle )
while not quit_requested ():
clear_screen ( color_black ())
for i in range ( outer_circle_radius , 5 , - 1 ):
fill_circle_record ( rgb_color ( 0 , 0 , 255 - i ) , circle_at ( circle_centre , i ))
Output :
Returns a circle at the indicated point and radius.
Parameters:
Name Type Description pt Point 2d
The location of the center of the circle radius Double
The radius of the circle
Return Type: Circle
Signatures:
circle circle_at ( const point_2d & pt , double radius )
public static Circle SplashKit . CircleAt (Point2D pt, double radius);
def circle_at ( pt , radius ) :
function CircleAt ( const pt: Point2D; radius: Double ): Circle
Returns a circle at the indicated point and radius.
Parameters:
Name Type Description x Double
The x location of the circle y Double
The y location of the circle radius Double
The radius of the circle
Return Type: Circle
Signatures:
circle circle_at ( double x , double y , double radius )
public static Circle SplashKit . CircleAt ( double x, double y, double radius);
def circle_at_from_points ( x , y , radius ) :
function CircleAt (x: Double ; y: Double ; radius: Double ): Circle
Returns the circle radius.
Parameters:
Name Type Description c Circle
The circle
Return Type: Float
Signatures:
float circle_radius ( const circle c )
public static float SplashKit . CircleRadius (Circle c);
function CircleRadius (c: Circle): Single
Usage:
See Code Examples Example 1 : Using the Circle Radius
// Declare constants and variables
const int MAX_RADIUS = 250 ;
window window = open_window ( " Circle Radius " , 600 , 700 );
font arial = load_font ( " arial " , " arial.ttf " );
circle circle = circle_at ( screen_center (), 100 );
rectangle quadrant1 = rectangle_from ( circle_x (circle), circle_y (circle) - circle_radius (circle), circle_radius (circle) + 1 , circle_radius (circle) + 1 );
rectangle quadrant2 = rectangle_from ( circle_x (circle) - circle_radius (circle), circle_y (circle) - circle_radius (circle), circle_radius (circle) + 1 , circle_radius (circle) + 1 );
rectangle quadrant3 = rectangle_from ( circle_x (circle) - circle_radius (circle), circle_y (circle), circle_radius (circle) + 1 , circle_radius (circle) + 1 );
rectangle quadrant4 = rectangle_from ( circle_x (circle), circle_y (circle), circle_radius (circle) + 1 , circle_radius (circle) + 1 );
int quadrant_clicked = 0 ;
while ( ! window_close_requested (window))
// User input to change radius size
if ( key_down (UP_KEY) && circle_radius (circle) < MAX_RADIUS)
if ( key_down (DOWN_KEY) && circle_radius (circle) > 10 )
// Click left mouse button to remove quadrant of circle in mouse location
pt_pt_angle = point_point_angle ( screen_center (), mouse_position ());
if ( mouse_clicked (LEFT_BUTTON))
if (pt_pt_angle < 0 && pt_pt_angle >= - 90 )
if (pt_pt_angle < - 90 && pt_pt_angle >= - 180 )
if (pt_pt_angle < 180 && pt_pt_angle >= 90 )
if (pt_pt_angle < 90 && pt_pt_angle >= 0 )
// Press escape key to show whole circle
if ( key_typed (ESCAPE_KEY))
// Show/hide segment cut-out
clear_screen ( color_light_gray ());
clear_screen ( color_white ());
// Draw the Circle and segment cut-out if clicked
fill_circle ( color_orange (), circle);
switch (quadrant_clicked)
quadrant1 = rectangle_from ( circle_x (circle), circle_y (circle) - circle_radius (circle), circle_radius (circle) + 1 , circle_radius (circle) + 1 );
fill_rectangle ( color_white (), quadrant1);
quadrant2 = rectangle_from ( circle_x (circle) - circle_radius (circle), circle_y (circle) - circle_radius (circle), circle_radius (circle) + 1 , circle_radius (circle) + 1 );
fill_rectangle ( color_white (), quadrant2);
quadrant3 = rectangle_from ( circle_x (circle) - circle_radius (circle), circle_y (circle), circle_radius (circle) + 1 , circle_radius (circle) + 1 );
fill_rectangle ( color_white (), quadrant3);
quadrant4 = rectangle_from ( circle_x (circle), circle_y (circle), circle_radius (circle) + 1 , circle_radius (circle) + 1 );
fill_rectangle ( color_white (), quadrant4);
// Draw other shapes and instructions
draw_rectangle ( color_gray (), 50 , 100 , 500 , 500 );
draw_line ( color_gray (), screen_width () / 2 , 100 , screen_width () / 2 , 600 );
draw_line ( color_gray (), 50 , screen_height () / 2 , 550 , screen_height () / 2 );
draw_text ( " Instructions " , color_red (), arial, 16 , 50 , 10 );
draw_text ( " 1. Use the up/down arrow keys to change the radius of the circle. " , color_blue (), arial, 14 , 50 , 40 );
draw_text ( " 2. Click in a quadrant to remove the segment of the circle. Escape key to reset. " , color_blue (), arial, 14 , 50 , 65 );
draw_text ( " Psst! Hold Space bar to see how it works! " , color_blue (), arial, 12 , 50 , 630 );
draw_text ( " Circle Radius: " + std:: to_string (( int ) circle_radius (circle)), color_green (), arial, 24 , 320 , 620 );
using static SplashKitSDK . SplashKit;
// Declare constants and variables
const int MAX_RADIUS = 250 ;
Window window = OpenWindow ( " Circle Radius " , 600 , 700 );
Font arial = LoadFont ( " arial " , " arial.ttf " );
Circle circle = CircleAt ( ScreenCenter (), 100 );
Rectangle quadrant1 = RectangleFrom ( CircleX (circle), CircleY (circle) - CircleRadius (circle), CircleRadius (circle) + 1 , CircleRadius (circle) + 1 );
Rectangle quadrant2 = RectangleFrom ( CircleX (circle) - CircleRadius (circle), CircleY (circle) - CircleRadius (circle), CircleRadius (circle) + 1 , CircleRadius (circle) + 1 );
Rectangle quadrant3 = RectangleFrom ( CircleX (circle) - CircleRadius (circle), CircleY (circle), CircleRadius (circle) + 1 , CircleRadius (circle) + 1 );
Rectangle quadrant4 = RectangleFrom ( CircleX (circle), CircleY (circle), CircleRadius (circle) + 1 , CircleRadius (circle) + 1 );
while ( ! WindowCloseRequested (window))
// User input to change radius size
if ( KeyDown ( KeyCode . UpKey ) && CircleRadius (circle) < MAX_RADIUS)
if ( KeyDown ( KeyCode . DownKey ) && CircleRadius (circle) > 10 )
// Click left mouse button to remove quadrant of circle in mouse location
ptPtAngle = PointPointAngle ( ScreenCenter (), MousePosition ());
if ( MouseClicked ( MouseButton . LeftButton ))
if (ptPtAngle < 0 && ptPtAngle >= - 90 )
if (ptPtAngle < - 90 && ptPtAngle >= - 180 )
if (ptPtAngle < 180 && ptPtAngle >= 90 )
if (ptPtAngle < 90 && ptPtAngle >= 0 )
// Press escape key to show whole circle
if ( KeyTyped ( KeyCode . EscapeKey ))
// Show/hide segment cut-out
if ( KeyDown ( KeyCode . SpaceKey ))
ClearScreen ( ColorLightGray ());
ClearScreen ( ColorWhite ());
// Draw the Circle and segment cut-out if clicked
FillCircle ( ColorOrange (), circle);
quadrant1 = RectangleFrom ( CircleX (circle), CircleY (circle) - CircleRadius (circle), CircleRadius (circle) + 1 , CircleRadius (circle) + 1 );
FillRectangle ( ColorWhite (), quadrant1);
quadrant2 = RectangleFrom ( CircleX (circle) - CircleRadius (circle), CircleY (circle) - CircleRadius (circle), CircleRadius (circle) + 1 , CircleRadius (circle) + 1 );
FillRectangle ( ColorWhite (), quadrant2);
quadrant3 = RectangleFrom ( CircleX (circle) - CircleRadius (circle), CircleY (circle), CircleRadius (circle) + 1 , CircleRadius (circle) + 1 );
FillRectangle ( ColorWhite (), quadrant3);
quadrant4 = RectangleFrom ( CircleX (circle), CircleY (circle), CircleRadius (circle) + 1 , CircleRadius (circle) + 1 );
FillRectangle ( ColorWhite (), quadrant4);
// Draw other shapes and instructions
DrawRectangle ( ColorGray (), 50 , 100 , 500 , 500 );
DrawLine ( ColorGray (), ScreenWidth () / 2 , 100 , ScreenWidth () / 2 , 600 );
DrawLine ( ColorGray (), 50 , ScreenHeight () / 2 , 550 , ScreenHeight () / 2 );
DrawText ( " Instructions " , ColorRed (), arial, 16 , 50 , 10 );
DrawText ( " 1. Use the up/down arrow keys to change the radius of the circle. " , ColorBlue (), arial, 14 , 50 , 40 );
DrawText ( " 2. Click in a quadrant to remove the segment of the circle. Escape key to reset. " , ColorBlue (), arial, 14 , 50 , 65 );
DrawText ( " Psst! Hold Space bar to see how it works! " , ColorBlue (), arial, 12 , 50 , 630 );
DrawText ( $" Circle Radius: { CircleRadius ( circle )} " , ColorGreen (), arial, 24 , 320 , 620 );
namespace CircleRadiusExample
public static void Main ()
// Declare constants and variables
const int MAX_RADIUS = 250 ;
Window window = new Window( " Circle Radius " , 600 , 700 );
Font arial = new Font( " arial " , " arial.ttf " );
Circle circle = SplashKit . CircleAt ( SplashKit . ScreenCenter (), 100 );
Rectangle quadrant1 = SplashKit . RectangleFrom ( circle . Center . X , circle . Center . Y - circle . Radius , circle . Radius + 1 , circle . Radius + 1 );
Rectangle quadrant2 = SplashKit . RectangleFrom ( circle . Center . X - circle . Radius , circle . Center . Y - circle . Radius , circle . Radius + 1 , circle . Radius + 1 );
Rectangle quadrant3 = SplashKit . RectangleFrom ( circle . Center . X - circle . Radius , circle . Center . Y , circle . Radius + 1 , circle . Radius + 1 );
Rectangle quadrant4 = SplashKit . RectangleFrom ( circle . Center . X , circle . Center . Y , circle . Radius + 1 , circle . Radius + 1 );
while ( ! window . CloseRequested )
SplashKit . ProcessEvents ();
// User input to change radius size
if ( SplashKit . KeyDown ( KeyCode . UpKey ) && SplashKit . CircleRadius (circle) < MAX_RADIUS)
if ( SplashKit . KeyDown ( KeyCode . DownKey ) && SplashKit . CircleRadius (circle) > 10 )
// Click left mouse button to remove quadrant of circle in mouse location
ptPtAngle = SplashKit . PointPointAngle ( SplashKit . ScreenCenter (), SplashKit . MousePosition ());
if ( SplashKit . MouseClicked ( MouseButton . LeftButton ))
if (ptPtAngle < 0 && ptPtAngle >= - 90 )
if (ptPtAngle < - 90 && ptPtAngle >= - 180 )
if (ptPtAngle < 180 && ptPtAngle >= 90 )
if (ptPtAngle < 90 && ptPtAngle >= 0 )
// Press escape key to show whole circle
if ( SplashKit . KeyTyped ( KeyCode . EscapeKey ))
// Show/hide segment cut-out
if ( SplashKit . KeyDown ( KeyCode . SpaceKey ))
SplashKit . ClearScreen ( Color . LightGray );
SplashKit . ClearScreen ( Color . White );
// Draw the Circle and segment cut-out if clicked
SplashKit . FillCircle ( Color . Orange , circle);
quadrant1 = SplashKit . RectangleFrom ( circle . Center . X , circle . Center . Y - circle . Radius , circle . Radius + 1 , circle . Radius + 1 );
SplashKit . FillRectangle ( Color . White , quadrant1);
quadrant2 = SplashKit . RectangleFrom ( circle . Center . X - circle . Radius , circle . Center . Y - circle . Radius , circle . Radius + 1 , circle . Radius + 1 );
SplashKit . FillRectangle ( Color . White , quadrant2);
quadrant3 = SplashKit . RectangleFrom ( circle . Center . X - circle . Radius , circle . Center . Y , circle . Radius + 1 , circle . Radius + 1 );
SplashKit . FillRectangle ( Color . White , quadrant3);
quadrant4 = SplashKit . RectangleFrom ( circle . Center . X , circle . Center . Y , circle . Radius + 1 , circle . Radius + 1 );
SplashKit . FillRectangle ( Color . White , quadrant4);
// Draw other shapes and instructions
SplashKit . DrawRectangle ( Color . Gray , 50 , 100 , 500 , 500 );
SplashKit . DrawLine ( Color . Gray , SplashKit . ScreenWidth () / 2 , 100 , SplashKit . ScreenWidth () / 2 , 600 );
SplashKit . DrawLine ( Color . Gray , 50 , SplashKit . ScreenHeight () / 2 , 550 , SplashKit . ScreenHeight () / 2 );
SplashKit . DrawText ( " Instructions " , Color . Red , arial, 16 , 50 , 10 );
SplashKit . DrawText ( " 1. Use the up/down arrow keys to change the radius of the circle. " , Color . Blue , arial, 14 , 50 , 40 );
SplashKit . DrawText ( " 2. Click in a quadrant to remove the segment of the circle. Escape key to reset. " , Color . Blue , arial, 14 , 50 , 65 );
SplashKit . DrawText ( " Psst! Hold Space bar to see how it works! " , Color . Blue , arial, 12 , 50 , 630 );
SplashKit . DrawText ( $" Circle Radius: { circle . Radius } " , Color . Green , arial, 24 , 320 , 620 );
SplashKit . RefreshScreen ( 60 );
# Declare constants and variables
window = open_window ( " Circle Radius " , 600 , 700 )
arial = load_font ( " arial " , " arial.ttf " )
circle = circle_at ( screen_center () , 100 )
quadrant1 = rectangle_from ( circle_x ( circle ) , circle_y ( circle ) - circle_radius ( circle ) , circle_radius ( circle ) + 1 , circle_radius ( circle ) + 1 )
quadrant2 = rectangle_from ( circle_x ( circle ) - circle_radius ( circle ) , circle_y ( circle ) - circle_radius ( circle ) , circle_radius ( circle ) + 1 , circle_radius ( circle ) + 1 )
quadrant3 = rectangle_from ( circle_x ( circle ) - circle_radius ( circle ) , circle_y ( circle ) , circle_radius ( circle ) + 1 , circle_radius ( circle ) + 1 )
quadrant4 = rectangle_from ( circle_x ( circle ) , circle_y ( circle ) , circle_radius ( circle ) + 1 , circle_radius ( circle ) + 1 )
while ( not window_close_requested ( window )):
# User input to change radius size
if ( key_down ( KeyCode.up_key ) and circle_radius ( circle ) < MAX_RADIUS ):
if ( key_down ( KeyCode.down_key ) and circle_radius ( circle ) > 10 ):
# Click left mouse button to remove quadrant of circle in mouse location
pt_pt_angle = point_point_angle ( screen_center () , mouse_position ())
if ( mouse_clicked ( MouseButton.left_button )):
if (pt_pt_angle < 0 and pt_pt_angle >= - 90 ):
if (pt_pt_angle < - 90 and pt_pt_angle >= - 180 ):
if (pt_pt_angle < 180 and pt_pt_angle >= 90 ):
if (pt_pt_angle < 90 and pt_pt_angle >= 0 ):
# Press escape key to show whole circle
if ( key_typed ( KeyCode.escape_key )):
# Show/hide segment cut-out
if ( key_down ( KeyCode.space_key )):
clear_screen ( color_light_gray ())
clear_screen ( color_white ())
# Draw the Circle and segment cut-out if clicked
fill_circle_record ( color_orange () , circle )
match (quadrant_clicked):
quadrant1 = rectangle_from ( circle_x ( circle ) , circle_y ( circle ) - circle_radius ( circle ) , circle_radius ( circle ) + 1 , circle_radius ( circle ) + 1 )
fill_rectangle_record ( color_white () , quadrant1 )
quadrant2 = rectangle_from ( circle_x ( circle ) - circle_radius ( circle ) , circle_y ( circle ) - circle_radius ( circle ) , circle_radius ( circle ) + 1 , circle_radius ( circle ) + 1 )
fill_rectangle_record ( color_white () , quadrant2 )
quadrant3 = rectangle_from ( circle_x ( circle ) - circle_radius ( circle ) , circle_y ( circle ) , circle_radius ( circle ) + 1 , circle_radius ( circle ) + 1 )
fill_rectangle_record ( color_white () , quadrant3 )
quadrant4 = rectangle_from ( circle_x ( circle ) , circle_y ( circle ) , circle_radius ( circle ) + 1 , circle_radius ( circle ) + 1 )
fill_rectangle_record ( color_white () , quadrant4 )
# Draw other shapes and instructions
draw_rectangle ( color_gray () , 50 , 100 , 500 , 500 )
draw_line ( color_gray () , screen_width () / 2 , 100 , screen_width () / 2 , 600 )
draw_line ( color_gray () , 50 , screen_height () / 2 , 550 , screen_height () / 2 )
draw_text ( " Instructions " , color_red () , arial , 16 , 50 , 10 )
draw_text ( " 1. Use the up/down arrow keys to change the radius of the circle. " , color_blue () , arial , 14 , 50 , 40 )
draw_text ( " 2. Click in a quadrant to remove the segment of the circle. Escape key to reset. " , color_blue () , arial , 14 , 50 , 65 )
draw_text ( " Psst! Hold Space bar to see how it works! " , color_blue () , arial , 12 , 50 , 630 )
draw_text ( " Circle Radius: " + str ( int ( circle_radius ( circle ))) , color_green () , arial , 24 , 320 , 620 )
refresh_screen_with_target_fps ( 60 )
Output :
Detects if a circle intersects with a triangle.
Parameters:
Name Type Description c Circle
The circle to test tri Triangle
The triangle to test
Return Type: Boolean
Signatures:
bool circle_triangle_intersect ( const circle & c , const triangle & tri )
public static bool SplashKit . CircleTriangleIntersect (Circle c, Triangle tri);
def circle_triangle_intersect ( c , tri ) :
function CircleTriangleIntersect ( const c: Circle; const tri: Triangle): Boolean
Detects if a circle intersects with a triangle. The closest point on the triangle to the circle is assigned to p, even if the circle and triangle do not intersect. If the centre of the circle is inside the triangle, the point assigned to p is the centre of the circle.
Parameters:
Name Type Description c Circle
The circle to test tri Triangle
The triangle to test p Point 2d
The point to set to the closest point on the triangle to the circle
Return Type: Boolean
Signatures:
bool circle_triangle_intersect ( const circle & c , const triangle & tri , point_2d & p )
public static bool SplashKit . CircleTriangleIntersect (Circle c, Triangle tri, ref Point2D p);
def circle_triangle_intersect_get_closest_point ( c , tri , p ) :
function CircleTriangleIntersect ( const c: Circle; const tri: Triangle; var p: Point2D): Boolean
Returns the circle x value.
Parameters:
Name Type Description c Circle
The circle
Return Type: Float
Signatures:
float circle_x ( const circle & c )
public static float SplashKit . CircleX (Circle c);
function CircleX ( const c: Circle): Single
Usage:
See Code Examples Example 1 : X-coordinate in middle of Circle
// Create a circle (with random x position value bewteen 200 - 600)
circle circle = circle_at ( rnd ( 400 ) + 200 , 300 , 200 );
open_window ( " Circle X " , 800 , 600 );
// Draw the Circle and x coordinate on window
clear_screen ( color_white ());
draw_circle (COLOR_RED, circle);
draw_text ( " Circle X: " + std:: to_string ( circle_x (circle)), COLOR_BLACK, 100 , 100 );
using static SplashKitSDK . SplashKit;
// Create a circle (with random x position value bewteen 200 - 600)
Circle circle = CircleAt ( Rnd ( 400 ) + 200 , 300 , 200 );
OpenWindow ( " Circle X " , 800 , 600 );
// Draw the Circle and x coordinate on window
ClearScreen ( ColorWhite ());
DrawCircle ( ColorRed (), circle);
DrawText ( $" Circle X: { CircleX ( circle )} " , ColorBlack (), 100 , 100 );
public static void Main ()
// Create a circle (with random x position value bewteen 200 - 600)
Circle circle = SplashKit . CircleAt ( SplashKit . Rnd ( 400 ) + 200 , 300 , 200 );
Window window = new Window( " Circle X " , 800 , 600 );
// Draw the Circle and x coordinate on window
window . Clear ( Color . White );
SplashKit . DrawCircle ( Color . Red , circle);
SplashKit . DrawText ( $" Circle X: { SplashKit . CircleX ( circle )} " , Color . Black , 100 , 100 );
# Create a circle (with random x position value bewteen 200 - 600)
circle = circle_at_from_points ( rnd_int ( 400 ) + 200 , 300 , 200 )
open_window ( " Circle X " , 800 , 600 )
# Draw the circle and x coordinate on window
clear_screen ( color_white ())
draw_circle_record ( color_red () , circle )
draw_text_no_font_no_size ( f "Circle X: { circle_x ( circle ) } " , color_black () , 100 , 100 )
Output :
Returns the circle y value.
Parameters:
Name Type Description c Circle
The circle
Return Type: Float
Signatures:
float circle_y ( const circle & c )
public static float SplashKit . CircleY (Circle c);
function CircleY ( const c: Circle): Single
Usage:
See Code Examples Example 1 : Using the Circle Y-coordinate
// Create a circle (with random y position value between 200 - 400)
circle circle = circle_at ( 400 , rnd ( 200 ) + 200 , 200 );
open_window ( " Circle Y " , 800 , 600 );
// Draw the Circle and y coordinate on window
clear_screen ( color_white ());
draw_circle (COLOR_RED, circle);
draw_text ( " Circle Y: " + std:: to_string ( circle_y (circle)), COLOR_BLACK, 100 , 100 );
// Draw a line to show the circle Y coordinate
draw_line (COLOR_BLACK, 0 , circle_y (circle), screen_width (), circle_y (circle));
// Draw 10 circles with radius of 50 and the same circle y coordinate
for ( int i = 0 ; i < 10 ; i ++ )
draw_circle (COLOR_BLUE, i * 60 + 100 , circle_y (circle), 50 );
using static SplashKitSDK . SplashKit;
// Create a circle (with random y position value between 200 - 400)
Circle circle = CircleAt ( 400 , Rnd ( 200 ) + 200 , 200 );
OpenWindow ( " Circle Y " , 800 , 600 );
// Draw the Circle and y coordinate on window
ClearScreen ( ColorWhite ());
DrawCircle ( ColorRed (), circle);
DrawText ( " Circle Y: " + CircleY (circle), ColorBlack (), 100 , 100 );
// Draw a line to show the circle Y coordinate
DrawLine ( ColorBlack (), 0 , CircleY (circle), ScreenWidth (), CircleY (circle));
// Draw 10 circles with radius of 50 and the same circle y coordinate
for ( int i = 0 ; i < 10 ; i ++ )
DrawCircle ( ColorBlue (), i * 60 + 100 , CircleY (circle), 50 );
public static void Main ()
// Create a circle (with random y position value between 200 - 400)
Circle circle = SplashKit . CircleAt ( 400 , SplashKit . Rnd ( 200 ) + 200 , 200 );
Window window = new Window( " Circle Y " , 800 , 600 );
// Draw the Circle and y coordinate on window
window . Clear ( Color . White );
SplashKit . DrawCircle ( Color . Red , circle);
SplashKit . DrawText ( " Circle Y: " + SplashKit . CircleY (circle), Color . Black , 100 , 100 );
// Draw a line to show the circle Y coordinate
SplashKit . DrawLine ( Color . Black , 0 , SplashKit . CircleY (circle), SplashKit . ScreenWidth (), SplashKit . CircleY (circle));
// Draw 10 circles with radius of 50 and the same circle y coordinate
for ( int i = 0 ; i < 10 ; i ++ )
SplashKit . DrawCircle ( Color . Blue , i * 60 + 100 , SplashKit . CircleY (circle), 50 );
# Create a circle (with random y position value between 200 - 400)
circle = circle_at_from_points ( 400 , rnd_int ( 200 ) + 200 , 200 )
open_window ( " Circle Y " , 800 , 600 )
# Draw the circle and y coordinate on window
clear_screen ( color_white ())
draw_circle_record ( color_red () , circle )
draw_text_no_font_no_size ( " Circle Y: " + str ( circle_y ( circle )) , color_black () , 100 , 100 )
# Draw a line to show the circle Y coordinate
draw_line ( color_black () , 0 , circle_y ( circle ) , screen_width () , circle_y ( circle ))
# Draw 10 circles with radius of 50 and the same circle y coordinate
draw_circle ( color_blue () , i * 60 + 100 , circle_y ( circle ) , 50 )
Output :
Detects if two circles intersect. This can be used to detect collisions between bounding circles.
Parameters:
Name Type Description c1 Circle
The circle to test if intersects with c2 c2 Circle
The circle to test if intersects with c1
Return Type: Boolean
Signatures:
bool circles_intersect (circle c1 , circle c2 )
public static bool SplashKit . CirclesIntersect (Circle c1, Circle c2);
def circles_intersect ( c1 , c2 ) :
function CirclesIntersect (c1: Circle; c2: Circle): Boolean
Detects if two circles intersect. This can be used to detect collisions between bounding circles. The circle data is passed in as individual values.
Parameters:
Name Type Description c1_x Double
the x location of the first circle c1_y Double
the y location of the first circle c1_radius Double
the radius of the first circle c2_x Double
the x location of the second circle c2_y Double
the y location of the second circle c2_radius Double
the radius of the second circle
Return Type: Boolean
Signatures:
bool circles_intersect ( double c1_x , double c1_y , double c1_radius , double c2_x , double c2_y , double c2_radius )
public static bool SplashKit . CirclesIntersect ( double c1X, double c1Y, double c1Radius, double c2X, double c2Y, double c2Radius);
def circles_intersect_using_values ( c1_x , c1_y , c1_radius , c2_x , c2_y , c2_radius ) :
function CirclesIntersect (c1X: Double ; c1Y: Double ; c1Radius: Double ; c2X: Double ; c2Y: Double ; c2Radius: Double ): Boolean
The closest point on the circle to the given point.
Parameters:
Name Type Description from_pt Point 2d
The point to test from c Circle
The circle you want to get a point on its circumference
Return Type: Point 2d
Signatures:
point_2d closest_point_on_circle ( const point_2d & from_pt , const circle & c )
public static Point2D SplashKit . ClosestPointOnCircle (Point2D fromPt, Circle c);
def closest_point_on_circle ( from_pt , c ) :
function ClosestPointOnCircle ( const fromPt: Point2D; const c: Circle): Point2D
Usage:
See Code Examples Example 1 : Closest Point to Mouse on Circle
Note: The blue dot represents the “Mouse” point.
open_window ( " Closest point " , 600 , 600 );
point_2d circle_pt = screen_center ();
circle circle = circle_at (circle_pt, 100 );
point_2d mouse_pt = mouse_position ();
while ( ! quit_requested ())
// Get "current" Mouse Position
mouse_pt = mouse_position ();
// Calculate the closest distance between the current mouse position and the circle
closest_point = closest_point_on_circle (mouse_pt, circle);
// Draw circle and indicated points
draw_circle (COLOR_BLACK, circle);
fill_circle (COLOR_BLUE, mouse_pt . x , mouse_pt . y , 5 );
fill_circle (COLOR_RED, closest_point . x , closest_point . y , 5 );
using static SplashKitSDK . SplashKit;
OpenWindow ( " Closest point " , 600 , 600 );
Point2D circle_pt = ScreenCenter ();
Circle circle = CircleAt (circle_pt, 100 );
Point2D mouse_pt = MousePosition ();
// Get "current" Mouse Position
mouse_pt = MousePosition ();
// Calculate the closest distance between the current mouse position and the circle
closest_point = ClosestPointOnCircle (mouse_pt, circle);
// Draw circle and indicated points
DrawCircle ( ColorBlack (), circle);
FillCircle ( ColorRed (), closest_point . X , closest_point . Y , 5 );
FillCircle ( ColorBlue (), mouse_pt . X , mouse_pt . Y , 5 );
namespace ClosestPointOnCircleExample
public static void Main ()
SplashKit . OpenWindow ( " Closest point " , 600 , 600 );
Point2D circle_pt = ScreenCenter ();
Circle circle = SplashKit . CircleAt (circle_pt, 100 );
Point2D mouse_pt = SplashKit . MousePosition ();
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
// Get "current" Mouse Position
mouse_pt = SplashKit . MousePosition ();
// Calculate the closest distance between the current mouse position and the circle
closest_point = SplashKit . ClosestPointOnCircle (mouse_pt, circle);
// Draw circle and indicated points
SplashKit . DrawCircle ( Color . Black , circle);
SplashKit . FillCircle ( Color . Red , closest_point . X , closest_point . Y , 5 );
SplashKit . FillCircle ( Color . Blue , mouse_pt . X , mouse_pt . Y , 5 );
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Closest point " , 600 , 600 )
circle_pt = screen_center ()
circle = circle_at ( circle_pt , 100 )
mouse_pt = mouse_position ()
while ( not quit_requested ()):
# Get "current" Mouse Position
mouse_pt = mouse_position ()
# Calculate the closest distance between the current mouse position and the circle
closest_point = closest_point_on_circle ( mouse_pt , circle )
# Draw circle and indicated points
draw_circle_record ( color_black () , circle )
fill_circle ( color_blue () , mouse_pt.x , mouse_pt.y , 5 )
fill_circle ( color_red () , closest_point.x , closest_point.y , 5 )
Output :
Returns the closest point on a line to a circle.
Parameters:
Return Type: Point 2d
Signatures:
point_2d closest_point_on_line_from_circle ( const circle & c , const line & l )
public static Point2D SplashKit . ClosestPointOnLineFromCircle (Circle c, Line l);
def closest_point_on_line_from_circle ( c , l ) :
function ClosestPointOnLineFromCircle ( const c: Circle; const l: Line): Point2D
Returns the closest point on a rectangle to a circle.
Parameters:
Return Type: Point 2d
Signatures:
point_2d closest_point_on_rect_from_circle ( const circle & c , const rectangle & rect )
public static Point2D SplashKit . ClosestPointOnRectFromCircle (Circle c, Rectangle rect);
def closest_point_on_rect_from_circle ( c , rect ) :
function ClosestPointOnRectFromCircle ( const c: Circle; const rect: Rectangle): Point2D
Calculates the closest point on a triangle to a circle. If the circle and triangle do not intersect, the closest point on the triangle to the circle is returned. If the circle and triangle do intersect, the center of the circle is returned.
Parameters:
Name Type Description c Circle
The circle to test tri Triangle
The triangle to test
Return Type: Point 2d
Signatures:
point_2d closest_point_on_triangle_from_circle ( const circle & c , const triangle & tri )
public static Point2D SplashKit . ClosestPointOnTriangleFromCircle (Circle c, Triangle tri);
def closest_point_on_triangle_from_circle ( c , tri ) :
function ClosestPointOnTriangleFromCircle ( const c: Circle; const tri: Triangle): Point2D
The furthest point on the circle to the given point.
Parameters:
Name Type Description pt Point 2d
The point to test from c Circle
The circle you want to get a point on its circumference
Return Type: Point 2d
Signatures:
point_2d distant_point_on_circle ( const point_2d & pt , const circle & c )
public static Point2D SplashKit . DistantPointOnCircle (Point2D pt, Circle c);
def distant_point_on_circle ( pt , c ) :
function DistantPointOnCircle ( const pt: Point2D; const c: Circle): Point2D
Determines the opposite side of a circle given a collision point and a heading.
Parameters:
Name Type Description pt Point 2d
The point from which the test is being made c Circle
The circle heading Vector 2d
The direction the point is heading opposite_pt Point 2d
After the call, this is set to the point on the opposite side of the circle from pt when it is heading in the given direction.
Return Type: Boolean
Signatures:
bool distant_point_on_circle_heading ( const point_2d & pt , const circle & c , const vector_2d & heading , point_2d & opposite_pt )
public static bool SplashKit . DistantPointOnCircleHeading (Point2D pt, Circle c, Vector2D heading, ref Point2D oppositePt);
def distant_point_on_circle_heading ( pt , c , heading , opposite_pt ) :
function DistantPointOnCircleHeading ( const pt: Point2D; const c: Circle; const heading: Vector2D; var oppositePt: Point2D): Boolean
Calculates the distance from a ray cast from a point to a given circle.
Parameters:
Name Type Description ray_origin Point 2d
The origin of the ray ray_heading Vector 2d
The direction of the ray c Circle
The circle being tested
Return Type: Float
Signatures:
float ray_circle_intersect_distance ( const point_2d & ray_origin , const vector_2d & ray_heading , const circle & c )
public static float SplashKit . RayCircleIntersectDistance (Point2D rayOrigin, Vector2D rayHeading, Circle c);
def ray_circle_intersect_distance ( ray_origin , ray_heading , c ) :
function RayCircleIntersectDistance ( const rayOrigin: Point2D; const rayHeading: Vector2D; const c: Circle): Single
Returns the two tangent points on the circle given the indicated point.
Parameters:
Name Type Description from_pt Point 2d
The source point c Circle
The circle p1 Point 2d
If this returns true, then p1
contains one of the points p2 Point 2d
If this returns true, then p2
contains one of the points
Return Type: Boolean
Signatures:
bool tangent_points ( const point_2d & from_pt , const circle & c , point_2d & p1 , point_2d & p2 )
public static bool SplashKit . TangentPoints (Point2D fromPt, Circle c, ref Point2D p1, ref Point2D p2);
def tangent_points ( from_pt , c , p1 , p2 ) :
function TangentPoints ( const fromPt: Point2D; const c: Circle; var p1: Point2D; var p2: Point2D): Boolean
Calculates the two points on a circles radius that lie along the given vector. This represents the points on the circle when the vector is placed at the circle’s center point.
Parameters:
Name Type Description c Circle
The circle along Vector 2d
The vector representing the line along which the points lie. pt1 Point 2d
After the call, this is set to one of the widest points pt2 Point 2d
After the call, this is set to one of the widest points
Signatures:
void widest_points ( const circle & c , const vector_2d & along , point_2d & pt1 , point_2d & pt2 )
public static void SplashKit . WidestPoints (Circle c, Vector2D along, ref Point2D pt1, ref Point2D pt2);
def widest_points ( c , along , pt1 , pt2 ) :
procedure WidestPoints ( const c: Circle; const along: Vector2D; var pt1: Point2D; var pt2: Point2D)
Returns the cosine of the supplied angle (in degrees).
Parameters:
Name Type Description degrees Float
The angle in degrees
Return Type: Float
Signatures:
float cosine ( float degrees )
public static float SplashKit . Cosine ( float degrees);
function Cosine (degrees: Single ): Single
Returns the sine of the supplied angle (in degrees).
Parameters:
Name Type Description degrees Float
The angle in degrees
Return Type: Float
Signatures:
float sine ( float degrees )
public static float SplashKit . Sine ( float degrees);
function Sine (degrees: Single ): Single
Returns the tangent of the supplied angle (in degrees).
Parameters:
Name Type Description degrees Float
The angle in degrees
Return Type: Float
Signatures:
float tangent ( float degrees )
public static float SplashKit . Tangent ( float degrees);
function Tangent (degrees: Single ): Single
Gets the closest point on the line to a given point.
Parameters:
Name Type Description from_pt Point 2d
The point to test (usually somewhere near the line) l Line
The line
Return Type: Point 2d
Signatures:
point_2d closest_point_on_line ( const point_2d from_pt , const line & l )
public static Point2D SplashKit . ClosestPointOnLine (Point2D fromPt, Line l);
def closest_point_on_line ( from_pt , l ) :
function ClosestPointOnLine (fromPt: Point2D; const l: Line): Point2D
Get the point closest to from pt
that is on one of the supplied lines.
Parameters:
Name Type Description from_pt Point 2d
The point to test lines Vector
The lines to check line_idx Integer
After the call this will store the index of the line that had the matching point.
Return Type: Point 2d
Signatures:
point_2d closest_point_on_lines ( const point_2d from_pt , const vector<line> & lines , int & line_idx )
public static Point2D SplashKit . ClosestPointOnLines (Point2D fromPt, List < Line > lines, ref int lineIdx);
def closest_point_on_lines ( from_pt , lines , line_idx ) :
function ClosestPointOnLines (fromPt: Point2D; const lines: ArrayOfLine; var lineIdx: Integer ): Point2D
Create a line from one point to another.
Parameters:
Name Type Description start Point 2d
The start of the line end_pt Point 2d
The end of the line
Return Type: Line
Signatures:
line line_from ( const point_2d & start, const point_2d & end_pt)
public static Line SplashKit . LineFrom (Point2D start, Point2D endPt);
def line_from_point_to_point ( start , end_pt ) :
function LineFrom ( const start: Point2D; const endPt: Point2D): Line
Creates a line that starts at a point, and follows a given vector.
Parameters:
Name Type Description start Point 2d
The start of the line offset Vector 2d
The offset to the end of the line
Return Type: Line
Signatures:
line line_from ( const point_2d & start, const vector_2d & offset)
public static Line SplashKit . LineFrom (Point2D start, Vector2D offset);
def line_from_start_with_offset ( start , offset ) :
function LineFrom ( const start: Point2D; const offset: Vector2D): Line
Gets a line that goes from the origin and ends at the end of the vector.
Parameters:
Name Type Description v Vector 2d
The offset from the origin for the end of the line
Return Type: Line
Signatures:
line line_from ( const vector_2d & v)
public static Line SplashKit . LineFrom (Vector2D v);
function LineFrom ( const v: Vector2D): Line
Create a line from one point to another.
Parameters:
Name Type Description x1 Double
The x value of the start of the line y1 Double
The y value of the start of the line x2 Double
The x value of the end of the line y2 Double
The y value of the end of the line
Return Type: Line
Signatures:
line line_from ( double x1, double y1, double x2, double y2)
public static Line SplashKit . LineFrom ( double x1, double y1, double x2, double y2);
def line_from ( x1 , y1 , x2 , y2 ) :
function LineFrom (x1: Double ; y1: Double ; x2: Double ; y2: Double ): Line
Returns the point at which two lines would intersect. This point may lie past the end of one or both lines.
Parameters:
Name Type Description line1 Line
The first line line2 Line
The other line pt Point 2d
The resulting point where they intersect
Return Type: Boolean
Signatures:
bool line_intersection_point ( const line & line1 , const line & line2 , point_2d & pt )
public static bool SplashKit . LineIntersectionPoint (Line line1, Line line2, ref Point2D pt);
def line_intersection_point ( line1 , line2 , pt ) :
function LineIntersectionPoint ( const line1: Line; const line2: Line; var pt: Point2D): Boolean
Returns true if the line intersects the circle.
Parameters:
Return Type: Boolean
Signatures:
bool line_intersects_circle ( const line & l , const circle & c )
public static bool SplashKit . LineIntersectsCircle (Line l, Circle c);
def line_intersects_circle ( l , c ) :
function LineIntersectsCircle ( const l: Line; const c: Circle): Boolean
Returns true if the line intersects any of the lines.
Parameters:
Name Type Description l Line
The line to check lines Vector
The lines to check against
Return Type: Boolean
Signatures:
bool line_intersects_lines ( const line & l , const vector<line> & lines )
public static bool SplashKit . LineIntersectsLines (Line l, List < Line > lines);
def line_intersects_lines ( l , lines ) :
function LineIntersectsLines ( const l: Line; const lines: ArrayOfLine): Boolean
Returns true if the line intersects the rectangle.
Parameters:
Return Type: Boolean
Signatures:
bool line_intersects_rect ( const line & l , const rectangle & rect )
public static bool SplashKit . LineIntersectsRect (Line l, Rectangle rect);
def line_intersects_rect ( l , rect ) :
function LineIntersectsRect ( const l: Line; const rect: Rectangle): Boolean
Returns the length of a line.
Parameters:
Name Type Description l Line
The line
Return Type: Float
Signatures:
float line_length ( const line & l )
public static float SplashKit . LineLength (Line l);
function LineLength ( const l: Line): Single
Usage:
See Code Examples Example 1 : Simple Line Length
open_window ( " Line Length " , 800 , 600 );
// Define points for the line
point_2d start_point = { 100 , 150 };
point_2d end_point = { 500 , 550 };
// Create a line from start and end points
line demo_line = line_from (start_point, end_point);
draw_line (COLOR_RED, demo_line);
// Calculate the length and draw to window
float length = line_length (demo_line);
draw_text ( " Line length: " + std:: to_string (length), COLOR_BLACK, 110 , 130 );
using static SplashKitSDK . SplashKit;
OpenWindow ( " Line Length " , 800 , 600 );
// Define points for the line
Point2D startPoint = new Point2D() { X = 100 , Y = 150 };
Point2D endPoint = new Point2D() { X = 500 , Y = 550 };
// Create a line from start and end points
Line demoLine = LineFrom (startPoint, endPoint);
DrawLine ( ColorRed (), demoLine);
// Calculate the length and draw to window
float length = LineLength (demoLine);
DrawText ( " Line length: " + length . ToString (), ColorBlack (), 110 , 130 );
namespace LineLengthExample
public static void Main ()
SplashKit . OpenWindow ( " Line Length " , 800 , 600 );
// Define points for the line
Point2D startPoint = new Point2D() { X = 100 , Y = 150 };
Point2D endPoint = new Point2D() { X = 500 , Y = 550 };
// Create a line from start and end points
Line demoLine = SplashKit . LineFrom (startPoint, endPoint);
SplashKit . DrawLine ( Color . Red , demoLine);
// Calculate the length and draw to window
float length = SplashKit . LineLength (demoLine);
SplashKit . DrawText ( " Line length: " + length . ToString (), Color . Black , 110 , 130 );
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Line Length " , 800 , 600 )
# Define points for the line
# Create a line from start and end points
demo_line = line_from_point_to_point ( start_point , end_point ) ;
draw_line_record ( color_red () , demo_line )
# Calculate the length and draw to window
length = line_length ( demo_line )
draw_text_no_font_no_size ( " Line length: " + str ( length ) , color_black () , 110 , 130 )
Output :
Returns the squared length of the line. You can also get the Line Length
.
Parameters:
Name Type Description l Line
The line
Return Type: Float
Signatures:
float line_length_squared ( const line & l )
public static float SplashKit . LineLengthSquared (Line l);
def line_length_squared ( l ) :
function LineLengthSquared ( const l: Line): Single
Usage:
See Code Examples Example 1 : Simple Line Length Squared
open_window ( " Line Length Squared " , 800 , 600 );
// Define points for the line
point_2d start_point = { 100 , 150 };
point_2d end_point = { 500 , 550 };
// Create a line from start and end points
line demo_line = line_from (start_point, end_point);
draw_line (COLOR_RED, demo_line);
// Calculate the squared length and draw to window
float length = line_length_squared (demo_line);
draw_text ( " Line length squared: " + std:: to_string (length), COLOR_BLACK, 110 , 130 );
using static SplashKitSDK . SplashKit;
OpenWindow ( " Line Length Squared " , 800 , 600 );
// Define points for the line
Point2D startPoint = new Point2D() { X = 100 , Y = 150 };
Point2D endPoint = new Point2D() { X = 500 , Y = 550 };
// Create a line from start and end points
Line demoLine = LineFrom (startPoint, endPoint);
DrawLine ( ColorRed (), demoLine);
// Calculate the squared length and draw to window
float length = LineLengthSquared (demoLine);
DrawText ( " Line length squared: " + length . ToString (), ColorBlack (), 110 , 130 );
namespace LineLengthSquaredExample
public static void Main ()
SplashKit . OpenWindow ( " Line Length Squared " , 800 , 600 );
// Define points for the line
Point2D startPoint = new Point2D() { X = 100 , Y = 150 };
Point2D endPoint = new Point2D() { X = 500 , Y = 550 };
// Create a line from start and end points
Line demoLine = SplashKit . LineFrom (startPoint, endPoint);
SplashKit . DrawLine ( Color . Red , demoLine);
// Calculate the squared length and draw to window
float length = SplashKit . LineLengthSquared (demoLine);
SplashKit . DrawText ( " Line length squared: " + length . ToString (), Color . Black , 110 , 130 );
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Line Length Squared " , 800 , 600 )
# Define points for the line
# Create a line from start and end points
demo_line = line_from_point_to_point ( start_point , end_point )
draw_line_record ( color_red () , demo_line )
# Calculate the squared length and draw to window
length = line_length_squared ( demo_line )
draw_text_no_font_no_size ( " Line length squared: " +
str ( length ) , color_black () , 110 , 130 )
Output :
Returns the center point of the line.
Parameters:
Name Type Description l Line
The line
Return Type: Point 2d
Signatures:
point_2d line_mid_point ( const line & l )
public static Point2D SplashKit . LineMidPoint (Line l);
function LineMidPoint ( const l: Line): Point2D
Usage:
See Code Examples Example 1 : Simple Line Mid Point
open_window ( " Line Mid Point " , 800 , 600 );
// Define points for the line
point_2d start_point = { 100 , 150 };
point_2d end_point = { 500 , 550 };
// Create a line from start and end points
line demo_line = line_from (start_point, end_point);
draw_line (COLOR_RED, demo_line);
// Find the mid point and mark it
point_2d mid_point = line_mid_point (demo_line);
draw_circle (COLOR_BLACK, mid_point . x , mid_point . y , 2 );
// Display the midpoint coordinates
draw_text ( " Midpoint coordinates: " + std:: to_string ( mid_point . x ) + " , " + std:: to_string ( mid_point . y ), COLOR_BLACK, mid_point . x + 10 , mid_point . y - 10 );
using static SplashKitSDK . SplashKit;
OpenWindow ( " Line Mid Point " , 800 , 600 );
// Define points for the line
Point2D startPoint = new Point2D() { X = 100 , Y = 150 };
Point2D endPoint = new Point2D() { X = 500 , Y = 550 };
// Create a line from start and end points
Line demoLine = LineFrom (startPoint, endPoint);
DrawLine ( ColorRed (), demoLine);
// Find the mid point and mark it
Point2D midPoint = LineMidPoint (demoLine);
DrawCircle ( ColorBlack (), midPoint . X , midPoint . Y , 2 );
// Display the midpoint coordinates
DrawText ( " Midpoint Coordinates: " + midPoint . X . ToString () + " , " + midPoint . Y . ToString (), ColorBlack (), midPoint . X + 10 , midPoint . Y - 10 );
namespace LineMidPointExample
public static void Main ()
SplashKit . OpenWindow ( " Line Mid Point " , 800 , 600 );
// Define points for the line
Point2D startPoint = new Point2D() { X = 100 , Y = 150 };
Point2D endPoint = new Point2D() { X = 500 , Y = 550 };
// Create a line from start and end points
Line demoLine = SplashKit . LineFrom (startPoint, endPoint);
SplashKit . DrawLine ( Color . Red , demoLine);
// Find the mid point and mark it
Point2D midPoint = SplashKit . LineMidPoint (demoLine);
SplashKit . DrawCircle ( Color . Black , midPoint . X , midPoint . Y , 2 );
// Display the midpoint coordinates
SplashKit . DrawText ( " Midpoint Coordinates: " + midPoint . X . ToString () + " , " + midPoint . Y . ToString (), SplashKit . Color . Black , midPoint . X + 10 , midPoint . Y - 10 );
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Line Mid Point " , 800 , 600 )
# Define points for the line
# Create a line from start and end points
demo_line = line_from_point_to_point ( start_point , end_point )
draw_line_record ( color_red () , demo_line )
# Find the mid point and mark it
mid_point = line_mid_point ( demo_line )
draw_circle ( color_black () , mid_point.x , mid_point.y , 2 )
# Display the midpoint coordinates
draw_text_no_font_no_size ( " Midpoint Coordinates: " +
str ( mid_point.x ) + " , " + str ( mid_point.y ) , color_black () , mid_point.x + 10 , mid_point.y - 10 )
Output :
The line normal (a perpendicular vector).
Parameters:
Name Type Description l Line
The line
Return Type: Vector 2d
Signatures:
vector_2d line_normal ( const line & l )
public static Vector2D SplashKit . LineNormal (Line l);
function LineNormal ( const l: Line): Vector2D
Returns a text description of the line.
Parameters:
Name Type Description ln Line
The line
Return Type: String
Signatures:
string line_to_string ( const line & ln )
public static string SplashKit . LineToString (Line ln);
function LineToString ( const ln: Line): String
Usage:
See Code Examples Example 1 : Display Line Information
open_window ( " Line To String " , 800 , 600 );
// Define points for the line
point_2d start_point = { 100 , 150 };
point_2d end_point = { 500 , 550 };
// Create a line from start and end points
line demo_line = line_from (start_point, end_point);
draw_line (COLOR_RED, demo_line);
// Find the text description of the line
string desc = line_to_string (demo_line);
draw_text (desc, COLOR_BLACK, 110 , 130 );
using static SplashKitSDK . SplashKit;
OpenWindow ( " Line To String " , 800 , 600 );
// Define points for the line
Point2D startPoint = new Point2D() { X = 100 , Y = 150 };
Point2D endPoint = new Point2D() { X = 500 , Y = 550 };
// Create a line from start and end points
Line demoLine = LineFrom (startPoint, endPoint);
DrawLine ( ColorRed (), demoLine);
// Find the text description of the line
string desc = LineToString (demoLine);
DrawText (desc, ColorBlack (), 110 , 130 );
namespace LineToStringExample
public static void Main ()
SplashKit . OpenWindow ( " Line To String " , 800 , 600 );
// Define points for the line
Point2D startPoint = new Point2D() { X = 100 , Y = 150 };
Point2D endPoint = new Point2D() { X = 500 , Y = 550 };
// Create a line from start and end points
Line demoLine = SplashKit . LineFrom (startPoint, endPoint);
SplashKit . DrawLine ( Color . Red , demoLine);
// Find the text description of the line
string desc = SplashKit . LineToString (demoLine);
SplashKit . DrawText (desc, Color . Black , 110 , 130 );
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Line To String " , 800 , 600 )
# Define points for the line
# Create a line from start and end points
demo_line = line_from_point_to_point ( start_point , end_point )
draw_line_record ( color_red () , demo_line )
# Find the text description of the line
desc = line_to_string ( demo_line )
draw_text_no_font_no_size ( desc , color_black () , 110 , 130 )
Output :
Returns an array of lines from a supplied rectangle.
Parameters:
Name Type Description rect Rectangle
The rectangle to get the lines from
Return Type: Vector
Signatures:
vector<line> lines_from ( const rectangle & rect )
public static List < Line > SplashKit . LinesFrom (Rectangle rect);
def lines_from_rectangle ( rect ) :
function LinesFrom ( const rect: Rectangle): ArrayOfLine
Returns an array of lines from the details in the triangle.
Parameters:
Name Type Description t Triangle
The triangle
Return Type: Vector
Signatures:
vector<line> lines_from ( const triangle & t )
public static List < Line > SplashKit . LinesFrom (Triangle t);
def lines_from_triangle ( t ) :
function LinesFrom ( const t: Triangle): ArrayOfLine
Returns true if the two lines intersect.
Parameters:
Name Type Description l1 Line
The first line l2 Line
The other line
Return Type: Boolean
Signatures:
bool lines_intersect ( const line & l1 , const line & l2 )
public static bool SplashKit . LinesIntersect (Line l1, Line l2);
def lines_intersect ( l1 , l2 ) :
function LinesIntersect ( const l1: Line; const l2: Line): Boolean
Usage:
See Code Examples Example 1 : Simple Line Intersect Check
open_window ( " Lines Intersect " , 800 , 600 );
// Define points for the lines
point_2d start_point_a = { 100 , 150 };
point_2d end_point_a = { 500 , 550 };
point_2d start_point_b = { 100 , 550 };
point_2d end_point_b = { 500 , 150 };
point_2d start_point_c = { 550 , 150 };
point_2d end_point_c = { 550 , 500 };
line demo_line_a = line_from (start_point_a, end_point_a);
draw_line (COLOR_RED, demo_line_a);
draw_text ( " A " , COLOR_BLACK, start_point_a . x - 20 , start_point_a . y - 10 );
line demo_line_b = line_from (start_point_b, end_point_b);
draw_line (COLOR_BLUE, demo_line_b);
draw_text ( " B " , COLOR_BLACK, start_point_b . x - 20 , start_point_b . y - 10 );
line demo_line_c = line_from (start_point_c, end_point_c);
draw_line (COLOR_GREEN, demo_line_c);
draw_text ( " C " , COLOR_BLACK, start_point_c . x - 20 , start_point_c . y - 10 );
bool intersect_ab = lines_intersect (demo_line_a, demo_line_b);
bool intersect_ac = lines_intersect (demo_line_a, demo_line_c);
// Display intersection results
draw_text ( " A and B intersect: " + std:: string (intersect_ab ? " Yes " : " No " ), COLOR_BLACK, 150 , 130 );
draw_text ( " A and C intersect: " + std:: string (intersect_ac ? " Yes " : " No " ), COLOR_BLACK, 150 , 150 );
using static SplashKitSDK . SplashKit;
OpenWindow ( " Lines Intersect " , 800 , 600 );
// Define points for the lines
Point2D startPointA = new Point2D() { X = 100 , Y = 150 };
Point2D endPointA = new Point2D() { X = 500 , Y = 550 };
Point2D startPointB = new Point2D() { X = 100 , Y = 550 };
Point2D endPointB = new Point2D() { X = 500 , Y = 150 };
Point2D startPointC = new Point2D() { X = 550 , Y = 150 };
Point2D endPointC = new Point2D() { X = 550 , Y = 500 };
Line demoLineA = LineFrom (startPointA, endPointA);
DrawLine ( ColorRed (), demoLineA);
DrawText ( " A " , ColorBlack (), startPointA . X - 20 , startPointA . Y - 10 );
Line demoLineB = LineFrom (startPointB, endPointB);
DrawLine ( ColorBlue (), demoLineB);
DrawText ( " B " , ColorBlack (), startPointB . X - 20 , startPointB . Y - 10 );
Line demoLineC = LineFrom (startPointC, endPointC);
DrawLine ( ColorGreen (), demoLineC);
DrawText ( " C " , ColorBlack (), startPointC . X - 20 , startPointC . Y - 10 );
bool intersectAB = LinesIntersect (demoLineA, demoLineB);
bool intersectAC = LinesIntersect (demoLineA, demoLineC);
// Display intersection results
DrawText ( " A and B intersect: " + (intersectAB ? " Yes " : " No " ), ColorBlack (), 150 , 130 );
DrawText ( " A and C intersect: " + (intersectAC ? " Yes " : " No " ), ColorBlack (), 150 , 150 );
namespace LinesIntersectExample
public static void Main ()
SplashKit . OpenWindow ( " Lines Intersect " , 800 , 600 );
// Define points for the lines
Point2D startPointA = new Point2D() { X = 100 , Y = 150 };
Point2D endPointA = new Point2D() { X = 500 , Y = 550 };
Point2D startPointB = new Point2D() { X = 100 , Y = 550 };
Point2D endPointB = new Point2D() { X = 500 , Y = 150 };
Point2D startPointC = new Point2D() { X = 550 , Y = 150 };
Point2D endPointC = new Point2D() { X = 550 , Y = 500 };
Line demoLineA = SplashKit . LineFrom (startPointA, endPointA);
SplashKit . DrawLine ( Color . Red , demoLineA);
SplashKit . DrawText ( " A " , Color . Black , startPointA . X - 20 , startPointA . Y - 10 );
Line demoLineB = SplashKit . LineFrom (startPointB, endPointB);
SplashKit . DrawLine ( Color . Blue , demoLineB);
SplashKit . DrawText ( " B " , Color . Black , startPointB . X - 20 , startPointB . Y - 10 );
Line demoLineC = SplashKit . LineFrom (startPointC, endPointC);
SplashKit . DrawLine ( Color . Green , demoLineC);
SplashKit . DrawText ( " C " , Color . Black , startPointC . X - 20 , startPointC . Y - 10 );
bool intersectAB = SplashKit . LinesIntersect (demoLineA, demoLineB);
bool intersectAC = SplashKit . LinesIntersect (demoLineA, demoLineC);
// Display intersection results
SplashKit . DrawText ( " A and B intersect: " + (intersectAB ? " Yes " : " No " ), Color . Black , 150 , 130 );
SplashKit . DrawText ( " A and C intersect: " + (intersectAC ? " Yes " : " No " ), Color . Black , 150 , 150 );
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Lines Intersect " , 800 , 600 )
# Define points for the lines
start_point_a = Point2D ()
start_point_b = Point2D ()
start_point_c = Point2D ()
demo_line_a = line_from_point_to_point ( start_point_a , end_point_a )
draw_line_record ( color_red () , demo_line_a )
draw_text_no_font_no_size (
" A " , color_black () , start_point_a.x - 20 , start_point_a.y - 10 )
demo_line_b = line_from_point_to_point ( start_point_b , end_point_b )
draw_line_record ( color_blue () , demo_line_b )
draw_text_no_font_no_size (
" B " , color_black () , start_point_b.x - 20 , start_point_b.y - 10 )
demo_line_c = line_from_point_to_point ( start_point_c , end_point_c )
draw_line_record ( color_green () , demo_line_c )
draw_text_no_font_no_size (
" C " , color_black () , start_point_c.x - 20 , start_point_c.y - 10 )
intersect_ab = lines_intersect ( demo_line_a , demo_line_b )
intersect_ac = lines_intersect ( demo_line_a , demo_line_c )
# Display intersection results
draw_text_no_font_no_size (
" A and B intersect: " + ( " Yes " if intersect_ab else " No " ) , color_black () , 150 , 130 )
draw_text_no_font_no_size (
" A and C intersect: " + ( " Yes " if intersect_ac else " No " ) , color_black () , 150 , 150 )
Output :
Returns a point at the given location.
Parameters:
Name Type Description x Double
The x value of the coordinate y Double
The y value of the coordinate
Return Type: Point 2d
Signatures:
point_2d point_at ( double x , double y )
public static Point2D SplashKit . PointAt ( double x, double y);
function PointAt (x: Double ; y: Double ): Point2D
Usage:
See Code Examples Example 1 : Flower Grid
// Draw a flower at specific point
void draw_flower (color petal_color , point_2d location )
fill_circle (petal_color, location . x , location . y - 30 , 20 );
fill_circle (petal_color, location . x + 28 , location . y - 10 , 20 );
fill_circle (petal_color, location . x - 28 , location . y - 10 , 20 );
fill_circle (petal_color, location . x + 18 , location . y + 25 , 20 );
fill_circle (petal_color, location . x - 18 , location . y + 25 , 20 );
fill_circle (COLOR_GOLD, location . x , location . y , 20 );
open_window ( " Grid of Flowers " , 600 , 600 );
// Declare constants and variables
point_2d points [GRID_SIZE][GRID_SIZE];
color flower_colors [GRID_SIZE][GRID_SIZE];
// Generate flower points in 5x5 grid pattern
for ( int x = 0 ; x < GRID_SIZE; x ++ )
for ( int y = 0 ; y < GRID_SIZE; y ++ )
// Create a point using temp_x and temp_y
temp_x = 100 + (x * 100 );
temp_y = 100 + (y * 100 );
point_2d temp_point = point_at (temp_x, temp_y);
// Assign data to 2D arrays
points [x][y] = temp_point;
flower_colors [x][y] = rgb_color (x * 50 , 100 , y * 50 );
while ( ! quit_requested ())
// Draw grid of flowers with random colors
for ( int x = 0 ; x < GRID_SIZE; x ++ )
for ( int y = 0 ; y < GRID_SIZE; y ++ )
draw_flower ( flower_colors [x][y], points [x][y]);
using static SplashKitSDK . SplashKit;
// Draw a flower at specific point
static void DrawFlower (Color petal_color, Point2D location)
FillCircle (petal_color, location . X , location . Y - 30 , 20 );
FillCircle (petal_color, location . X + 28 , location . Y - 10 , 20 );
FillCircle (petal_color, location . X - 28 , location . Y - 10 , 20 );
FillCircle (petal_color, location . X + 18 , location . Y + 25 , 20 );
FillCircle (petal_color, location . X - 18 , location . Y + 25 , 20 );
FillCircle ( ColorGold (), location . X , location . Y , 20 );
OpenWindow ( " Grid of Flowers " , 600 , 600 );
// Declare constants and variables
Point2D[,] points = new Point2D[GRID_SIZE, GRID_SIZE];
Color[,] flower_colors = new Color[GRID_SIZE, GRID_SIZE];
// Generate flower points in 5x5 grid pattern
for ( int x = 0 ; x < GRID_SIZE; x ++ )
for ( int y = 0 ; y < GRID_SIZE; y ++ )
// Create a point using temp_x and temp_y
temp_x = 100 + (x * 100 );
temp_y = 100 + (y * 100 );
Point2D temp_point = PointAt (temp_x, temp_y);
// Assign data to 2D arrays
points [x, y] = temp_point;
flower_colors [x, y] = RGBColor (x * 50 , 100 , y * 50 );
// Draw grid of flowers with random colors
for ( int x = 0 ; x < GRID_SIZE; x ++ )
for ( int y = 0 ; y < GRID_SIZE; y ++ )
DrawFlower ( flower_colors [x, y], points [x, y]);
// Draw a flower at specific point
public static void DrawFlower (Color petal_color, Point2D location)
SplashKit . FillCircle (petal_color, location . X , location . Y - 30 , 20 );
SplashKit . FillCircle (petal_color, location . X + 28 , location . Y - 10 , 20 );
SplashKit . FillCircle (petal_color, location . X - 28 , location . Y - 10 , 20 );
SplashKit . FillCircle (petal_color, location . X + 18 , location . Y + 25 , 20 );
SplashKit . FillCircle (petal_color, location . X - 18 , location . Y + 25 , 20 );
SplashKit . FillCircle ( Color . Gold , location . X , location . Y , 20 );
public static void Main ()
SplashKit . OpenWindow ( " Grid of Flowers " , 600 , 600 );
// Declare constants and variables
Point2D[,] points = new Point2D[GRID_SIZE, GRID_SIZE];
Color[,] flower_colors = new Color[GRID_SIZE,GRID_SIZE];
// Generate flower points in 5x5 grid pattern
for ( int x = 0 ; x < GRID_SIZE; x ++ )
for ( int y = 0 ; y < GRID_SIZE; y ++ )
// Create a point using temp_x and temp_y
temp_x = 100 + (x * 100 );
temp_y = 100 + (y * 100 );
Point2D temp_point = SplashKit . PointAt (temp_x, temp_y);
// Assign data to 2D arrays
points [x,y] = temp_point;
flower_colors [x,y] = Color . RGBColor (x * 50 , 100 , y * 50 );
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
// Draw grid of flowers with random colors
for ( int x = 0 ; x < GRID_SIZE; x ++ )
for ( int y = 0 ; y < GRID_SIZE; y ++ )
DrawFlower ( flower_colors [x,y], points [x,y]);
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
# Draw a flower at specific point
def draw_flower ( petal_color , location ) :
fill_circle ( petal_color , location.x , location.y - 30 , 20 )
fill_circle ( petal_color , location.x + 28 , location.y - 10 , 20 )
fill_circle ( petal_color , location.x - 28 , location.y - 10 , 20 )
fill_circle ( petal_color , location.x + 18 , location.y + 25 , 20 )
fill_circle ( petal_color , location.x - 18 , location.y + 25 , 20 )
fill_circle ( color_gold () , location.x , location.y , 20 )
open_window ( " Grid of Flowers " , 600 , 600 )
# Declare constants and variables
points = [[ None for x in range ( GRID_SIZE ) ] for y in range ( GRID_SIZE ) ]
flower_colors = [[ None for x in range ( GRID_SIZE ) ] for y in range ( GRID_SIZE ) ]
# Generate flower points in 5x5 grid pattern
for x in range ( GRID_SIZE ):
for y in range ( GRID_SIZE ):
# Create a point using temp_x and temp_y
temp_point = point_at ( temp_x , temp_y )
# Assign data to 2D arrays
points[x] [ y ] = temp_point
flower_colors[x] [ y ] = rgb_color ( x * 50 , 100 , y * 50 )
while ( not quit_requested ()):
# Draw grid of flowers with random colors
for x in range ( GRID_SIZE ):
for y in range ( GRID_SIZE ):
draw_flower ( flower_colors [ x ] [ y ], points [ x ] [ y ] )
Output :
Returns a point representing the origin.
Return Type: Point 2d
Signatures:
point_2d point_at_origin ()
public static Point2D SplashKit . PointAtOrigin ();
function PointAtOrigin (): Point2D
Usage:
See Code Examples Example 1 : Red Dot At Origin
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
fill_circle (COLOR_RED, point . x , point . y , 4 );
using static SplashKitSDK . SplashKit;
OpenWindow ( " Point At Origin " , 800 , 600 );
// Create a point at origin
Point2D point = PointAtOrigin ();
// Create red circle at the origin point
FillCircle ( ColorRed (), point . X , point . Y , 4 );
namespace PointAtOriginExample
public static void Main ()
SplashKit . OpenWindow ( " Point At Origin " , 800 , 600 );
// Create a point at origin
Point2D point = SplashKit . PointAtOrigin ();
// Create red circle at the origin point
SplashKit . FillCircle ( Color . Red , point . X , point . Y , 4 );
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Point At Origin " , 800 , 600 )
# Create a point at origin
point = point_at_origin ()
# Create red circle at the origin point
fill_circle ( color_red () , point.x , point.y , 4 )
Output :
Example 2 : Hot Summer Sun
open_window ( " Point At Origin " , 800 , 600 );
// Create a point at origin
point_2d point = point_at_origin ();
// Create "sun" at the origin point
for ( int i = 200 ; i > 10 ; i -- )
fill_circle ( rgb_color ( 255 , i + 50 , i % 30 ), point . x , point . y , i);
using static SplashKitSDK . SplashKit;
OpenWindow ( " Point At Origin " , 800 , 600 );
// Create a point at origin
Point2D point = PointAtOrigin ();
// Create "sun" at the origin point
for ( int i = 200 ; i > 10 ; i -- )
FillCircle ( RGBColor ( 255 , i + 50 , i % 30 ), point . X , point . Y , i);
namespace PointAtOriginExample
public static void Main ()
SplashKit . OpenWindow ( " Point At Origin " , 800 , 600 );
// Create a point at origin
Point2D point = SplashKit . PointAtOrigin ();
// Create "sun" at the origin point
for ( int i = 200 ; i > 10 ; i -- )
SplashKit . FillCircle ( SplashKit . RGBColor ( 255 , i + 50 , i % 30 ), point . X , point . Y , i);
SplashKit . RefreshScreen ();
SplashKit . CloseAllWindows ();
open_window ( " Point At Origin " , 800 , 600 )
# Create a point at origin
point = point_at_origin ()
# Create "sun" at the origin point
clear_screen ( color_white ())
for i in range ( 200 , 10 , - 1 ):
fill_circle ( rgb_color ( 255 , i + 50 , i % 30 ) , point.x , point.y , i )
Output :
Returns true if the point pt
is in the circle c
.
Parameters:
Name Type Description pt Point 2d
The point to test c Circle
The circle to check
Return Type: Boolean
Signatures:
bool point_in_circle ( const point_2d & pt , const circle & c )
public static bool SplashKit . PointInCircle (Point2D pt, Circle c);
def point_in_circle ( pt , c ) :
function PointInCircle ( const pt: Point2D; const c: Circle): Boolean
Usage:
See Code Examples Example 1 : Mouse in a Circle
window window = open_window ( " Point In Circle " , 800 , 600 );
circle circle = circle_at ( 400 , 300 , 100 );
while ( ! quit_requested ())
mouse_pt = mouse_position ();
// Update text and circle colour based on the mouse position in relation to the circle
if ( point_in_circle (mouse_pt, circle))
circle_clr = color_red ();
text = " Point in the Circle! " ;
circle_clr = color_green ();
text = " Point not in the Circle! " ;
draw_circle (circle_clr, circle);
draw_text (text, color_red (), 100 , 100 );
using static SplashKitSDK . SplashKit;
Window window = OpenWindow ( " Point In Circle " , 800 , 600 );
Circle circle = CircleAt ( 400 , 300 , 100 );
mousePt = MousePosition ();
// Update text and circle colour based on the mouse position in relation to the circle
if ( PointInCircle (mousePt, circle))
text = " Point in the Circle! " ;
circleClr = ColorGreen ();
text = " Point not in the Circle! " ;
DrawCircle (circleClr, circle);
DrawText (text, ColorRed (), 100 , 100 );
namespace PointInCircleExample
public static void Main ()
Window window = new Window( " Point In Circle " , 800 , 600 );
Circle circle = SplashKit . CircleAt ( 400 , 300 , 100 );
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
mousePt = SplashKit . MousePosition ();
// Update text and circle colour based on the mouse position in relation to the circle
if ( SplashKit . PointInCircle (mousePt, circle))
circleClr = SplashKit . ColorRed ();
text = " Point in the Circle! " ;
circleClr = SplashKit . ColorGreen ();
text = " Point not in the Circle! " ;
SplashKit . DrawCircle (circleClr, circle);
SplashKit . DrawText (text, SplashKit . ColorRed (), 100 , 100 );
SplashKit . RefreshScreen ();
window = open_window ( " Point In Circle " , 800 , 600 )
circle = circle_at_from_points ( 400 , 300 , 100 )
while ( not quit_requested ()):
mouse_pt = mouse_position ()
# Update text and circle colour based on the mouse position in relation to the circle
if ( point_in_circle ( mouse_pt , circle )):
text = " Point in the Circle! "
circle_clr = color_green ()
text = " Point not in the Circle! "
draw_circle_record ( circle_clr , circle )
draw_text_no_font_no_size ( text , color_red () , 100 , 100 )
Output :
Return true if the point is in the circle.
Parameters:
Name Type Description ptx Double
the x value of the point pty Double
the y value of the point cx Double
the x value of the centre of the circle cy Double
the y value of the centre of the circle radius Double
the radius of the circle
Return Type: Boolean
Signatures:
bool point_in_circle ( double ptx , double pty , double cx , double cy , double radius )
public static bool SplashKit . PointInCircle ( double ptx, double pty, double cx, double cy, double radius);
def point_in_circle_with_values ( ptx , pty , cx , cy , radius ) :
function PointInCircle (ptx: Double ; pty: Double ; cx: Double ; cy: Double ; radius: Double ): Boolean
Tests if a point is in a quad.
Parameters:
Name Type Description pt Point 2d
The point to test. q Quad
The quad to check if the point is within.
Return Type: Boolean
Signatures:
bool point_in_quad ( const point_2d & pt , const quad & q )
public static bool SplashKit . PointInQuad (Point2D pt, Quad q);
def point_in_quad ( pt , q ) :
function PointInQuad ( const pt: Point2D; const q: Quad): Boolean
Returns true if point pt
is in the Rectangle rect
.
Parameters:
Return Type: Boolean
Signatures:
bool point_in_rectangle ( const point_2d & pt , const rectangle & rect )
public static bool SplashKit . PointInRectangle (Point2D pt, Rectangle rect);
def point_in_rectangle ( pt , rect ) :
function PointInRectangle ( const pt: Point2D; const rect: Rectangle): Boolean
Usage:
See Code Examples Example 1 : Cursor Jail
rectangle boundary = rectangle_from ( 150 , 150 , 300 , 100 );
timer flashing_timer = create_timer ( " flash time " );
open_window ( " Cursor Jail " , 600 , 600 );
start_timer (flashing_timer);
while ( ! quit_requested ())
mouse_pt = mouse_position ();
// Check if mouse is in the boundary
if ( point_in_rectangle (mouse_pt, boundary))
reset_timer (flashing_timer);
// Flash screen red and blue if mouse has escaped boundary
color1 = color_royal_blue ();
color2 = color_dark_red ();
// Draw UI using timer ticks
if ( timer_ticks (flashing_timer) < 500 )
fill_rectangle ( color_white (), boundary);
if ( timer_ticks (flashing_timer) >= 500 && timer_ticks (flashing_timer) < 1000 )
fill_rectangle ( color_white (), boundary);
draw_text (text, color_black (), 250 , 400 );
if ( timer_ticks (flashing_timer) >= 1000 )
reset_timer (flashing_timer);
using static SplashKitSDK . SplashKit;
SplashKitSDK . Point2D mousePt;
SplashKitSDK . Rectangle boundary = RectangleFrom ( 150 , 150 , 300 , 100 );
SplashKitSDK . Color color1;
SplashKitSDK . Color color2;
SplashKitSDK . Timer flashingTimer = CreateTimer ( " flash time " );
OpenWindow ( " Cursor Jail " , 600 , 600 );
StartTimer (flashingTimer);
mousePt = MousePosition ();
// Check if mouse is in the boundary
if ( PointInRectangle (mousePt, boundary))
ResetTimer (flashingTimer);
// Flash screen red and blue if mouse has escaped boundary
color1 = ColorRoyalBlue ();
// Draw UI using timer ticks
if ( TimerTicks (flashingTimer) < 500 )
FillRectangle ( ColorWhite (), boundary);
if ( TimerTicks (flashingTimer) >= 500 && TimerTicks (flashingTimer) < 1000 )
FillRectangle ( ColorWhite (), boundary);
DrawText (text, ColorBlack (), 250 , 400 );
if ( TimerTicks (flashingTimer) >= 1000 )
ResetTimer (flashingTimer);
namespace PointInRectangleExample
public static void Main ()
Rectangle boundary = SplashKit . RectangleFrom ( 150 , 150 , 300 , 100 );
SplashKitSDK . Timer flashingTimer = SplashKit . CreateTimer ( " flash time " );
SplashKit . OpenWindow ( " Cursor Jail " , 600 , 600 );
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
mousePt = SplashKit . MousePosition ();
// Check if mouse is in the boundary
if ( SplashKit . PointInRectangle (mousePt, boundary))
// Flash screen red and blue if mouse has escaped boundary
color1 = Color . RoyalBlue ;
// Draw UI using timer ticks
if ( flashingTimer . Ticks < 500 )
SplashKit . ClearScreen (color1);
SplashKit . FillRectangle ( Color . White , boundary);
SplashKit . RefreshScreen ();
if ( flashingTimer . Ticks >= 500 && flashingTimer . Ticks < 1000 )
SplashKit . ClearScreen (color2);
SplashKit . FillRectangle ( Color . White , boundary);
SplashKit . DrawText (text, Color . Black , 250 , 400 );
SplashKit . RefreshScreen ();
if ( flashingTimer . Ticks >= 1000 )
SplashKit . CloseAllWindows ();
boundary = rectangle_from ( 150 , 150 , 300 , 100 )
flashing_timer = create_timer ( " flash time " )
open_window ( " Cursor Jail " , 600 , 600 )
start_timer ( flashing_timer )
while not quit_requested ():
mouse_pt = mouse_position ()
# Check if mouse is in the boundary
if point_in_rectangle ( mouse_pt , boundary ):
reset_timer ( flashing_timer )
# Flash screen red and blue if mouse has escaped boundary
color1 = color_royal_blue ()
color2 = color_dark_red ()
# Draw UI using timer ticks
if timer_ticks ( flashing_timer ) < 500 :
fill_rectangle_record ( color_white () , boundary )
if timer_ticks ( flashing_timer ) >= 500 and timer_ticks ( flashing_timer ) < 1000 :
fill_rectangle_record ( color_white () , boundary )
draw_text_no_font_no_size ( text , color_black () , 250 , 400 )
if timer_ticks ( flashing_timer ) >= 1000 :
reset_timer ( flashing_timer )
Output :
Returns true if the point is within the bounds of a Rectangle.
Parameters:
Name Type Description ptx Double
the x value of the point pty Double
the y value of the point rect_x Double
x value of the rectangle rect_y Double
y value of the rectangle rect_width Double
width of the rectangle rect_height Double
height of the rectangle
Return Type: Boolean
Signatures:
bool point_in_rectangle ( double ptx , double pty , double rect_x , double rect_y , double rect_width , double rect_height )
public static bool SplashKit . PointInRectangle ( double ptx, double pty, double rectX, double rectY, double rectWidth, double rectHeight);
def point_in_rectangle_with_values ( ptx , pty , rect_x , rect_y , rect_width , rect_height ) :
function PointInRectangle (ptx: Double ; pty: Double ; rectX: Double ; rectY: Double ; rectWidth: Double ; rectHeight: Double ): Boolean
Returns true if the point pt
is in the Triangle tri
.
Parameters:
Return Type: Boolean
Signatures:
bool point_in_triangle ( const point_2d & pt , const triangle & tri )
public static bool SplashKit . PointInTriangle (Point2D pt, Triangle tri);
def point_in_triangle ( pt , tri ) :
function PointInTriangle ( const pt: Point2D; const tri: Triangle): Boolean
Usage:
See Code Examples Example 1 : Mouse in a Triangle
triangle triangle = triangle_from ( 700 , 200 , 500 , 1 , 200 , 500 );
open_window ( " Point In Triangle " , 800 , 600 );
while ( ! quit_requested ())
mouse_pt = mouse_position ();
// Update text and triangle colour based on the mouse position in relation to the triangle
if ( point_in_triangle (mouse_pt, triangle))
triangle_clr = color_red ();
text = " Point in the triangle! " ;
triangle_clr = color_green ();
text = " Point not in the triangle! " ;
draw_triangle (triangle_clr, triangle);
draw_text (text, color_red (), 100 , 100 );
using static SplashKitSDK . SplashKit;
SplashKitSDK . Triangle triangle = TriangleFrom ( 700 , 200 , 500 , 1 , 200 , 500 );
SplashKitSDK . Point2D mousePt;
SplashKitSDK . Color triangleClr;
OpenWindow ( " Point In Triangle " , 800 , 600 );
mousePt = MousePosition ();
// Update text and triangle colour based on the mouse position in relation to the triangle
if ( PointInTriangle (mousePt, triangle))
triangleClr = ColorRed ();
text = " Point in the triangle! " ;
triangleClr = ColorGreen ();
text = " Point not in the triangle! " ;
DrawTriangle (triangleClr, triangle);
DrawText (text, ColorRed (), 100 , 100 );
namespace PointInTriangleExample
public static void Main ()
Window window = new Window( " Point In Triangle " , 800 , 600 );
Triangle triangle = SplashKit . TriangleFrom ( 700 , 200 , 500 , 1 , 200 , 500 );
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
mousePt = SplashKit . MousePosition ();
// Update text and triangle colour based on the mouse position in relation to the triangle
if ( SplashKit . PointInTriangle (mousePt, triangle))
triangleClr = SplashKit . ColorRed ();
text = " Point in the triangle! " ;
triangleClr = SplashKit . ColorGreen ();
text = " Point not in the triangle! " ;
SplashKit . DrawTriangle (triangleClr, triangle);
SplashKit . DrawText (text, SplashKit . ColorRed (), 100 , 100 );
SplashKit . RefreshScreen ();
triangle = triangle_from ( point_at ( 700 , 200 ) , point_at ( 500 , 1 ) , point_at ( 200 , 500 ))
open_window ( " Point In Triangle " , 800 , 600 )
while ( not quit_requested ()):
mouse_pt = mouse_position ()
# Update text and triangle colour based on the mouse position in relation to the triangle
if ( point_in_triangle ( mouse_pt , triangle )):
triangle_clr = color_red ()
text = " Point in the triangle! "
triangle_clr = color_green ()
text = " Point not in the triangle! "
draw_triangle_record ( triangle_clr , triangle )
draw_text_no_font_no_size ( text , color_red () , 100 , 100 )
Output :
Returns the distance from a point to a line.
Parameters:
Return Type: Float
Signatures:
float point_line_distance ( const point_2d & pt , const line & l )
public static float SplashKit . PointLineDistance (Point2D pt, Line l);
def point_line_distance ( pt , l ) :
function PointLineDistance ( const pt: Point2D; const l: Line): Single
Calculate the Point 2d
that is offset from the start_point
by the offset
Parameters:
Name Type Description start_point Point 2d
The starting point offset Vector 2d
The distance and direction to move
Return Type: Point 2d
Signatures:
point_2d point_offset_by ( const point_2d & start_point , const vector_2d & offset )
public static Point2D SplashKit . PointOffsetBy (Point2D startPoint, Vector2D offset);
def point_offset_by ( start_point , offset ) :
function PointOffsetBy ( const startPoint: Point2D; const offset: Vector2D): Point2D
Usage:
See Implementations in Guides
Returns the point offset from the origin by the provided vector.
Parameters:
Name Type Description offset Vector 2d
The distance and direction to move
Return Type: Point 2d
Signatures:
point_2d point_offset_from_origin ( const vector_2d & offset )
public static Point2D SplashKit . PointOffsetFromOrigin (Vector2D offset);
def point_offset_from_origin ( offset ) :
function PointOffsetFromOrigin ( const offset: Vector2D): Point2D
Returns true if point pt
is on the line l
.
Parameters:
Name Type Description pt Point 2d
The point to test l Line
The line to check
Return Type: Boolean
Signatures:
bool point_on_line ( const point_2d & pt , const line & l )
public static bool SplashKit . PointOnLine (Point2D pt, Line l);
def point_on_line ( pt , l ) :
function PointOnLine ( const pt: Point2D; const l: Line): Boolean
Usage:
See Code Examples Example 1 : Mouse Point On Line?
line line = line_from ( 100 , 300 , 500 , 300 );
window window = open_window ( " Select Point " , 600 , 600 );
while ( ! quit_requested ())
clear_screen ( color_white ());
draw_line ( color_black (), line);
// Draw text if cursor is on line
if ( point_on_line ( mouse_position (), line))
draw_text ( " Point on line: " + point_to_string ( mouse_position ()), color_black (), 200 , 450 );
using static SplashKitSDK . SplashKit;
Line line = LineFrom ( 100 , 300 , 500 , 300 );
Window window = OpenWindow ( " Select Point " , 600 , 600 );
ClearScreen ( ColorWhite ());
DrawLine ( ColorBlack (), line);
// Draw text if cursor is on line
if ( PointOnLine ( MousePosition (), line))
DrawText ( " Point on line: " + PointToString ( MousePosition ()), ColorBlack (), 200 , 450 );
namespace PointOnLineExample
public static void Main ()
Line line = SplashKit . LineFrom ( 100 , 300 , 500 , 300 );
Window window = new Window( " Select Point " , 600 , 600 );
while ( ! SplashKit . QuitRequested ())
window . Clear ( Color . White );
window . DrawLine ( Color . Black , line);
// Draw text if cursor is on line
if ( SplashKit . PointOnLine ( SplashKit . MousePosition (), line))
window . DrawText ( " Point on line: " + SplashKit . PointToString ( SplashKit . MousePosition ()), Color . Black , 200 , 450 );
SplashKit . ProcessEvents ();
line = line_from ( 100 , 300 , 500 , 300 )
window = open_window ( " Select Point " , 600 , 600 )
while not quit_requested ():
clear_screen ( color_white ())
draw_line_record ( color_black () , line )
if point_on_line ( mouse_position () , line ):
# Draw text if cursor is on line
draw_text_no_font_no_size ( " Point on line: " + point_to_string ( mouse_position ()) , color_black () , 200 , 450 )
Output :
Example 2 : Volume Slider Simulation
line slider = line_from ( 100 , 300 , 500 , 300 );
line bar = line_from (bar_x, 310 , bar_x, 290 );
bool bar_selected = false ;
window window = open_window ( " Volume Slider " , 600 , 600 );
while ( ! quit_requested ())
// Check if user has clicked on the bar Line
if ( mouse_down (LEFT_BUTTON) && point_on_line ( mouse_position (), bar))
// Check if user has released mouse button
if ( mouse_up (LEFT_BUTTON))
if (bar_selected && mouse_x () >= 100 && mouse_x () <= 500 )
bar_x = mouse_x (); // sets bar_x value to mouse x value
percent = int ((bar_x - 100 ) / ( 500 - 100 ) * 100 ); // convert bar_x position to percent value
bar = line_from (bar_x, 310 , bar_x, 290 );
// Draw lines and volume text
clear_screen ( color_white ());
draw_line ( color_black (), bar);
draw_line ( color_black (), slider);
draw_text ( " Volume: " + std:: to_string (percent), color_black (), 200 , 450 );
using static SplashKitSDK . SplashKit;
Line slider = LineFrom ( 100 , 300 , 500 , 300 );
Line bar = LineFrom (barX, 310 , barX, 290 );
bool barSelected = false ;
Window window = OpenWindow ( " Volume Slider " , 600 , 600 );
// Check if user has clicked on the bar Line
if ( MouseDown ( MouseButton . LeftButton ) && PointOnLine ( MousePosition (), bar))
// Check if user has released mouse button
if ( MouseUp ( MouseButton . LeftButton ))
if (barSelected && MouseX () >= 100 && MouseX () <= 500 )
barX = MouseX (); // sets barX value to mouse X value
percent = ( int )((barX - 100 ) / ( 500 - 100 ) * 100 ); // convert barX position to percent value
bar = LineFrom (barX, 310 , barX, 290 );
// Draw Lines and volume text
ClearScreen ( ColorWhite ());
DrawLine ( ColorBlack (), bar);
DrawLine ( ColorBlack (), slider);
DrawText ( $" Volume: { percent } " , ColorBlack (), 200 , 450 );
namespace PointOnLineExample
public static void Main ()
Line slider = SplashKit . LineFrom ( 100 , 300 , 500 , 300 );
Line bar = SplashKit . LineFrom (barX, 310 , barX, 290 );
bool barSelected = false ;
Window window = new Window( " Volume Slider " , 600 , 600 );
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
// Check if user has clicked on the bar Line
if ( SplashKit . MouseDown ( MouseButton . LeftButton ) && SplashKit . PointOnLine ( SplashKit . MousePosition (), bar))
// Check if user has released mouse button
if ( SplashKit . MouseUp ( MouseButton . LeftButton ))
if (barSelected && SplashKit . MouseX () >= 100 && SplashKit . MouseX () <= 500 )
barX = SplashKit . MouseX (); // sets barX value to mouse X value
percent = ( int )((barX - 100 ) / ( 500 - 100 ) * 100 ); // convert barX position to percent value
bar = SplashKit . LineFrom (barX, 310 , barX, 290 );
// Draw Lines and volume text
window . Clear ( Color . White );
window . DrawLine ( Color . Black , bar);
window . DrawLine ( Color . Black , slider);
window . DrawText ( $" Volume: { percent } % " , Color . Black , 200 , 450 );
slider = line_from ( 100 , 300 , 500 , 300 )
bar = line_from ( bar_x , 310 , bar_x , 290 )
window = open_window ( " Volume Slider " , 600 , 600 )
while not quit_requested ():
# Check if user has clicked on the bar Line
if ( mouse_down ( MouseButton.left_button ) and point_on_line ( mouse_position () , bar )):
# Check if user has released mouse button
if ( mouse_up ( MouseButton.left_button )):
if (bar_selected and mouse_x () >= 100 and mouse_x () <= 500 ):
bar_x = mouse_x () # sets bar_x value to mouse x value
percent = int ( (bar_x - 100 ) / ( 500 - 100 ) * 100 ) # convert bar_x position to percent value
bar = line_from ( bar_x , 310 , bar_x , 290 )
# Draw lines and volume text
clear_screen ( color_white ())
draw_line_record ( color_black () , bar )
draw_line_record ( color_black () , slider )
draw_text_no_font_no_size ( " Volume: " + str ( percent ) , color_black () , 200 , 450 )
Output :
Returns true when the point pt
is on the line l
. The proximity value is used to set the sensitivity — higher values effectively make the line thicker.
Parameters:
Name Type Description pt Point 2d
The point to test l Line
The line to check proximity Float
The sensitivity to allow close approximities
Return Type: Boolean
Signatures:
bool point_on_line ( const point_2d & pt , const line & l , float proximity )
public static bool SplashKit . PointOnLine (Point2D pt, Line l, float proximity);
def point_on_line_with_proximity ( pt , l , proximity ) :
function PointOnLine ( const pt: Point2D; const l: Line; proximity: Single ): Boolean
Returns the angle between two points in degrees.
Parameters:
Return Type: Float
Signatures:
float point_point_angle ( const point_2d & pt1 , const point_2d & pt2 )
public static float SplashKit . PointPointAngle (Point2D pt1, Point2D pt2);
def point_point_angle ( pt1 , pt2 ) :
function PointPointAngle ( const pt1: Point2D; const pt2: Point2D): Single
Usage:
See Code Examples Example 1 : How Does “Point Point Angle” Work?
window window = open_window ( " How Does \" Point Point Angle \" Work? " , 400 , 400 );
font arial = load_font ( " arial " , " arial.ttf " );
line horizontal_line = line_from ( 0 , screen_height () / 2 , screen_width (), screen_height () / 2 );
line vertical_line = line_from ( screen_width () / 2 , 0 , screen_width () / 2 , screen_height ());
line zero_line = line_from ( screen_width () / 2 , screen_height () / 2 , screen_width (), screen_height () / 2 );
circle outer_circle = circle_at ( screen_center (), 100 );
circle center_circle = circle_at ( screen_center (), 4 );
point_2d center_pt = screen_center ();
float pt_pt_angle; // Store the "Point Point Angle"
while ( ! quit_requested ())
// Get "current" Mouse Position
mouse_pt = mouse_position ();
// Calculate the angle between the center point and the current mouse position
pt_pt_angle = point_point_angle (center_pt, mouse_pt);
// Round to 2 decimal places for nicer output
snprintf (angle, 10 , " %.2f " , pt_pt_angle);
// Draw background annotation
clear_screen ( color_white ());
draw_line ( color_black (), horizontal_line);
draw_line ( color_black (), vertical_line);
draw_circle ( color_black (), outer_circle);
draw_line ( color_red (), zero_line);
fill_circle ( color_red (), center_circle);
draw_text ( " 0 " , color_blue (), arial, 16 , 350 , screen_height () / 2 - 20 );
draw_text ( " o " , color_blue (), arial, 10 , 360 , screen_height () / 2 - 23 );
draw_text ( " 90 " , color_blue (), arial, 16 , screen_width () / 2 + 5 , 350 );
draw_text ( " o " , color_blue (), arial, 10 , screen_width () / 2 + 24 , 347 );
draw_text ( " -90 " , color_blue (), arial, 16 , screen_width () / 2 + 5 , 35 );
draw_text ( " o " , color_blue (), arial, 10 , screen_width () / 2 + 29 , 32 );
draw_text ( " 180 " , color_blue (), arial, 16 , 30 , screen_height () / 2 - 20 );
draw_text ( " o " , color_blue (), arial, 10 , 58 , screen_height () / 2 - 23 );
draw_line ( color_red (), center_pt, mouse_position ());
fill_rectangle ( color_green (), mouse_x () + 10 , mouse_y () - 10 , 80 , 30 );
draw_text (angle, color_white (), arial, 16 , mouse_x () + 20 , mouse_y () - 5 );
draw_text ( " o " , color_white (), arial, 10 , mouse_x () + 20 + text_width (angle, arial, 16 ), mouse_y () - 8 );
using static SplashKitSDK . SplashKit;
using static System . Math;
Window window = OpenWindow ( " How Does \" Point Point Angle \" Work? " , 400 , 400 );
Font arial = LoadFont ( " arial " , " arial.ttf " );
Line horizontalL = LineFrom ( 0 , ScreenHeight () / 2 , ScreenWidth (), ScreenHeight () / 2 );
Line verticalL = LineFrom ( ScreenWidth () / 2 , 0 , ScreenWidth () / 2 , ScreenHeight ());
Line zeroL = LineFrom ( ScreenWidth () / 2 , ScreenHeight () / 2 , ScreenWidth (), ScreenHeight () / 2 );
Circle quadrantsC = CircleAt ( ScreenCenter (), 100 );
Circle centerC = CircleAt ( ScreenCenter (), 4 );
Point2D centerPt = ScreenCenter ();
float ptPtAngle; // Store the "Point Point Angle"
// Get "current" Mouse Position
mousePt = MousePosition ();
// Calculate the angle between the center point and the current mouse position
ptPtAngle = PointPointAngle (centerPt, mousePt);
// Round to 2 decimal places for nicer output
angle = Round (ptPtAngle, 2 );
// Draw background annotation
ClearScreen ( ColorWhite ());
DrawLine ( ColorBlack (), horizontalL);
DrawLine ( ColorBlack (), verticalL);
DrawCircle ( ColorBlack (), quadrantsC);
DrawLine ( ColorRed (), zeroL);
FillCircle ( ColorRed (), centerC);
DrawText ( " 0 " , ColorBlue (), arial, 16 , 350 , ScreenHeight () / 2 - 20 );
DrawText ( " o " , ColorBlue (), arial, 10 , 360 , ScreenHeight () / 2 - 23 );
DrawText ( " 90 " , ColorBlue (), arial, 16 , ScreenWidth () / 2 + 5 , 350 );
DrawText ( " o " , ColorBlue (), arial, 10 , ScreenWidth () / 2 + 24 , 347 );
DrawText ( " -90 " , ColorBlue (), arial, 16 , ScreenWidth () / 2 + 5 , 35 );
DrawText ( " o " , ColorBlue (), arial, 10 , ScreenWidth () / 2 + 29 , 32 );
DrawText ( " 180 " , ColorBlue (), arial, 16 , 30 , ScreenHeight () / 2 - 20 );
DrawText ( " o " , ColorBlue (), arial, 10 , 58 , ScreenHeight () / 2 - 23 );
DrawLine ( ColorRed (), centerPt, MousePosition ());
FillRectangle ( ColorGreen (), MouseX () + 10 , MouseY () - 10 , 80 , 30 );
DrawText ( $" { angle } " , ColorWhite (), arial, 16 , MouseX () + 20 , MouseY () - 5 );
DrawText ( " o " , ColorWhite (), arial, 10 , MouseX () + 20 + TextWidth ( $" { angle } " , arial, 16 ), MouseY () - 8 );
namespace PointPointAngleExample
public static void Main ()
Window window = SplashKit . OpenWindow ( " How Does \" Point Point Angle \" Work? " , 400 , 400 );
Font arial = SplashKit . LoadFont ( " arial " , " arial.ttf " );
Line horizontalL = SplashKit . LineFrom ( 0 , SplashKit . ScreenHeight () / 2 , SplashKit . ScreenWidth (), SplashKit . ScreenHeight () / 2 );
Line verticalL = SplashKit . LineFrom ( SplashKit . ScreenWidth () / 2 , 0 , SplashKit . ScreenWidth () / 2 , SplashKit . ScreenHeight ());
Line zeroL = SplashKit . LineFrom ( SplashKit . ScreenWidth () / 2 , SplashKit . ScreenHeight () / 2 , SplashKit . ScreenWidth (), SplashKit . ScreenHeight () / 2 );
Circle quadrantsC = SplashKit . CircleAt ( SplashKit . ScreenCenter (), 100 );
Circle centerC = SplashKit . CircleAt ( SplashKit . ScreenCenter (), 4 );
Point2D centerPt = SplashKit . ScreenCenter ();
float ptPtAngle; // Store the "Point Point Angle"
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
// Get "current" Mouse Position
mousePt = SplashKit . MousePosition ();
// Calculate the angle between the center point and the current mouse position
ptPtAngle = SplashKit . PointPointAngle (centerPt, mousePt);
// Round to 2 decimal places for nicer output
angle = Math . Round (ptPtAngle, 2 );
// Draw background annotation
SplashKit . ClearScreen ( Color . White );
SplashKit . DrawLine ( Color . Black , horizontalL);
SplashKit . DrawLine ( Color . Black , verticalL);
SplashKit . DrawCircle ( Color . Black , quadrantsC);
SplashKit . DrawLine ( Color . Red , zeroL);
SplashKit . FillCircle ( Color . Red , centerC);
SplashKit . DrawText ( " 0 " , Color . Blue , arial, 16 , 350 , SplashKit . ScreenHeight () / 2 - 20 );
SplashKit . DrawText ( " o " , Color . Blue , arial, 10 , 360 , SplashKit . ScreenHeight () / 2 - 23 );
SplashKit . DrawText ( " 90 " , Color . Blue , arial, 16 , SplashKit . ScreenWidth () / 2 + 5 , 350 );
SplashKit . DrawText ( " o " , Color . Blue , arial, 10 , SplashKit . ScreenWidth () / 2 + 24 , 347 );
SplashKit . DrawText ( " -90 " , Color . Blue , arial, 16 , SplashKit . ScreenWidth () / 2 + 5 , 35 );
SplashKit . DrawText ( " o " , Color . Blue , arial, 10 , SplashKit . ScreenWidth () / 2 + 29 , 32 );
SplashKit . DrawText ( " 180 " , Color . Blue , arial, 16 , 30 , SplashKit . ScreenHeight () / 2 - 20 );
SplashKit . DrawText ( " o " , Color . Blue , arial, 10 , 58 , SplashKit . ScreenHeight () / 2 - 23 );
SplashKit . DrawLine ( Color . Red , centerPt, SplashKit . MousePosition ());
SplashKit . FillRectangle ( Color . Green , SplashKit . MouseX () + 10 , SplashKit . MouseY () - 10 , 80 , 30 );
SplashKit . DrawText ( $" { angle } " , Color . White , arial, 16 , SplashKit . MouseX () + 20 , SplashKit . MouseY () - 5 );
SplashKit . DrawText ( " o " , Color . White , arial, 10 , SplashKit . MouseX () + 20 + SplashKit . TextWidth ( $" { angle } " , arial, 16 ), SplashKit . MouseY () - 8 );
SplashKit . RefreshScreen ();
window = open_window ( ' How Does "Point Point Angle" Work? ' , 400 , 400 )
arial = load_font ( " arial " , " arial.ttf " )
horizontal_line = line_from ( 0 , screen_height () / 2 , screen_width () , screen_height () / 2 )
vertical_line = line_from ( screen_width () / 2 , 0 , screen_width () / 2 , screen_height ())
zero_line = line_from ( screen_width () / 2 , screen_height () / 2 , screen_width () , screen_height () / 2 )
outer_circle = circle_at ( screen_center () , 100 )
center_circle = circle_at ( screen_center () , 4 )
center_pt = screen_center ()
pt_pt_angle = 0 # Store the "Point Point Angle"
while not quit_requested ():
# Get "current" Mouse Position
mouse_pt = mouse_position ()
# Calculate the angle between the center point and the current mouse position
pt_pt_angle = point_point_angle ( center_pt , mouse_pt )
# Round to 2 decimal places for nicer output
angle = str ( round ( pt_pt_angle , 2 ))
# Draw background annotation
clear_screen ( color_white ())
draw_line_record ( color_black () , horizontal_line )
draw_line_record ( color_black () , vertical_line )
draw_circle_record ( color_black () , outer_circle )
draw_line_record ( color_red () , zero_line )
fill_circle_record ( color_red () , center_circle )
draw_text ( " 0 " , color_blue () , arial , 16 , 350 , screen_height () / 2 - 20 )
draw_text ( " o " , color_blue () , arial , 10 , 360 , screen_height () / 2 - 23 )
draw_text ( " 90 " , color_blue () , arial , 16 , screen_width () / 2 + 5 , 350 )
draw_text ( " o " , color_blue () , arial , 10 , screen_width () / 2 + 24 , 347 )
draw_text ( " -90 " , color_blue () , arial , 16 , screen_width () / 2 + 5 , 35 )
draw_text ( " o " , color_blue () , arial , 10 , screen_width () / 2 + 29 , 32 )
draw_text ( " 180 " , color_blue () , arial , 16 , 30 , screen_height () / 2 - 20 )
draw_text ( " o " , color_blue () , arial , 10 , 58 , screen_height () / 2 - 23 )
draw_line_point_to_point ( color_red () , center_pt , mouse_position ())
fill_rectangle ( color_green () , mouse_x () + 10 , mouse_y () - 10 , 80 , 30 )
draw_text ( angle , color_white () , arial , 16 , mouse_x () + 20 , mouse_y () - 5 )
draw_text ( " o " , color_white () , arial , 10 , mouse_x () + 20 + text_width ( angle , arial , 16 ) , mouse_y () - 8 )
Output :
Returns the distance between two points.
Parameters:
Return Type: Float
Signatures:
float point_point_distance ( const point_2d & pt1 , const point_2d & pt2 )
public static float SplashKit . PointPointDistance (Point2D pt1, Point2D pt2);
def point_point_distance ( pt1 , pt2 ) :
function PointPointDistance ( const pt1: Point2D; const pt2: Point2D): Single
Usage:
See Code Examples Example 1 : Distance To Center
open_window ( " Distance From Center " , 600 , 600 );
point_2d center_pt = screen_center ();
while ( ! quit_requested ())
// Get "current" Mouse Position
mouse_pt = mouse_position ();
// Calculate the distance between the center point and the current mouse position
pt_pt_distance = point_point_distance (center_pt, mouse_pt);
// Draw line and distance between center of window (filled circle) and mouse point
fill_circle (COLOR_RED, center_pt . y , center_pt . y , 5 );
draw_line (COLOR_BLUE, center_pt, mouse_pt);
draw_text (std:: to_string (pt_pt_distance), COLOR_BLACK, mouse_pt . x + 10 , mouse_pt . y - 10 );
// Close all opened windows
using static SplashKitSDK . SplashKit;
OpenWindow ( " Distance From Center " , 600 , 600 );
Point2D center_pt = ScreenCenter ();
// Get "current" Mouse Position
mouse_pt = MousePosition ();
// Calculate the distance between the center point and the current mouse position
pt_pt_distance = PointPointDistance (center_pt, mouse_pt);
// Draw line and distance between center of window (filled circle) and mouse point
FillCircle ( ColorRed (), center_pt . X , center_pt . Y , 5 );
DrawLine ( ColorBlue (), center_pt, mouse_pt);
DrawText ( pt_pt_distance . ToString (), ColorBlack (), mouse_pt . X + 10 , mouse_pt . Y - 10 );
// Close all opened windows
namespace PointPointDistance
public static void Main ()
SplashKit . OpenWindow ( " Distance From Center " , 600 , 600 );
Point2D center_pt = SplashKit . ScreenCenter ();
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
// Get "current" Mouse Position
mouse_pt = SplashKit . MousePosition ();
// Calculate the distance between the center point and the current mouse position
pt_pt_distance = SplashKit . PointPointDistance (center_pt, mouse_pt);
// Draw line and distance between center of window (filled circle) and mouse point
SplashKit . FillCircle ( Color . Red , center_pt . X , center_pt . Y , 5 );
SplashKit . DrawLine ( Color . Blue , center_pt, mouse_pt);
SplashKit . DrawText ( pt_pt_distance . ToString (), Color . Black , mouse_pt . X + 10 , mouse_pt . Y - 10 );
SplashKit . RefreshScreen ();
// Close all opened windows
SplashKit . CloseAllWindows ();
open_window ( " Distance From Center " , 600 , 600 )
center_pt = screen_center ()
pt_pt_distance = 0 # Store the "Point Point Distance"
while ( not quit_requested ()):
# Get "current" Mouse Position
mouse_pt = mouse_position ()
# Calculate the distance between the center point and the current mouse position
pt_pt_distance = point_point_distance ( center_pt , mouse_pt )
# Draw line and distance between center of window (filled circle) and mouse point
fill_circle ( color_red () , center_pt.y , center_pt.y , 5 )
draw_line_point_to_point ( color_blue () , center_pt , mouse_pt )
draw_text_no_font_no_size ( str ( pt_pt_distance ) , color_black () , mouse_pt.x + 10 , mouse_pt.y - 10 )
# Close all opened windows
Output :
Get a text description of the Point 2d
.
Parameters:
Name Type Description pt Point 2d
The point details
Return Type: String
Signatures:
string point_to_string ( const point_2d & pt )
public static string SplashKit . PointToString (Point2D pt);
function PointToString ( const pt: Point2D): String
Usage:
See Code Examples Example 1 : Mouse Click Location
string mouse_position_text = " Click to see coordinates... " ;
open_window ( " Mouse Clicked Location " , 600 , 600 );
while ( ! quit_requested ())
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 );
using static SplashKitSDK . SplashKit;
string mousePositionText = " Click to see coordinates... " ;
OpenWindow ( " Mouse Clicked Location " , 600 , 600 );
if ( MouseClicked ( MouseButton . LeftButton ))
mousePositionText = " Mouse clicked at " + PointToString ( MousePosition ());
// Print mouse position to screen
ClearScreen ( ColorGhostWhite ());
DrawText (mousePositionText, ColorBlack (), 100 , 300 );
namespace PointToStringExample
public static void Main ()
string mousePositionText = " Click to see coordinates... " ;
Window window = new Window( " Mouse Clicked Location " , 600 , 600 );
while ( ! SplashKit . QuitRequested ())
SplashKit . ProcessEvents ();
if ( SplashKit . MouseClicked ( MouseButton . LeftButton ))
mousePositionText = " Mouse clicked at " + SplashKit . PointToString ( SplashKit . MousePosition ());
// Print mouse position to screen
window . Clear ( Color . GhostWhite );
window . DrawText (mousePositionText, Color . Black , 100 , 300 );
mouse_position_text = " Click to see coordinates... "
open_window ( " Mouse Clicked Location " , 600 , 600 )
while not quit_requested ():
if mouse_clicked ( MouseButton.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_no_font_no_size ( mouse_position_text , color_black () , 100 , 300 )
Output :
Returns a random point within the bounds of the bitmap.
Parameters:
Name Type Description bmp Bitmap
The bitmap
Return Type: Point 2d
Signatures:
point_2d random_bitmap_point (bitmap bmp )
public static Point2D SplashKit . RandomBitmapPoint (Bitmap bmp);
def random_bitmap_point ( bmp ) :
function RandomBitmapPoint (bmp: Bitmap): Point2D
Usage:
See Code Examples Example 1 : Random Triangles
// Create Window and empty bitmap
open_window ( " Random Bitmap Points with Triangles " , 600 , 600 );
bitmap bmp = create_bitmap ( " Random Triangles " , 600 , 600 );
for ( int i = 0 ; i < 10 ; i ++ )
// Create triangle using random points on bitmap
triangle triangle = triangle_from (
random_bitmap_point (bmp),
random_bitmap_point (bmp),
random_bitmap_point (bmp));
fill_triangle_on_bitmap (bmp, random_color (), triangle);
clear_screen ( color_white_smoke ());
using static SplashKitSDK . SplashKit;
// Create Window and empty bitmap
OpenWindow ( " Random Bitmap Points with Triangles " , 600 , 600 );
Bitmap bmp = CreateBitmap ( " Random Triangles " , 600 , 600 );
for ( int i = 0 ; i < 10 ; i ++ )
// Create triangle using random points on bitmap
Triangle triangle = TriangleFrom (
FillTriangleOnBitmap (bmp, RandomColor (), triangle);
ClearScreen ( ColorWhiteSmoke ());
namespace RandomBitmapPointExample
public static void Main ()
// Create Window and empty bitmap
Window window = new Window( " Random Bitmap Points with Triangles " , 600 , 600 );
Bitmap bmp = new Bitmap( " Random Triangles " , 600 , 600 );
for ( int i = 0 ; i < 10 ; i ++ )
// Create triangle using random points on bitmap
Triangle triangle = SplashKit . TriangleFrom (
SplashKit . RandomBitmapPoint (bmp),
SplashKit . RandomBitmapPoint (bmp),
SplashKit . RandomBitmapPoint (bmp));
bmp . FillTriangle ( Color . Random (), triangle);
window . Clear ( Color . WhiteSmoke );
window . DrawBitmap (bmp, 0 , 0 );
# Create Window and empty bitmap
open_window ( " Random Bitmap Points with Triangles " , 600 , 600 )
bmp = create_bitmap ( " Random Triangles " , 600 , 600 )
# Create triangle using random points on bitmap
triangle = triangle_from (
random_bitmap_point ( bmp ) ,
random_bitmap_point ( bmp ) ,
random_bitmap_point ( bmp ))
fill_triangle_on_bitmap_record ( bmp , random_color () , triangle )
clear_screen ( color_white_smoke ())
Output :
Returns a random point on the current window.
Return Type: Point 2d
Signatures:
point_2d random_screen_point ()
public static Point2D SplashKit . RandomScreenPoint ();
def random_screen_point () :
function RandomScreenPoint (): Point2D
Usage:
See Code Examples Example 1 : Stars in the Sky
open_window ( " Night Sky " , 600 , 600 );
clear_screen (COLOR_BLACK);
for ( int i = 0 ; i < 1000 ; i ++ )
// Set random pixel location on screen
point_2d pixel = random_screen_point ();
draw_pixel ( random_rgb_color ( 255 ), pixel);
using static SplashKitSDK . SplashKit;
OpenWindow ( " Night Sky " , 600 , 600 );
ClearScreen ( ColorBlack ());
for ( int i = 0 ; i < 1000 ; i ++ )
// Set random pixel location on screen
Point2D pixel = RandomScreenPoint ();
DrawPixel ( RandomRGBColor ( 255 ), pixel);
namespace RandomScreenPointExample
public static void Main ()
Window window = new Window( " Night Sky " , 600 , 600 );
window . Clear ( Color . Black );
for ( int i = 0 ; i < 1000 ; i ++ )
// Set random pixel location on screen
Point2D pixel = SplashKit . RandomScreenPoint ();
SplashKit . DrawPixel ( Color . RandomRGB ( 255 ), pixel);
open_window ( " Night Sky " , 600 , 600 )
clear_screen ( color_black ())
# Set random pixel location on screen
pixel = random_screen_point ()
draw_pixel_at_point ( random_rgb_color ( 255 ) , pixel )
Output :
Returns a random point on the provided window.
Parameters:
Name Type Description wind Window
The window
Return Type: Point 2d
Signatures:
point_2d random_window_point (window wind )
public static Point2D SplashKit . RandomWindowPoint (Window wind);
def random_window_point ( wind ) :
function RandomWindowPoint (wind: Window): Point2D
Usage:
See Code Examples Example 1 : Random Portals
window window = open_window ( " Portal " , 600 , 600 );
load_bitmap ( " blue_portal " , " bluePortal.png " );
load_bitmap ( " orange_portal " , " orangePortal.png " );
sprite blue_portal = create_sprite ( bitmap_named ( " blue_portal " ));
sprite orange_portal = create_sprite ( bitmap_named ( " orange_portal " ));
// Set random portal location
sprite_set_position (blue_portal, random_window_point (window));
sprite_set_position (orange_portal, random_window_point (window));
clear_window (window, color_black ());
draw_sprite (blue_portal);
draw_sprite (orange_portal);
using static SplashKitSDK . SplashKit;
Window Window = OpenWindow ( " Portal " , 600 , 600 );
LoadBitmap ( " BluePortal " , " bluePortal.png " );
LoadBitmap ( " OrangePortal " , " orangePortal.png " );
Sprite BluePortal = CreateSprite ( BitmapNamed ( " BluePortal " ));
Sprite OrangePortal = CreateSprite ( BitmapNamed ( " OrangePortal " ));
// Set random portal location
SpriteSetPosition (BluePortal, RandomWindowPoint (Window));
SpriteSetPosition (OrangePortal, RandomWindowPoint (Window));
ClearWindow (Window, ColorBlack ());
DrawSprite (OrangePortal);
namespace RandomWindowPointExample
public static void Main ()
Window Window = SplashKit . OpenWindow ( " Portal " , 600 , 600 );
Bitmap BluePortal = new Bitmap( " BluePortal " , " bluePortal.png " );
Bitmap OrangePortal = new Bitmap( " OrangePortal " , " orangePortal.png " );
Sprite BluePortalSprite = SplashKit . CreateSprite (BluePortal);
Sprite OrangePortalSprite = SplashKit . CreateSprite (OrangePortal);
// Set random portal location
BluePortalSprite . Position = SplashKit . RandomWindowPoint (Window);
OrangePortalSprite . Position = SplashKit . RandomWindowPoint (Window);
Window . Clear ( Color . Black );
SplashKit . DrawSprite (BluePortalSprite);
SplashKit . DrawSprite (OrangePortalSprite);
window = open_window ( " Portal " , 600 , 600 )
load_bitmap ( " blue_portal " , " bluePortal.png " )
load_bitmap ( " orange_portal " , " orangePortal.png " )
blue_portal = create_sprite ( bitmap_named ( " blue_portal " ))
orange_portal = create_sprite ( bitmap_named ( " orange_portal " ))
# Set random portal location
sprite_set_position ( blue_portal , random_window_point ( window ))
sprite_set_position ( orange_portal , random_window_point ( window ))
clear_window ( window , color_black ())
draw_sprite ( orange_portal )
Output :
Returns True of pt1
is at the same point as pt2
. This checks at an integer level, indicating the two points refer to the same pixel.
Parameters:
Return Type: Boolean
Signatures:
bool same_point ( const point_2d & pt1 , const point_2d & pt2 )
public static bool SplashKit . SamePoint (Point2D pt1, Point2D pt2);
def same_point ( pt1 , pt2 ) :
function SamePoint ( const pt1: Point2D; const pt2: Point2D): Boolean
Usage:
See Code Examples Example 1 : Point 2D Guessing Game
point_2d get_point (string prompt )
string guess_input = read_line ();
vector < string > coords = split (guess_input, ' , ' );
while ( ! is_double ( coords [ 0 ]) || ! is_double ( coords [ 1 ]))
write_line ( " Invalid input. Try again. " );
guess_input = read_line ();
coords = split (guess_input, ' , ' );
double guess_x = convert_to_double ( coords [ 0 ]);
double guess_y = convert_to_double ( coords [ 1 ]);
return point_at (guess_x, guess_y);
point_2d target_point = point_at ( 50 , 75 );
write_line ( " Guess the coordinate inside (100,100) " );
// Get point input from user
guess_point = get_point ( " Enter your coordinates as x,y: " );
while ( ! same_point (target_point, guess_point))
if ( target_point . x > guess_point . x )
write_line ( " x is too low " );
else if ( target_point . x < guess_point . x )
write_line ( " x is too high " );
write_line ( " x is correct !!! " );
if ( target_point . y > guess_point . y )
write_line ( " y is too low " );
else if ( target_point . y < guess_point . y )
write_line ( " y is too high " );
write_line ( " y is correct !!! " );
write_line ( " Try Again! " );
guess_point = get_point ( " Enter your coordinates as x,y: " );
using static SplashKitSDK . SplashKit;
static Point2D GetPoint ( string prompt)
string guessInput = ReadLine ();
List< string > coords = Split (guessInput, ',' );
while ( ! IsDouble ( coords [ 0 ]) || ! IsDouble ( coords [ 1 ]))
WriteLine ( " Invalid input. Try again. " );
coords = Split (guessInput, ',' );
double guessX = ConvertToDouble ( coords [ 0 ]);
double guessY = ConvertToDouble ( coords [ 1 ]);
return PointAt (guessX, guessY);
Point2D targetPoint = PointAt ( 50 , 75 );
WriteLine ( " Guess the coordinate inside (100,100) " );
guessPoint = GetPoint ( " Enter your coordinates as x,y: " );
while ( ! SamePoint (targetPoint, guessPoint))
if ( targetPoint . X > guessPoint . X )
WriteLine ( " x is too low " );
else if ( targetPoint . X < guessPoint . X )
WriteLine ( " x is too high " );
WriteLine ( " x is correct !!! " );
if ( targetPoint . Y > guessPoint . Y )
WriteLine ( " y is too low " );
else if ( targetPoint . Y < guessPoint . Y )
WriteLine ( " y is too high " );
WriteLine ( " y is correct !!! " );
guessPoint = GetPoint ( " Enter your coordinates as x,y: " );
namespace SamePointExample
public static Point2D GetPoint ( string prompt)
string guessInput = SplashKit . ReadLine ();
List< string > coords = SplashKit . Split (guessInput, ',' );
while ( ! SplashKit . IsDouble ( coords [ 0 ]) || ! SplashKit . IsDouble ( coords [ 1 ]))
SplashKit . WriteLine ( " Invalid input. Try again. " );
guessInput = SplashKit . ReadLine ();
coords = SplashKit . Split (guessInput, ',' );
double guessX = SplashKit . ConvertToDouble ( coords [ 0 ]);
double guessY = SplashKit . ConvertToDouble ( coords [ 1 ]);
return SplashKit . PointAt (guessX, guessY);
public static void Main ()
Point2D targetPoint = SplashKit . PointAt ( 50 , 75 );
SplashKit . WriteLine ( " Guess the coordinate inside (100,100) " );
guessPoint = GetPoint ( " Enter your coordinates as x,y: " );
while ( ! SplashKit . SamePoint (targetPoint, guessPoint))
if ( targetPoint . X > guessPoint . X )
SplashKit . WriteLine ( " x is too low " );
else if ( targetPoint . X < guessPoint . X )
SplashKit . WriteLine ( " x is too high " );
SplashKit . WriteLine ( " x is correct !!! " );
if ( targetPoint . Y > guessPoint . Y )
SplashKit . WriteLine ( " y is too low " );
else if ( targetPoint . Y < guessPoint . Y )
SplashKit . WriteLine ( " y is too high " );
SplashKit . WriteLine ( " y is correct !!! " );
SplashKit . WriteLine ( " Try Again! " );
guessPoint = GetPoint ( " Enter your coordinates as x,y: " );
SplashKit . WriteLine ( " You Win! " );
guess_input = read_line ()
coords = split ( guess_input , ' , ' )
while ( not is_double ( coords [ 0 ]) or not is_double ( coords [ 1 ])):
write_line ( " Invalid input. Try again. " )
guess_input = read_line ()
coords = split ( guess_input , ' , ' )
guess_x = convert_to_double ( coords [ 0 ])
guess_y = convert_to_double ( coords [ 1 ])
return point_at ( guess_x , guess_y )
target_point = point_at ( 50 , 75 )
write_line ( " Guess the coordinate inside (100,100) " )
# Get point input from user
guess_point = get_point ( " Enter your coordinates as x,y: " )
while ( not same_point ( target_point , guess_point )):
if target_point.x > guess_point.x:
write_line ( " x is too low " )
elif target_point.x < guess_point.x:
write_line ( " x is too high " )
write_line ( " x is correct !!! " )
if target_point.y > guess_point.y:
write_line ( " y is too low " )
elif target_point.y < guess_point.y:
write_line ( " y is too high " )
write_line ( " y is correct !!! " )
guess_point = get_point ( " Enter your coordinates as x,y: " )
Output :
Returns a quad from the passed in line and width. The quad will be a rectangle with the line as the diagonal, and the width as the width of the rectangle.
Parameters:
Name Type Description line_origin Point 2d
The origin of the line line_end Point 2d
The end of the line width Double
The width of the quad
Return Type: Quad
Signatures:
quad quad_from ( const point_2d & line_origin , const point_2d & line_end , double width )
public static Quad SplashKit . QuadFrom (Point2D lineOrigin, Point2D lineEnd, double width);
def quad_from_from_line ( line_origin , line_end , width ) :
function QuadFrom ( const lineOrigin: Point2D; const lineEnd: Point2D; width: Double ): Quad
Returns a quad from the passed in points.
Parameters:
Name Type Description p1 Point 2d
The top left of the quad. p2 Point 2d
The top right of the quad p3 Point 2d
The bottom left of the quad p4 Point 2d
The bottom right of the quad
Return Type: Quad
Signatures:
quad quad_from ( const point_2d & p1 , const point_2d & p2 , const point_2d & p3 , const point_2d & p4 )
public static Quad SplashKit . QuadFrom (Point2D p1, Point2D p2, Point2D p3, Point2D p4);
def quad_from_points ( p1 , p2 , p3 , p4 ) :
function QuadFrom ( const p1: Point2D; const p2: Point2D; const p3: Point2D; const p4: Point2D): Quad
Returns a quad from the x-y points of a given recatangle
Parameters:
Name Type Description rect Rectangle
The rectangle to convert to a quad
Return Type: Quad
Signatures:
quad quad_from ( const rectangle & rect )
public static Quad SplashKit . QuadFrom (Rectangle rect);
def quad_from_rectangle ( rect ) :
function QuadFrom ( const rect: Rectangle): Quad
Returns a quad from the rectangle, then applies the transformation to the quads points.
Parameters:
Name Type Description rect Rectangle
The rectangle to transform to a quad. transform Matrix 2d
A transform to apply to the resulting quad.
Return Type: Quad
Signatures:
quad quad_from ( const rectangle & rect , const matrix_2d & transform )
public static Quad SplashKit . QuadFrom (Rectangle rect, Matrix2D transform);
def quad_from_rectangle_with_transformation ( rect , transform ) :
function QuadFrom ( const rect: Rectangle; const transform: Matrix2D): Quad
Returns a quad for the passed in x & y points.
Parameters:
Name Type Description x_top_left Double
X coordinate of the top left of the quad y_top_left Double
Y coordinate of the top left of the quad x_top_right Double
X coordinate of the top right of the quad y_top_right Double
Y coordinate of the top right of the quad x_bottom_left Double
X coordinate of the bottom left of the quad y_bottom_left Double
Y coordinate of the bottom left of the quad x_bottom_right Double
X coordinate of the bottom right of the quad y_bottom_right Double
Y coordinate of the bottom right of the quad
Return Type: Quad
Signatures:
quad quad_from ( double x_top_left , double y_top_left , double x_top_right , double y_top_right , double x_bottom_left , double y_bottom_left , double x_bottom_right , double y_bottom_right )
public static Quad SplashKit . QuadFrom ( double xTopLeft, double yTopLeft, double xTopRight, double yTopRight, double xBottomLeft, double yBottomLeft, double xBottomRight, double yBottomRight);
def quad_from ( x_top_left , y_top_left , x_top_right , y_top_right , x_bottom_left , y_bottom_left , x_bottom_right , y_bottom_right ) :
function QuadFrom (xTopLeft: Double ; yTopLeft: Double ; xTopRight: Double ; yTopRight: Double ; xBottomLeft: Double ; yBottomLeft: Double ; xBottomRight: Double ; yBottomRight: Double ): Quad
Returns true if two quads intersect.
Parameters:
Name Type Description q1 Quad
The first quad q2 Quad
The second quad
Return Type: Boolean
Signatures:
bool quads_intersect ( const quad & q1 , const quad & q2 )
public static bool SplashKit . QuadsIntersect (Quad q1, Quad q2);
def quads_intersect ( q1 , q2 ) :
function QuadsIntersect ( const q1: Quad; const q2: Quad): Boolean
Change a point in a quad.
Parameters:
Name Type Description q Quad
The quad to change idx Integer
The index of the point: 0 is top left, 1 is top right, 2 is bottom left, and 3 is bottom right value Point 2d
The new value for that point in the quad
Signatures:
void set_quad_point (quad & q , int idx , const point_2d & value )
public static void SplashKit . SetQuadPoint ( ref Quad q, int idx, Point2D value );
def set_quad_point ( q , idx , value ) :
procedure SetQuadPoint ( var q: Quad; idx: Integer ; const value: Point2D)
Returns the two triangles that make up a quad in a vector.
Parameters:
Name Type Description q Quad
The quad
Return Type: Vector
Signatures:
vector<triangle> triangles_from ( const quad & q )
public static List < Triangle > SplashKit . TrianglesFrom (Quad q);
function TrianglesFrom ( const q: Quad): ArrayOfTriangle
Return a rectangle that is inset an amount from a given rectangle.
Parameters:
Name Type Description rect Rectangle
The rectangle to inset inset_amount Float
The amount to inset the rectangle
Return Type: Rectangle
Signatures:
rectangle inset_rectangle ( const rectangle & rect , float inset_amount )
public static Rectangle SplashKit . InsetRectangle (Rectangle rect, float insetAmount);
def inset_rectangle ( rect , inset_amount ) :
function InsetRectangle ( const rect: Rectangle; insetAmount: Single ): Rectangle
Returns a rectangle that represents the intersection of two rectangles.
Parameters:
Return Type: Rectangle
Signatures:
rectangle intersection ( const rectangle & rect1 , const rectangle & rect2 )
public static Rectangle SplashKit . Intersection (Rectangle rect1, Rectangle rect2);
def intersection ( rect1 , rect2 ) :
function Intersection ( const rect1: Rectangle; const rect2: Rectangle): Rectangle
Returns a rectangle that surrounds a given circle
Parameters:
Name Type Description c Circle
The circle
Return Type: Rectangle
Signatures:
rectangle rectangle_around ( const circle & c )
public static Rectangle SplashKit . RectangleAround (Circle c);
def rectangle_around_circle ( c ) :
function RectangleAround ( const c: Circle): Rectangle
Returns a rectangle that surrounds a given line segment
Parameters:
Name Type Description l Line
The line
Return Type: Rectangle
Signatures:
rectangle rectangle_around ( const line & l )
public static Rectangle SplashKit . RectangleAround (Line l);
def rectangle_around_line ( l ) :
function RectangleAround ( const l: Line): Rectangle
Returns a rectangle that surrounds a given quad.
Parameters:
Name Type Description q Quad
The quad
Return Type: Rectangle
Signatures:
rectangle rectangle_around ( const quad & q )
public static Rectangle SplashKit . RectangleAround (Quad q);
def rectangle_around_quad ( q ) :
function RectangleAround ( const q: Quad): Rectangle
Returns a rectangle that surrounds a given triangle
Parameters:
Name Type Description t Triangle
The triangle
Return Type: Rectangle
Signatures:
rectangle rectangle_around ( const triangle & t )
public static Rectangle SplashKit . RectangleAround (Triangle t);
def rectangle_around_triangle ( t ) :
function RectangleAround ( const t: Triangle): Rectangle
The location of the bottom of the rectangle.
Parameters:
Name Type Description rect Rectangle
The rectangle.
Return Type: Float
Signatures:
float rectangle_bottom ( const rectangle & rect )
public static float SplashKit . RectangleBottom (Rectangle rect);
def rectangle_bottom ( rect ) :
function RectangleBottom ( const rect: Rectangle): Single
Returns the center point of a given rectangle
Parameters:
Name Type Description rect Rectangle
The rectangle
Return Type: Point 2d
Signatures:
point_2d rectangle_center ( const rectangle & rect )
public static Point2D SplashKit . RectangleCenter (Rectangle rect);
def rectangle_center ( rect ) :
function RectangleCenter ( const rect: Rectangle): Point2D
Returns a rectangle at the specified point with a given width and height
Parameters:
Name Type Description pt Point 2d
The origin for the rectangle width Double
Its width height Double
Its height
Return Type: Rectangle
Signatures:
rectangle rectangle_from ( const point_2d pt , const double width , const double height )
public static Rectangle SplashKit . RectangleFrom (Point2D pt, double width, double height);
def rectangle_from_point_and_size ( pt , width , height ) :
function RectangleFrom (pt: Point2D; width: Double ; height: Double ): Rectangle
Returns a rectangle with pt1 and pt2 defining the two distant edge points.
Parameters:
Return Type: Rectangle
Signatures:
rectangle rectangle_from ( const point_2d pt1 , const point_2d pt2 )
public static Rectangle SplashKit . RectangleFrom (Point2D pt1, Point2D pt2);
def rectangle_from_points ( pt1 , pt2 ) :
function RectangleFrom (pt1: Point2D; pt2: Point2D): Rectangle
Returns a rectangle from a given x,y location with the specified width and height.
Parameters:
Name Type Description x Double
The x coordinate of the rectangle y Double
The y coordinate of the rectangle width Double
The width of the rectangle height Double
The height of the rectangle
Return Type: Rectangle
Signatures:
rectangle rectangle_from ( double x , double y , double width , double height )
public static Rectangle SplashKit . RectangleFrom ( double x, double y, double width, double height);
def rectangle_from ( x , y , width , height ) :
function RectangleFrom (x: Double ; y: Double ; width: Double ; height: Double ): Rectangle
Usage:
See Implementations in Guides
The location of the left edge of the rectangle.
Parameters:
Name Type Description rect Rectangle
The rectangle.
Return Type: Float
Signatures:
float rectangle_left ( const rectangle & rect )
public static float SplashKit . RectangleLeft (Rectangle rect);
def rectangle_left ( rect ) :
function RectangleLeft ( const rect: Rectangle): Single
Returns a rectangle that is moved by the provided vector.
Parameters:
Name Type Description rect Rectangle
The original rectangle offset Vector 2d
The amount and direction for the rectangle to move
Return Type: Rectangle
Signatures:
rectangle rectangle_offset_by ( const rectangle & rect , const vector_2d & offset )
public static Rectangle SplashKit . RectangleOffsetBy (Rectangle rect, Vector2D offset);
def rectangle_offset_by ( rect , offset ) :
function RectangleOffsetBy ( const rect: Rectangle; const offset: Vector2D): Rectangle
The location of the right edge of the rectangle.
Parameters:
Name Type Description rect Rectangle
The rectangle.
Return Type: Float
Signatures:
float rectangle_right ( const rectangle & rect )
public static float SplashKit . RectangleRight (Rectangle rect);
def rectangle_right ( rect ) :
function RectangleRight ( const rect: Rectangle): Single
Get a text representation of the passed in rectangle.
Parameters:
Name Type Description rect Rectangle
The rectangle
Return Type: String
Signatures:
string rectangle_to_string ( const rectangle & rect )
public static string SplashKit . RectangleToString (Rectangle rect);
def rectangle_to_string ( rect ) :
function RectangleToString ( const rect: Rectangle): String
The top of the rectangle.
Parameters:
Name Type Description rect Rectangle
The rectangle.
Return Type: Float
Signatures:
float rectangle_top ( const rectangle & rect )
public static float SplashKit . RectangleTop (Rectangle rect);
function RectangleTop ( const rect: Rectangle): Single
Returns true if the two rectangles intersect.
Parameters:
Return Type: Boolean
Signatures:
bool rectangles_intersect ( const rectangle & rect1 , const rectangle & rect2 )
public static bool SplashKit . RectanglesIntersect (Rectangle rect1, Rectangle rect2);
def rectangles_intersect ( rect1 , rect2 ) :
function RectanglesIntersect ( const rect1: Rectangle; const rect2: Rectangle): Boolean
Return the barycenter of the triangle. This is one way of calculating the center point of a triangle.
Parameters:
Name Type Description tri Triangle
The triangle to get the center of
Return Type: Point 2d
Signatures:
point_2d triangle_barycenter ( const triangle & tri )
public static Point2D SplashKit . TriangleBarycenter (Triangle tri);
def triangle_barycenter ( tri ) :
function TriangleBarycenter ( const tri: Triangle): Point2D
Generate a triangle from a set of points.
Parameters:
Name Type Description p1 Point 2d
The first point of the triangle p2 Point 2d
The second point of the triangle p3 Point 2d
The third point of the triangle
Return Type: Triangle
Signatures:
triangle triangle_from ( const point_2d & p1 , const point_2d & p2 , const point_2d & p3 )
public static Triangle SplashKit . TriangleFrom (Point2D p1, Point2D p2, Point2D p3);
def triangle_from ( p1 , p2 , p3 ) :
function TriangleFrom ( const p1: Point2D; const p2: Point2D; const p3: Point2D): Triangle
Generate a triangle from a set of points.
Parameters:
Name Type Description x1 Double
The x coordinate for the first point y1 Double
The y coordinate for the first point x2 Double
The x coordinate for the second point y2 Double
The y coordinate for the second point x3 Double
The x coordinate for the third point y3 Double
The y coordinate for the third point
Return Type: Triangle
Signatures:
triangle triangle_from ( double x1 , double y1 , double x2 , double y2 , double x3 , double y3 )
public static Triangle SplashKit . TriangleFrom ( double x1, double y1, double x2, double y2, double x3, double y3);
def triangle_from__from_coordinates ( x1 , y1 , x2 , y2 , x3 , y3 ) :
function TriangleFrom (x1: Double ; y1: Double ; x2: Double ; y2: Double ; x3: Double ; y3: Double ): Triangle
Returns true if the triangle intersects with the rectangle.
Parameters:
Return Type: Boolean
Signatures:
bool triangle_rectangle_intersect ( const triangle & tri , const rectangle & rect )
public static bool SplashKit . TriangleRectangleIntersect (Triangle tri, Rectangle rect);
def triangle_rectangle_intersect ( tri , rect ) :
function TriangleRectangleIntersect ( const tri: Triangle; const rect: Rectangle): Boolean
Returns a text description of the triangle.
Parameters:
Name Type Description tri Triangle
The triangle
Return Type: String
Signatures:
string triangle_to_string ( const triangle & tri )
public static string SplashKit . TriangleToString (Triangle tri);
def triangle_to_string ( tri ) :
function TriangleToString ( const tri: Triangle): String
Returns true if the two triangles intersect.
Parameters:
Return Type: Boolean
Signatures:
bool triangles_intersect ( const triangle & t1 , const triangle & t2 )
public static bool SplashKit . TrianglesIntersect (Triangle t1, Triangle t2);
def triangles_intersect ( t1 , t2 ) :
function TrianglesIntersect ( const t1: Triangle; const t2: Triangle): Boolean