I am trying to understand how I can draw a set of points (/set the pixels) that form a circle without using the library functions.
Now, getting the (x,y) co-ordinat
I have a file that takes advantage of unicode braille.
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#define PIXEL_TRUE 1
#define PIXEL_FALSE 0
// Core Function.
void drawBraille(int type) {
if(type > 255) {
return;
}
setlocale(LC_CTYPE, "");
wchar_t c = 0x2800 + type;
wprintf(L"%lc", c);
}
/*
Pixel Array.
0x01, 0x08,
0x02, 0x10,
0x04, 0x20,
0x40, 0x80,
*/
int pixelArr[8] = {
0x01, 0x08,
0x02, 0x10,
0x04, 0x20,
0x40, 0x80
};
typedef int cell[8];
void drawCell(cell cell) {
int total;
for(int i = 0; i < 8; i++) {
if(cell[i] == 1) {
total += pixelArr[i];
}
}
drawBraille(total);
}
// Main.
int main(void) {
cell a = {
0, 1,
0, 0,
1, 1,
0, 1
};
drawCell(a);
return 0;
}
You're Welcome!
char display[80][26];
void clearDisplay(void) {
memset(display, ' ', sizeof(display));
}
void printDisplay(void) {
for (short row=0; row<26; row++) {
for (short col=0; col<80; col++) {
printf("%c", display[col][row]);
}
printf("\n");
}
}
void draw(float x, float y, float center_x, float center_y) {
if (visible(x,y)) {
display[normalize(x)][normalize(y)] = '.';
}
}
EDITH: you changed your comment, to incorporate more of your question, so I will expand my answer a bit.
you have two sets of coordinates:
you need a metric, that transforms your world coordinates into display coordinates. To make things more complicated, you need a window (the part of the world you want to show the user) to clip the things you do cannot show (like africa, when you want to show europe). And you may want to zoom your world coordinates to match your display coordinates (how much of europe you want to display)
These metrics and clippings are simple algebraic transformations
and so on. Just wikipedia for "alegebraic transformation" or "geometrics"
It's a tough question because technically C doesn't have any built-in input/output capability. Even writing to a file requires a library. On certain systems, like real-mode DOS, you could directly access the video memory and set pixels by writing values into that memory, but modern OSes really get in the way of doing that. You could try writing a bootloader to launch the program in a more permissive CPU mode without an OS, but that's an enormous can of worms.
So, using the bare mimimum, the stdio library, you can write to stdout using ascii graphics as the other answer shows, or you can output a simple graphics format like xbm which can be viewed with a separate image-viewing program. A better choice might be the netpbm formats.
For the circle-drawing part, take a look at the classic Bresenham algorithm. Or, for way too much information, chapter 1 of Jim Blinn's A Trip Down the Graphics Pipeline describes 15 different circle-drawing algorithms!