From 66e341a7b2d0c4e9e16c7b9ca014bb34c35cc223 Mon Sep 17 00:00:00 2001 From: dhruvjanghu Date: Mon, 6 Oct 2025 02:19:44 +1100 Subject: [PATCH] Added split_text usage example in all languages with consistent visuals and structure --- .../utilities/split_text-1-example-oop.cs | 82 ++++++++++++++++++ .../split_text-1-example-top-level.cs | 53 +++++++++++ .../utilities/split_text-1-example.cpp | 56 ++++++++++++ .../utilities/split_text-1-example.png | Bin 0 -> 6855 bytes .../utilities/split_text-1-example.py | 45 ++++++++++ .../utilities/split_text-1-example.txt | 1 + 6 files changed, 237 insertions(+) create mode 100644 public/usage-examples/utilities/split_text-1-example-oop.cs create mode 100644 public/usage-examples/utilities/split_text-1-example-top-level.cs create mode 100644 public/usage-examples/utilities/split_text-1-example.cpp create mode 100644 public/usage-examples/utilities/split_text-1-example.png create mode 100644 public/usage-examples/utilities/split_text-1-example.py create mode 100644 public/usage-examples/utilities/split_text-1-example.txt diff --git a/public/usage-examples/utilities/split_text-1-example-oop.cs b/public/usage-examples/utilities/split_text-1-example-oop.cs new file mode 100644 index 000000000..30c1af678 --- /dev/null +++ b/public/usage-examples/utilities/split_text-1-example-oop.cs @@ -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(); + } + } +} diff --git a/public/usage-examples/utilities/split_text-1-example-top-level.cs b/public/usage-examples/utilities/split_text-1-example-top-level.cs new file mode 100644 index 000000000..bf8c81b0b --- /dev/null +++ b/public/usage-examples/utilities/split_text-1-example-top-level.cs @@ -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(); \ No newline at end of file diff --git a/public/usage-examples/utilities/split_text-1-example.cpp b/public/usage-examples/utilities/split_text-1-example.cpp new file mode 100644 index 000000000..4ecbcb380 --- /dev/null +++ b/public/usage-examples/utilities/split_text-1-example.cpp @@ -0,0 +1,56 @@ +#include "splashkit.h" +#include + +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 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(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; +} diff --git a/public/usage-examples/utilities/split_text-1-example.png b/public/usage-examples/utilities/split_text-1-example.png new file mode 100644 index 0000000000000000000000000000000000000000..3dbd39ff10ed601614a7ec71b9ec84b7f82bb45b GIT binary patch literal 6855 zcmb7Id0bOh+P)4gbc#YPwF(GKwbikp2#A0z(TZqCfhvSWmRJ!%!y-c111O&*$dX!$ z2pG_zf)F7FWJ`d6vYD{T5+H;i5s)lEzz|4CGWQ0*-^Y~NZ{`m|F84j>yyrd7^SsX? z`3HxSTRzqL6aauN-=DHQ2LMW10I=!NC(7Vo(8m)P;IB=g=T3eHly&W#0Uti{J7#|j z0Ek%C)gM0wpZ|L8lzS)usJ(!GHnjymz61bTp5NOZbB^@pGnv>g>A1b~2vg+CFW&Nq6DscQY4{0V6dy6sD_^}9F!HSUi87Gj z`}&1CEOlmPraUsQsi~<(E|btEEIIkInSAz)TpSiKd+@Fv4E3#d48L+YI9?Rt3rCbB zCnpaR6N6jg#T|%d)tGc!(}OXA9!AQmDOtw-zXJ^~& zgEtgy)=E;>ORtX+b@8$3>0S8XiWt$X8zl~HCG2++JXbYr?&4Ci6^jOuQEvQBGT8#~k0J9#c%F7e$40M*086@Kg{ z6+K?f{R@{b?>XRE^O^SHfWPBs9}Ap{CNi@S>A`VakNi)ynH;g{XIqU-EH&VjyVAYx zr}}7Q2*&y!Mam0O1WlQ$A(Pa-TPsW^Lx>j#ifI2}v)Li@<4rqsbkcfzdn2c^{U#c3 zDEU^Dh0l&!Y&Txw4Qs?K@%H65Pj%)_cM;>H;vu5X$<*}p1Ll`@+QgcBN4~xVmRM|6 zP*4!@H3-b7%bPcEwuQq>8Mn9TQ>Rj%Pub^A(>wJdXkUmMvmVoXJIfyH6cEAVh-NO!a~!d zDj?gn8azt#cv&oOtlqMNr&F=mHp4hU z%FwebPCKn4ug%tVa+wu=j&-837=f5eXp>1LKG&}sJLKC~i>xaPr^UsTwwEtoLV3i#Rz+Yi7$p_84juU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