CDM  v0.9
Console Draw Motor, C librarly for quickly developing Windows console applications with advanced graphics. https://github.com/komo97/CDM
main.cpp

This is an example of most all capabilities of CDM being put to use.

#include "CDM.h"
#include <string>
#define SQR_X 15
#define SQR_Y 15
int main()
{
int horSpeed = 1, verSpeed = 1;
CDMSetWindowTitle(L"Testing");
CDMSetFontAndSize(&ctx, L"Terminal", 8, 8);
CDMChangeWindowSize(&ctx, 80, 80);
CDMColorScheme mainColor;
CDMSetColorBin(&mainColor, 0, 0x00362b00);
CDMSetColorBin(&mainColor, 1, 0x00423607);
CDMSetColorBin(&mainColor, 2, 0x00756e58);
CDMSetColorBin(&mainColor, 3, 0x00837b65);
CDMSetColorBin(&mainColor, 4, 0x00969483);
CDMSetColorBin(&mainColor, 5, 0x00a1a193);
CDMSetColorBin(&mainColor, 6, 0x00d5e8ee);
CDMSetColorBin(&mainColor, 7, 0x00e3f6fd);
CDMSetColorBin(&mainColor, 8, 0x000089b5);
CDMSetColorBin(&mainColor, 9, 0x00164bcb);
CDMSetColorBin(&mainColor, 10, 0x002f32dc);
CDMSetColorBin(&mainColor, 11, 0x008236d3);
CDMSetColorBin(&mainColor, 12, 0x00c4716c);
CDMSetColorBin(&mainColor, 13, 0x00d28b26);
CDMSetColorBin(&mainColor, 14, 0x0098a12a);
CDMSetColorBin(&mainColor, 15, 0x00009985);
CDMSurface* square = CDMCreateSurface(0, 0, SQR_X, SQR_Y);
CDMSetCharacters(&square, 'T', 'E', 'S', 'T');
for (int i = 0; i < SQR_Y; ++i)
{
for (int j = 0; j < SQR_X; ++j)
{
int randNum = rand() % 100;
if (randNum < 25)
CDMSetPixel(&square, j, i, Set1);
else if(randNum < 50)
CDMSetPixel(&square, j, i, Set2);
else if (randNum < 75)
CDMSetPixel(&square, j, i, Set3);
else if (randNum < 100)
CDMSetPixel(&square, j, i, Set4);
}
}
CDMText* scrSize = CDMTextWrapper((char*)(std::string("Screen size = ") + std::to_string(ctx->rect.Right) +
", " + std::to_string(ctx->rect.Bottom) +
std::string("Press 0 to use the main palette, press 1 to change to a random palette")).data(), CDMLetterColor::WHITE, CDMBackgroundColor::BBLACK);
CDMPrepareText(&scrSize);
scrSize->rect.Left = txt->rect.Right + 1;
while (true)
{
CDMPollEvents(ctx, &ctx->events);
CDMKeepScreenSize(&ctx, &ctx->events);
CDMPrepareText(&scrSize);
if (square->rect.Left < 0)
{
square->rect.Left = 0;
horSpeed = (horSpeed / abs(horSpeed)) * ((rand() % 5) + 1);
horSpeed *= -1;
}
else if (square->rect.Left + square->rect.Right > ctx->rect.Right)
{
square->rect.Left = ctx->rect.Right - square->rect.Right;
horSpeed = (horSpeed / abs(horSpeed)) * ((rand() % 5) + 1);
horSpeed *= -1;
}
if (square->rect.Top < 0)
{
square->rect.Top = 0;
verSpeed = (verSpeed / abs(verSpeed)) * ((rand() % 5) + 1);
verSpeed *= -1;
}
else if (square->rect.Top + square->rect.Bottom > ctx->rect.Bottom)
{
square->rect.Top = ctx->rect.Bottom - square->rect.Bottom;
verSpeed = (verSpeed / abs(verSpeed)) * ((rand() % 5) + 1);
verSpeed *= -1;
}
{
CDMSetActiveScheme(mainColor, &ctx);
}
{
CDMColorScheme randScheme;
for (int i = 0; i < 15; ++i)
CDMSetColorRGB(&randScheme, i, rand() % 255, rand() % 255, rand() % 255);
CDMSetActiveScheme(randScheme, &ctx);
}
{
CDMFreeSurface(&square);
break;
}
square->rect.Left += horSpeed;
square->rect.Top += verSpeed;
CDMAddSurfaceToContext(&ctx, square);
CDMAddTextToContext(&ctx, txt);
CDMAddTextToContext(&ctx, scrSize);
CDMDraw(&ctx);
Sleep(16);
}
return 0;
}