Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Feblex

Julia Set Calculator- Help!

This topic is 5325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been tinkering with a Julia Set generator, and I need someone to check it over for me, if possible. It works using the (a + bi) format. I'm pretty sure my math is messed up incredibly, but I don't know any good ordered pairs to test whether or not it's spitting out the correct results.
#include <stdio.h>
#include <math.h>

float TempImg[2], Img1[2], Img2[2], ImgSum[2], OrigImg[2], a,b,c,d;

int x, count;


int Julia() {

	OrigImg[1] = Img1[1];
	OrigImg[2] = Img1[2]; 

	printf("%.2f, %.2fi\n\n", Img1[1], Img1[2]);

	while (x < 5) { 

	TempImg[1] = Img1[1] * Img1[1] - Img1[2] * Img1[2];
	TempImg[2] = Img1[1] * Img1[2] + Img1[2] * Img1[1];

	ImgSum[1] = TempImg[1] + Img2[1];
	ImgSum[2] = TempImg[2] + Img2[2];

	printf("%.2f, %.2fi\n\n", ImgSum[1], ImgSum[2]);

	Img1[1] = ImgSum[1];
	Img1[2] = ImgSum[2];

	x++;

	}

	return 1; 

}

void main() {

	printf("Julia Set Calculator\n");
	printf("--------------------- \n\n");

	printf("Imaginary Number 1 (Variable): \n\n");

	printf("Enter a: ");
	scanf("%f", &a);

	printf("Enter b: ");
	scanf("%f", &b);

	printf("\n\nImaginary Number 2 (Constant) \n\n");

	printf("Enter c: ");
	scanf("%f", &c);

	printf("Enter d: ");
	scanf("%f", &d);

	printf("\n\n");

	Img1[1] = a;
	Img1[2] = b;

	Img2[1] = c;
	Img2[2] = d;

	Julia();

	printf("\nIterations: %f\n\n", x);
	
}
  
[edited by - mrbugg on January 14, 2004 12:48:57 AM]

Share this post


Link to post
Share on other sites
Advertisement
(a+bi)^2=(a^2-b^2) + 2*a*b*i
ie.. I think... tempImg[2]=2.0f*Img1[1]*Img1[2];
you just messed up your complex squaring I think.
Also.. your loop is basically a for loop.. so why not make it a for loop?

EDIT: oops, thats what you are doing... well in any case.. the way I wrote it is faster.. and exactly the same, as multiplcation of reals is commutative. Why not just go ahead and make a plot.. that'll confirm it's correct. you need an escape condition however... just doing 5 iterations for each point is not going to give you anything worth plotting. You usually set a max iteration count.. and have a separate escape condition. If it hits max iterations without escaping.. it's in the set.. otherwise it's not (Julia set is all points which do not diverge under that iteration).

[edited by - dmounty on January 15, 2004 9:29:26 AM]

Share this post


Link to post
Share on other sites
Thank you! Yeah, I''ll definitely use your method of calculation rather than my own. My math skills are terrible, but I have an interest in the imaginary numbers, so I''m trying to tough it out.

Yeah, the 5 iterations was only a test for now, same with the escape condition not being there. Now that I have a better way to do the math, I can worry about setting up an actual Julia generator.

Thank you for your help! It''s greatly appreciated, especially since I know next to nothing about math!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!