forked from splashkit/splashkit.io-starlight
-
Notifications
You must be signed in to change notification settings - Fork 69
Added split_text usage example in all languages with consistent visua… #666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dhruvjanghu
wants to merge
1
commit into
thoth-tech:main
Choose a base branch
from
dhruvjanghu:usage-split-text
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
public/usage-examples/utilities/split_text-1-example-oop.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
53
public/usage-examples/utilities/split_text-1-example-top-level.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Split Text Example |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file has not description.