Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw shapes using C language without graphics library [closed]

Tags:

c

I have to make console program which will draw circle, line, parabola I made it using graphics library but my teacher asked me to make it without any library.

I have tried a lot without any result, I don't know how to draw it without graphics library

This is my code:

#include<graphics.h>

draw_line(int a,int b){
    int y;int x=3;
    for(x=-2;x<=2;x++)
    {
        y=a*x+b;
        moveto(x,y);

        printf("*");
    }
}

draw_circle(a,b,r){
    float newx;float newy;
    float angle;
    for(angle=0;angle<=360;angle+=0.1)
    {
        newx=a+cos(radians)*r;
        newy=b+sin(radians)*r;

        moveto(newx,newy);
        printf("*");
    }
}
draw_parabola(int a,int b,int c)
{

    float x; float y;
    for(x=0.0;x<=2.0;x+=0.1){

       y = (float) pow((float) a*x,2)+(float) pow((float) b*x,2)+c;
       printf("%f",y);printf("\n");
       printf("%f",x);printf("\n");

    }
}
like image 281
M.Bwe Avatar asked Dec 06 '25 09:12

M.Bwe


1 Answers

my teacher asked me to make it without any library.

You could do ASCII art, like answered here.

Otherwise, study the C11 standard n1570. You'll see that graphics is not standardized in C. So you then have to write some implementation specific code.

On current desktop and laptop operating systems (Linux, Windows, MacOSX, ...) and computers, the graphics hardware is very complex and accessible thru several complex layers of software. It is not reasonable to avoid all of them. See also this.

You could ask your teacher if you are allowed to use some portable library like GTK, SDL, libcairo.... or you could feed some existing graphical program (e.g. gnuplot, dot, ....) with data.

BTW, your code should declare all your routines as giving void, e.g.
void draw_line(int a,int b); etc...

like image 119
Basile Starynkevitch Avatar answered Dec 08 '25 22:12

Basile Starynkevitch