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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// I am showing a circle that can toggle fill, cycle colors, and pulse (OOP form).
// I am pressing SPACE to toggle fill; I am pressing C to change color;
// I am pressing P to pulse; I am pressing ESC to quit.

using System;
using SplashKitSDK;

namespace GraphicsExamples
{
public class DrawCircleFillToggle
{
private const int W = 720, H = 405;
private readonly int _cx = W / 2;
private readonly int _cy = H / 2;
private const double BaseRadius = 80.0;

private readonly SplashKitSDK.Color[] _palette =
{
SplashKit.RGBColor(100, 149, 237),
SplashKit.RGBColor(255, 140, 0),
SplashKit.RGBColor(46, 204, 113),
SplashKit.RGBColor(155, 89, 182),
SplashKit.RGBColor(241, 196, 15),
};
private int _colorIndex = 0;

private bool _isFilled = false;
private bool _isPulsing = false;
private double _t = 0.0;

public void Run()
{
SplashKit.OpenWindow("Circle - fill / color / pulse", W, H);

while (!SplashKit.QuitRequested())
{
SplashKit.ProcessEvents();

if (SplashKit.KeyTyped(KeyCode.EscapeKey))
{
break;
}
if (SplashKit.KeyTyped(KeyCode.SpaceKey))
{
_isFilled = !_isFilled;
}
if (SplashKit.KeyTyped(KeyCode.CKey))
{
_colorIndex = (_colorIndex + 1) % _palette.Length;
}
if (SplashKit.KeyTyped(KeyCode.PKey))
{
_isPulsing = !_isPulsing;
}

SplashKit.ClearScreen(SplashKit.ColorWhite());

double radius = BaseRadius;
if (_isPulsing)
{
radius = BaseRadius + 12.0 * Math.Sin(_t);
_t = _t + 0.07;
}

var ink = _palette[_colorIndex];

if (_isFilled)
{
SplashKit.FillCircle(ink, _cx, _cy, radius);
SplashKit.DrawCircle(SplashKit.ColorBlack(), _cx, _cy, radius);
}
else
{
SplashKit.DrawCircle(ink, _cx, _cy, radius);
}

SplashKit.DrawText("SPACE: fill C: color P: pulse ESC: quit",
SplashKit.ColorNavy(), 16, 16);
SplashKit.DrawText(_isFilled ? "Mode: filled" : "Mode: outline",
SplashKit.ColorBlack(), 16, 40);

SplashKit.RefreshScreen(60);
}
}

public static void Main()
{
new DrawCircleFillToggle().Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// I am showing a circle that can toggle fill, cycle colors, and pulse.
// I am pressing SPACE to toggle fill; I am pressing C to change color;
// I am pressing P to pulse; I am pressing ESC to quit.

#include "splashkit.h"
#include <cmath>
#include <vector>

int main()
{
// I am opening a window with an ASCII title.
const int window_width = 720, window_height = 405;
open_window("Circle - fill / color / pulse", window_width, window_height);

// I am keeping the circle centered.
const int center_x = window_width / 2;
const int center_y = window_height / 2;
const double base_radius = 80.0;

// I am using a small palette to keep the demo friendly.
std::vector<color> palette = {
rgb_color(100, 149, 237), // cornflower
rgb_color(255, 140, 0), // dark orange
rgb_color(46, 204, 113), // emerald
rgb_color(155, 89, 182), // amethyst
rgb_color(241, 196, 15) // sunflower
};
int color_index = 0;

// I am tracking fill/pulse state and a time value for pulsing.
bool is_filled = false;
bool is_pulsing = false;
double t = 0.0;

while (!quit_requested())
{
process_events();

// I am handling the controls.
if (key_typed(ESCAPE_KEY))
{
break;
}
if (key_typed(SPACE_KEY))
{
is_filled = !is_filled;
}
if (key_typed(C_KEY))
{
color_index = (color_index + 1) % static_cast<int>(palette.size());
}
if (key_typed(P_KEY))
{
is_pulsing = !is_pulsing;
}

clear_screen(COLOR_WHITE);

// I am computing a gentle "breathing" radius when pulsing.
double radius = base_radius;
if (is_pulsing)
{
radius = base_radius + 12.0 * std::sin(t);
t = t + 0.07;
}

const color ink = palette[static_cast<size_t>(color_index)];

if (is_filled)
{
fill_circle(ink, center_x, center_y, radius);
draw_circle(COLOR_BLACK, center_x, center_y, radius); // I am adding a subtle outline.
}
else
{
draw_circle(ink, center_x, center_y, radius);
}

// I am drawing the HUD (on-window text).
draw_text("SPACE: fill C: color P: pulse ESC: quit",
COLOR_NAVY, 16, 16);
draw_text(is_filled ? "Mode: filled" : "Mode: outline",
COLOR_BLACK, 16, 40);

refresh_screen(60);
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// I am showing a circle that can toggle fill, cycle colors, and pulse.
// I am pressing SPACE to toggle fill; I am pressing C to change color;
// I am pressing P to pulse; I am pressing ESC to quit.

using System;
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

OpenWindow("Circle - fill / color / pulse", 720, 405);

// I am keeping the circle centered.
int cx = 720 / 2;
int cy = 405 / 2;
double baseRadius = 80.0;

// I am using a small palette for clarity.
Color[] palette =
{
RGBColor(100, 149, 237), // cornflower
RGBColor(255, 140, 0), // dark orange
RGBColor(46, 204, 113), // emerald
RGBColor(155, 89, 182), // amethyst
RGBColor(241, 196, 15) // sunflower
};
int colorIndex = 0;

// I am tracking state and a time value for pulsing.
bool isFilled = false;
bool isPulsing = false;
double t = 0.0;

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

if (KeyTyped(KeyCode.EscapeKey))
{
break;
}
if (KeyTyped(KeyCode.SpaceKey))
{
isFilled = !isFilled;
}
if (KeyTyped(KeyCode.CKey))
{
colorIndex = (colorIndex + 1) % palette.Length;
}
if (KeyTyped(KeyCode.PKey))
{
isPulsing = !isPulsing;
}

ClearScreen(ColorWhite());

double radius = baseRadius;
if (isPulsing)
{
radius = baseRadius + 12.0 * Math.Sin(t);
t = t + 0.07;
}

Color ink = palette[colorIndex];

if (isFilled)
{
FillCircle(ink, cx, cy, radius);
DrawCircle(ColorBlack(), cx, cy, radius); // I am adding a subtle outline.
}
else
{
DrawCircle(ink, cx, cy, radius);
}

DrawText("SPACE: fill C: color P: pulse ESC: quit",
ColorNavy(), 16, 16);
DrawText(isFilled ? "Mode: filled" : "Mode: outline",
ColorBlack(), 16, 40);

RefreshScreen(60);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# pyright: reportMissingImports=false, reportUndefinedVariable=false
from splashkit import *
from splashkit import KeyCode
from math import sin

window_width, window_height = 720, 405
open_window("Circle — fill / color / pulse", window_width, window_height)

center_x = window_width // 2
center_y = window_height // 2
base_radius = 80.0

palette = [
rgb_color(100, 149, 237),
rgb_color(255, 140, 0),
rgb_color(46, 204, 113),
rgb_color(155, 89, 182),
rgb_color(241, 196, 15),
]
color_index = 0
is_filled = False
is_pulsing = False
time_value = 0.0

font_ok = False
try:
ui_font = load_font("Demo", "arial.ttf")
font_ok = True
except Exception:
ui_font = None

while not quit_requested():
process_events()
if key_typed(KeyCode.escape_key): break
if key_typed(KeyCode.space_key): is_filled = not is_filled
if key_typed(KeyCode.c_key): color_index = (color_index + 1) % len(palette)
if key_typed(KeyCode.p_key): is_pulsing = not is_pulsing

clear_screen(color_white())

radius = base_radius
if is_pulsing:
radius = base_radius + 12.0 * sin(time_value)
time_value += 0.07

circle_color = palette[color_index]
if is_filled:
fill_circle(circle_color, center_x, center_y, radius)
draw_circle(color_black(), center_x, center_y, radius) # subtle outline
else:
draw_circle(circle_color, center_x, center_y, radius)

if font_ok:
draw_text("SPACE: fill C: color P: pulse ESC: quit", color_navy(), ui_font, 16, 16, 16)
draw_text("Mode: filled" if is_filled else "Mode: outline", color_black(), ui_font, 16, 16, 40)

refresh_screen()
delay(16)

close_all_windows()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am showing a circle that can toggle fill, cycle colors, and pulse. I am pressing SPACE to toggle fill; I am pressing C to change color; I am pressing P to pulse; I am pressing ESC to quit.