-1

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 Thanks

Charles
  • 48,924
  • 13
  • 96
  • 136
hichamkazan
  • 168
  • 1
  • 7
  • 1
    Do you know something about Gnuplot ? It might help you. – Kabulan0lak May 26 '14 at 11:28
  • Perhaps something from here would help you (You mentioned something about graphic.h so I guess you want some C API): http://stackoverflow.com/questions/1275484/good-plotting-library-for-c – dragosht May 26 '14 at 11:35
  • 1
    Stack overflow does not consider questions like this to be on topic because the help you're asking for is extremely broad. Your questions here need to be concise and be able to be answered with concise responses. That is... _you_ choose your library, get started, and ask for help with specific issues rather than non-specific "how do I get started?" type things. – mah May 26 '14 at 11:43
  • I'm new to stack overflow and I'm not asking on how to start I'm asking is there a better library then graphic.h for my project – hichamkazan May 26 '14 at 15:29
  • I saw a library called mathGL does that works for me ? – hichamkazan May 26 '14 at 16:25
  • There are a lot of ways to do graphs, I prefer WinApi but it's not the simplest because you need to learn about C for windows first and then use WM_PAINT command to draw a line for every few pixels to draw something like that, for simple f(x) = ax + b you can just use a single line function but as I said it's not the simplest way. There are libraries like conio.h and graphics.h but never used them for something like this. – Survaf93 May 27 '14 at 08:09

1 Answers1

1

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 ...

Spektre
  • 41,942
  • 8
  • 91
  • 312