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


Julia Set Calculator- Help!

Recommended Posts

mrbugg    122
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];



	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);


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

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


	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
dmounty    122
(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
mrbugg    122
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