Project: fractal generating program

Started by
17 comments, last by Robin S 17 years, 7 months ago
The inputs are nondescriptive because some of them (particularly the arrays) are used for multiple purposes in order to save on memory. It's not so much how to use if/else statements that I'm looking for - I want to know how to write to a bitmap file. In the Blitz version of the program I did this by choosing a colour, then drawing that pixel on the screen, then finally when all pixels were drawn the program saved the buffer on which the image had been drawn. However, I'd prefer to be able to write to an image file without having to display the image on the screen.

Even more ideal would be to write straight to a PNG, but I'll stick with simple things first.

To give a rough idea of what the program does:

//take inputs;//do some maths;//create and set up 24-bit bitmap file, dimensions k by l, ready to write (not yet done);for(r=0;r<k;r++){	for(s=0;s<l;s++)	{		//do some more maths;		//create pixel at r,l-s-1 coloured using v as in above post (not yet done); 		//do some more maths;	}	//do some more maths;}
Advertisement
Quote:
The inputs are nondescriptive because some of them (particularly the arrays) are used for multiple purposes in order to save on memory.


Welcome to the nineties: don't optimize at the expense of clarity unless you know it's slowing your program down. :)

Quote:I want to know how to write to a bitmap file.
Standard C++ is pretty bare bones: you need a library that handles the tedium of writing bmp's for you. Take a look at this, maybe it's adequate for your needs:

http://sourceforge.net/projects/easybmp/
Sorry, I thought you were using C++ instead of C.

I'd strongly reccommend going (at least) the C++ route: it provides the STL which is immensely more convenient than straight C arrays for doing numerical work (it handles dynamic resizing for you, gives you nice abilities for iterating, + loads of other nice containers).
I probably will rewrite it in C++ once I have a working version in C. I'll need to so that things like the GUI are easier to write. For now, though, I just want a version that works faster than the one in Basic. Thanks for the advice, though. I'll keep what you said in mind.

Meanwhile, could anyone possibly help me towards getting the C version finished?
Look at the link I provided!

just compile your C program as C++ (it's mostly backward compatible) and use the BMP library to spit it out. There's even an example mandelbrot generator on the site that does EXACTLY what you want to do:

http://easybmp.sourceforge.net/samples.html
Thanks - although what I want to do involves more than just Mandelbrot sets.

Meanwhile, I seem to be having problems with loops. The following code prints the number "3", when from what I understand it should print 012. Can anyone explain?

int main(void){	unsigned short j;	for(j=0;j<=2;j++);	{		printf("%i",j);	}	return 0;}
Semicolon after the for.
Ah, thanks. Can't believe I missed that!

Now, to continue with debugging...
I've encountered another problem: scanf appears to reset the values of some of my variables to 0, for a reason that I don't understand. For example:

		printf("width? ");		scanf("%i",&k);		printf("height? ");		printf("%i",k); // prints fine		scanf("%i",&l);		printf("%i",k); // comes out as 0

Can anyone explain why, or how to rectify this problem?

This topic is closed to new replies.

Advertisement