C how to draw a point / set a pixel without using a graphics library or any other library functions

I'm trying to figure out how I can draw a set of points (/ set pixels) that form a circle without using library functions.

Now getting the coordinates (x, y) of the points given by the radius is simple.

    for (x=-r; x <r; x=x+0.1) {
         y = sqrt(r*r - x*x);
         draw(x,y, 0, 0);
     }

But as soon as I get points, how you draw a circle is what confuses me. I can use the graphics library, but I want to understand how you can do this without using the graphics library

    void draw(float x, float y, float center_x, float center_y) {
          //logic to set pixel given x, y and circle center_x and center_y
          // basically print x and y on the screen say print as a dot .
          // u 'd need some sort of a 2d char array but how do you translate x and y
          // to pixel positions
    }

Can someone share links or links or explain how this works?

+5
source share
2 answers
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: , , .

:

  • (, ), x y
  • : , Nexus 7 Nexus 10, ( ).

, . , ( , ), , , (, , ). ( )

-

  • world-to-display-coord: display-x = world-x * factor ( ).
  • : display-X +

.. " " ""

+6

, C /. . , DOS , , , . , , .

, stdio, stdout ascii, , , xbm, . .

Bresenham. , , 1 15 !

+2

All Articles