Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ library for drawing graphics [closed]

Someone can suggest me a good, free, easy to use library for c++ that allow to draw a mathematical function in a window for microsoft windows? (e.g. the parabola x^2+5x+3=0)

like image 675
BlackShadow Avatar asked Nov 28 '22 22:11

BlackShadow


2 Answers

Since you need a ready-made plotting widget, use Qwt.

It uses Qt.

You could use Qt directly as in contero's answer, without Qwt, as the task is simple enough. However, Qwt has lots of graph features built in, and the usage is straightforward.

plot

like image 133
Stefan Monov Avatar answered Dec 09 '22 21:12

Stefan Monov


I wrote a program similar to this using Qt. Qt is wonderful once you get it set up, but it may take a bit of effort if you've never used it (as will OpenGL, DirectX, etc..).

You can create a QImage and set it to whatever background color you want, then run your program through the width of the image pixel by pixel calling your function to get the y value. Roughly:

for (int i = 0; i < imageWidth; i++) {
   image->setPixel(i, yourFunction(i), lineColor);
}

Once you've created your QImage, you can attach it to a QLabel using setPixmap(). Once you've attached it you can then display the image in a layout.

like image 21
contero Avatar answered Dec 09 '22 20:12

contero