Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions public/usage-examples/utilities/gcd_1_example-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using SplashKitSDK;

namespace GCDExample
{
public class Program
{
public static void Main()
{
// open window
SplashKit.OpenWindow("Greatest Common Divisor Example", 640, 360);

// define two numbers
int numA = 48;
int numB = 18;

// calculate gcd using splashkit function
int result = SplashKit.GCD(numA, numB);

while (!SplashKit.QuitRequested())
{
SplashKit.ProcessEvents();
SplashKit.ClearScreen(Color.White);

// heading
SplashKit.DrawText("Calculating the Greatest Common Divisor (GCD)", Color.Blue, 60, 40);

// numbers
SplashKit.DrawText($"Number A: {numA}", Color.Black, 80, 100);
SplashKit.DrawText($"Number B: {numB}", Color.Black, 80, 140);

// result
SplashKit.DrawText($"GCD Result: {result}", Color.Red, 80, 200);

// exit instructions
SplashKit.DrawText("Press ESC to exit", Color.Gray, 420, 330);

SplashKit.RefreshScreen();
}

SplashKit.CloseAllWindows();
}
}
}
35 changes: 35 additions & 0 deletions public/usage-examples/utilities/gcd_1_example-top-level.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// open window
OpenWindow("Greatest Common Divisor Example", 640, 360);

// define two numbers
int numA = 48;
int numB = 18;

// calculate gcd using splashkit function
int result = GCD(numA, numB);

while (!QuitRequested())
{
ProcessEvents();
ClearScreen(ColorWhite());

// heading
DrawText("Calculating the Greatest Common Divisor (GCD)", ColorBlue(), 60, 40);

// numbers
DrawText($"Number A: {numA}", ColorBlack(), 80, 100);
DrawText($"Number B: {numB}", ColorBlack(), 80, 140);

// result
DrawText($"GCD Result: {result}", ColorRed(), 80, 200);

// exit instructions
DrawText("Press ESC to exit", ColorGray(), 420, 330);

RefreshScreen();
}

CloseAllWindows();
33 changes: 33 additions & 0 deletions public/usage-examples/utilities/gcd_1_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "splashkit.h"

int main()
{
open_window("Greatest Common Divisor Example", 600, 400);

// I am setting up two example numbers
int a = 48;
int b = 18;

// I am calculating the GCD using the built-in SplashKit function
int gcd_value = greatest_common_divisor(a, b);

// I am clearing the screen and showing the results
clear_screen(COLOR_WHITE);
draw_text("Calculating the Greatest Common Divisor (GCD)", COLOR_NAVY, 60, 60);
draw_text("Number A: " + std::to_string(a), COLOR_BLACK, 60, 120);
draw_text("Number B: " + std::to_string(b), COLOR_BLACK, 60, 150);
draw_text("GCD Result: " + std::to_string(gcd_value), COLOR_RED, 60, 200);

draw_text("Press ESC to exit", COLOR_GRAY, 400, 360);
refresh_screen();

// Wait for ESC key to exit
while (!quit_requested())
{
process_events();
if (key_typed(ESCAPE_KEY)) break;
}

close_all_windows();
return 0;
}
Binary file added public/usage-examples/utilities/gcd_1_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions public/usage-examples/utilities/gcd_1_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from splashkit import *

# open a window with the same title and dimensions
open_window("Greatest Common Divisor Example", 640, 360)

# define two numbers
num_a = 48
num_b = 18

# use splashkit's gcd function
result = gcd(num_a, num_b)

# main loop
while not quit_requested():
process_events()

clear_screen(color_white())

# heading text
draw_text("Calculating the Greatest Common Divisor (GCD)", color_blue(), 60, 40)

# numbers being used
draw_text(f"Number A: {num_a}", color_black(), 80, 100)
draw_text(f"Number B: {num_b}", color_black(), 80, 140)

# result in red
draw_text(f"GCD Result: {result}", color_red(), 80, 200)

# exit instructions
draw_text("Press ESC to exit", color_gray(), 420, 330)

refresh_screen()

close_all_windows()
1 change: 1 addition & 0 deletions public/usage-examples/utilities/gcd_1_example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Greatest Common Divisor Calculator
82 changes: 82 additions & 0 deletions public/usage-examples/utilities/split_text-1-example-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using SplashKitSDK;

namespace SplitTextExample
{
public class SplitText
{
private Window _window;
private string _text;
private string[] _parts;
private Color _topColor;
private Color _bottomColor;

public SplitText()
{
// creating window
_window = new Window("Split Text Example", 800, 400);

// I am defining the text to split
_text = "apple,banana,carrot";

// I am splitting the string into parts using SplashKit's split() function
_parts = SplashKit.Split(_text, ',');

// colors for background gradient
_topColor = SplashKit.RGBColor(245, 251, 255);
_bottomColor = SplashKit.RGBColor(200, 230, 255);
}

private Color BlendColors(Color c1, Color c2, double t)
{
// linear interpolation for RGB channels
int r = (int)((1 - t) * SplashKit.RedOf(c1) + t * SplashKit.RedOf(c2));
int g = (int)((1 - t) * SplashKit.GreenOf(c1) + t * SplashKit.GreenOf(c2));
int b = (int)((1 - t) * SplashKit.BlueOf(c1) + t * SplashKit.BlueOf(c2));
return SplashKit.RGBColor(r, g, b);
}

public void Run()
{
while (!SplashKit.QuitRequested())
{
SplashKit.ProcessEvents();

// draw gradient background
for (int y = 0; y < _window.Height; y++)
{
double t = (double)y / _window.Height;
Color blended = BlendColors(_topColor, _bottomColor, t);
SplashKit.DrawLine(blended, 0, y, _window.Width, y);
}

// display text
SplashKit.DrawText("Original string:", SplashKit.ColorDarkBlue(), "arial", 20, 60, 50);
SplashKit.DrawText(_text, SplashKit.ColorBlack(), "arial", 20, 280, 50);

int yPos = 130;
foreach (string s in _parts)
{
SplashKit.DrawText("Token: " + s, SplashKit.ColorBlack(), "arial", 18, 60, yPos);
yPos += 40;
}

SplashKit.DrawText("Press ESC to exit", SplashKit.ColorGray(), "arial", 14, 620, 360);
_window.Refresh(60);

if (SplashKit.KeyTyped(KeyCode.EscapeKey))
{
break;
}
}

_window.Close();
}

public static void Main()
{
SplitText demo = new SplitText();
demo.Run();
}
}
}
53 changes: 53 additions & 0 deletions public/usage-examples/utilities/split_text-1-example-top-level.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

Color BlendColors(Color c1, Color c2, double t)
{
// linear interpolation for RGB channels
int r = (int)((1 - t) * RedOf(c1) + t * RedOf(c2));
int g = (int)((1 - t) * GreenOf(c1) + t * GreenOf(c2));
int b = (int)((1 - t) * BlueOf(c1) + t * BlueOf(c2));
return RGBColor(r, g, b);
}

OpenWindow("Split Text Example", 800, 400);

// I am defining the text to split
string text = "apple,banana,carrot";

// I am splitting the string into parts using SplashKit's split() function
string[] parts = Split(text, ',');

// I am drawing a gradient background manually
Color top = RGBColor(245, 251, 255);
Color bottom = RGBColor(200, 230, 255);

for (int y = 0; y < 400; y++)
{
double t = (double)y / 400.0;
Color blended = BlendColors(top, bottom, t);
DrawLine(blended, 0, y, 800, y);
}

DrawText("Original string:", ColorDarkBlue(), "arial", 20, 60, 50);
DrawText(text, ColorBlack(), "arial", 20, 280, 50);

// I am printing each token from the split result
int yPos = 130;
foreach (string s in parts)
{
DrawText("Token: " + s, ColorBlack(), "arial", 18, 60, yPos);
yPos += 40;
}

DrawText("Press ESC to exit", ColorGray(), "arial", 14, 620, 360);
RefreshScreen();

// wait for quit event
while (!QuitRequested())
{
ProcessEvents();
if (KeyTyped(KeyCode.EscapeKey)) break;
}

CloseAllWindows();
56 changes: 56 additions & 0 deletions public/usage-examples/utilities/split_text-1-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "splashkit.h"
#include <vector>

color blend_colors(color c1, color c2, double t)
{
// linear interpolation for RGB channels
int r = (int)((1 - t) * red_of(c1) + t * red_of(c2));
int g = (int)((1 - t) * green_of(c1) + t * green_of(c2));
int b = (int)((1 - t) * blue_of(c1) + t * blue_of(c2));
return rgb_color(r, g, b);
}

int main()
{
open_window("Split Text Example", 800, 400);

// I am defining the text to split
string text = "apple,banana,carrot";

// I am splitting the string into parts using SplashKit's split() function
vector<string> parts = split(text, ',');

// I am drawing a gradient background manually
color top = rgb_color(245, 251, 255);
color bottom = rgb_color(200, 230, 255);

for (int y = 0; y < 400; y++)
{
double t = static_cast<double>(y) / 400.0;
color blended = blend_colors(top, bottom, t);
draw_line(blended, 0, y, 800, y);
}

draw_text("Original string:", color_dark_blue(), "arial", 20, 60, 50);
draw_text(text, color_black(), "arial", 20, 280, 50);

int y = 130;
for (string s : parts)
{
draw_text("Token: " + s, color_black(), "arial", 18, 60, y);
y += 40;
}

draw_text("Press ESC to exit", color_gray(), "arial", 14, 620, 360);

refresh_screen();

while (!quit_requested())
{
process_events();
if (key_typed(ESCAPE_KEY)) break;
}

close_all_windows();
return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions public/usage-examples/utilities/split_text-1-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from splashkit import *

def blend_colors(c1, c2, t):
# linear interpolation for RGB channels
r = int((1 - t) * red_of(c1) + t * red_of(c2))
g = int((1 - t) * green_of(c1) + t * green_of(c2))
b = int((1 - t) * blue_of(c1) + t * blue_of(c2))
return rgb_color(r, g, b)

open_window("Split Text Example", 800, 400)

# I am defining the text to split
text = "apple,banana,carrot"

# I am splitting the string into parts using SplashKit's split() function
parts = split(text, ',')

# I am drawing a gradient background manually
top = rgb_color(245, 251, 255)
bottom = rgb_color(200, 230, 255)

for y in range(400):
t = y / 400
blended = blend_colors(top, bottom, t)
draw_line(blended, 0, y, 800, y)

draw_text("Original string:", color_dark_blue(), "arial", 20, 60, 50)
draw_text(text, color_black(), "arial", 20, 280, 50)

# I am printing each token from the split result
y = 130
for s in parts:
draw_text("Token: " + s, color_black(), "arial", 18, 60, y)
y += 40

draw_text("Press ESC to exit", color_gray(), "arial", 14, 620, 360)
refresh_screen()

# wait for quit event
while not quit_requested():
process_events()
if key_typed(KeyCode.escape_key):
break

close_all_windows()
1 change: 1 addition & 0 deletions public/usage-examples/utilities/split_text-1-example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Split Text Example