You are not logged in.
I've made a small API for printing graphs, using SDL in, well, C (making binds for C++ should be very easy too :V) Mostly for my own learning and benefit, but I think I can see some uses for this for others too as it is pretty simple to use, so I decided to post it here.
http://code.google.com/p/sdl-grapher/
The following documentation (in the header file) should work for a start. There is also an example.c file.
Offline
Support for printing current Graph to a .bmp file has been added via write_BMP() eg. write_BMP(&myGraph, "crazystuff.bmp"); if anyone was using this. A couple of bugs have been fixed too :') Making crazy wallpapers ftw.
Offline
Thanks Themaister, that's a really nice little lib. I have been using Xgraphics or gnuplot to plot mine, but I'll have a play with your work.
====* -- Joke
O
\|/ --- Me
/ \ Whooooosh
Offline
Been playing around with fractals, especially http://en.wikipedia.org/wiki/Mandelbrot_set. Holy tacos, it's awesome Gief fancy color shading algorithms too^^
http://maister.homelinux.org/downloads/fractal.jpg
#include <sdlgraph.h>
int main()
{
Graph a;
a.xMin = -10.0;
a.xMax = 10.0;
a.yMin = -10.0;
a.yMax = 10.0;
a.xScale = 1.0;
a.yScale = 1.0;
a.height = 1000;
a.width = 1000; // Try this with 10000*10000 and watch your CPU and harddrive cry :D 300MB .bmp ftw.
init_graph(&a);
int x, y;
float xcoor, ycoor, XTEMP, X, Y;
int iteration, max = 200;
for ( x = 0; x < 1000; x++ )
{
for ( y = 0; y < 1000; y++ )
{
xcoor = x/500.0-1.0;
ycoor = y/500.0-1.0;
iteration = 0; X = 0; Y = 0;
while ( X*X + Y*Y <= 100.0 && iteration < max )
{
XTEMP = X*X - Y*Y + xcoor;
Y = 2*X*Y + ycoor;
X = XTEMP;
iteration++;
}
if ( iteration == max )
{
set_color ( &a, 0, 0, 0);
}
else
{
set_color(&a, 255*(float)iteration/(float)max, 7+230*(float)iteration/(float)max, 11+200*(float)iteration/(float)max);
}
print_pixel_by_window(&a, x, y); // Using the windows coords rather than graph coords :p Nice for printing full pictures rather than plain graphs.
//fprintf(stderr, "Printing pixel %4d, %4d\n", x, y);
}
}
update_screen(&a);
write_BMP(&a, "fractal.bmp");
idle();
quit();
return 0;
}
Last edited by Themaister (2009-10-15 19:32:21)
Offline