Login Register






[C] Loading Animation filter_list
Author
Message
[C] Loading Animation #1
A simple loader animation I wrote for Windows. Smile

[
Code:
cpp]#include <stdio.h> #include <stdlib.h> #include <windows.h> void print_progress(int percent) { const int mul = 2; // width factor percent = min(100, percent); // spinning animation static int spin_index = 0; char spinning[] = "_-\\|/-"; // bar filler int len = (percent * mul / 10) + 1; char *bar = malloc(len); memset(bar, '<', len - 1); bar[len - 1] = 0; // write display printf("%c Loading: [%*s] %*d%%\r", percent == 100 ? ' ' : spinning[spin_index], mul * 10, bar, 3, percent ); spin_index = (spin_index + 1) % strlen(spinning); free(bar); } int main() { printf("\nStarting Loader...\n"); for (int i = 10; i <= 100; i += 5) { print_progress(i); Sleep(150); } printf("\nDone...\n"); }

edit: Wow, ugly ass, and poor, syntax highlighting... Not to mention slow.

[Image: uNEtxbZ.gif]
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply





Messages In This Thread
[C] Loading Animation - by ArkPhaze - 05-25-2014, 08:10 PM