i need someone to fix my code,
its about 90% complete
willing to pay fg
please post
So the code below should be generates Julia Sets like this one:

So if you input the values:
CReal: 0.3
CImag: 0.0
Xmin: -2.0
Xmax: 2.0
Ymin: -2.0
Ymax: 2.0
WhateverName.jpg
it should print out the picture above.
But my code prints out a plain red screen.
I think the problem is within the While loop but i can't find the problem
So if someone can find it that would be very helpful. Here my code:import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.*;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
import javax.imageio.stream.ImageOutputStream;
public class Julia {
public static void main( String[] args) throws Exception
{
Scanner scan = new Scanner( System.in );
double CReal, CImag, Xmin, Xmax, Ymin, Ymax;
int width = 512;
int height = 512;
BufferedImage outImage = new BufferedImage( width, height, BufferedImage.TYPE_3BYTE_BGR );
System.out.println("Input: CReal CImag Xmin Xmax Ymin Ymax fname");
CReal = scan.nextDouble();
CImag = scan.nextDouble();
Xmin = scan.nextDouble();
Xmax = scan.nextDouble();
Ymin = scan.nextDouble();
Ymax = scan.nextDouble();
String fname = scan.next();
Complex C = new Complex(CReal, CImag);
for(int x=0; x<height; x++ ) {
for(int y=0; y<width; y++) {
double zReal = Xmin + x*((Xmax-Xmin)/512);
double zImag = Ymin + y*((Ymax-Ymin)/512);
// Create new complex number called z
Complex Z = new Complex(zReal,zImag );
int iterations = juliaCalc(Z , C);
int pixelcolor = getHSBColor(iterations);
outImage.setRGB(x, y, pixelcolor);
//System.out.println(pixelcolor);
}
}
saveImage(outImage, new File( fname ));
}
public static void saveImage( BufferedImage img, File file ) throws IOException{
ImageWriter writer = null;
java.util.Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
if( iter.hasNext() ){
writer = (ImageWriter)iter.next();
}
ImageOutputStream ios = ImageIO.createImageOutputStream( file );
writer.setOutput(ios);
ImageWriteParam param = new JPEGImageWriteParam( java.util.Locale.getDefault() );
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
param.setCompressionQuality(0.98f);
writer.write(null, new IIOImage( img, null, null ), param);
}
public static int juliaCalc(Complex Z, Complex C) {
int iterations = 0;
// Complex i = Z.multiply(Z);
// Complex j = i.add(C);
Complex k = Z.multiply(Z).add(C);
//System.out.println(k);
//for(iterations = 0; iterations < 256; iterations++) {
while (k.magnitude() < 2.0)
{
if(iterations > 255)
break;
else{
Z = Z.multiply(Z).add(C);
//System.out.println(Z);
iterations++;
}
}
// }
System.out.println(iterations);
return iterations;
}
public static int getHSBColor(int idx)
{
return Color.getHSBColor((float)(idx/255.0), 1.0f, 1.0f).getRGB();
}
}
class Complex
{
double real;
double imaginary;
Complex(double r, double i)
{
real = r;
imaginary = i;
}
//the calculation of magnitude
public double magnitude()
{
double mag = 0;
mag = Math.sqrt(Math.pow(this.real, 2) + Math.pow(this.imaginary, 2));
return mag;
}
//the calculation of multiplication
public Complex multiply(Complex toMultiply)
{
double realMultiComponent;
double imaginaryMultiComponent;
realMultiComponent = this.real * toMultiply.real - this.imaginary * toMultiply.imaginary;
imaginaryMultiComponent = this.imaginary * toMultiply.real + this.real * toMultiply.imaginary;
Complex multiplied = new Complex(realMultiComponent, imaginaryMultiComponent);
return multiplied;
}
//the calculation of addition
public Complex add(Complex toAdd)
{
double realAddComponent;
double imaginaryAddComponent;
realAddComponent = this.real + toAdd.real;
imaginaryAddComponent = this.imaginary + toAdd.imaginary;
Complex added = new Complex(realAddComponent, imaginaryAddComponent);
return added;
}
}
This post was edited by CiroC on Feb 27 2014 10:02pm