user3676127 user3676127 - 1 year ago 92
C Question

Math Functions graph in c

I'm new here, I searched for any related post like my question and I found nothing
I have a project to create a math function graph in a console like f(x)=ax^2+bx+c the user give me a b c and I draw the function.
Someone told me that there are a library called graphic.h that help me with that
so if someone can help me, I'm not finding anything about graphic.h and my project
And if there are another library or anything that could help

Answer Source

Sorry for incomplete answer but you have incomplete question so it is impossible to answer ...

What environment you have to use ? You wrote console but what compiler and OS ? because graphics is very different for each

  1. DOS

    many schools still use DOS console apps which is not the same as win or linux console. In DOS there is graphics.h which switch to gfx video mode and then you can use CGA/EGA/VGA and sometimes VESA graphics. Haven't done anything in it since Turbo Pascal 7.0 few decades ago.

    for DOS I am using direct VGA/VESA access instead (works on win32 too) but anyway look here and here for info about graphics.h with examples.

    graphics.h stands for BGI (Borland Graphics Interface) but you need CGA/EGA/VGA or VESA for proper functionality. Most gfx cards emulate them so that should be no problem just do not expect any arbitrary pixel or color resolution. It can handle 640x480x16 or 320x200x256 and the rest depends on your HW. This lib is native only to ancient Borland/Embarcadero compilers so you will find it somewhere in include path so use < > not " " !!! (you do not need to copy it to your project).

    #include <graphics.h>
  2. Windows

    You have to create graphics window by WinApi or by IDE of your programing language and then you can use GDI which is part of WinAPI and most compilers have libs for it natively.

  3. linux or different GUI OS

    I do not code for such so I do not know exactly but should be similar to Windows

  4. OpenGL (any GUI OS and also sometimes DOS with proper drivers)

    if you use OpenGL then you can find tons of examples how to create gfx window + OpenGL and also OpenGL GLUT (OpenGL utilities) have functions that take care of windows stuff. You just code code for events like keystroke, mouse move, redraw ...

    google NeHe OpenGL tutorials ... not my favorite but beginners like it

Look here for some more info

Now for the function plot

  1. clear gfx screen
  2. create for loop from xmin to xmax
  3. compute y value for each x

    do not forget to scale and offset x,y values to fit your gfx area !!!

  4. draw line from previous to actual point

    with different color than clear ...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download