Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4000742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:49:09+00:00 2026-05-20T07:49:09+00:00

I was asked to display the Mandelbrot set on Java but I have encountered

  • 0

I was asked to display the Mandelbrot set on Java but I have encountered a problem. My teacher and I both are stumped to why this doesn’t run correctly.

I reckon it has something to do with the algorithm or the complex class since all values except positive/negative 1 and 0 escape to infinity after two iterations.

import javax.swing.*;
import java.awt.*;

public class fractal {

        public class complex { double re; double im;
                public complex(double x, double y){
                    this.re =x;
                    this.im =y;
                }
                public double mag(){
                    return (Math.sqrt(re*re+im*im));
                }
        }


static int xcord = 500;
static int ycord = 500;

 public static void main(String[] args) {   
        JFrame myFrame = new JFrame("Question 10");
        myFrame.setSize(xcord,ycord);
        JPanel myPane = (JPanel) myFrame.getContentPane();
        myPane.add(new paint());
        myFrame.setVisible(true);
    }
}

class paint extends JComponent {

        public complex add(complex a, complex b){
            return new complex(a.re+b.re,a.im+b.im);
            }
         public complex multiply(complex a,complex b) {
              return new complex((a.re*b.re)-(a.im*b.im),(a.re*b.im)+(a.im*b.re));
            }




public void paint (Graphics g){

    final int SCALE =100; //pixels per unit
    int itr = 0;
    int max_itr = 30;
    Color clr = Color.black;
    g.translate(fractal.xcord/2, fractal.ycord/2); // Move origin to center of frame


    for (int x = -2*SCALE; x <= 1*SCALE; x++){

        for (int y = -1*SCALE; y <= 1*SCALE; y++){

            complex C = new complex(x/SCALE,y/SCALE); // math done on unscaled values
            complex z = C;
            itr = 0;

            while ( z.mag() <= 4.0 && itr < max_itr){ 

                z = add(multiply(z,z),C);   
                itr++;

                }

            if (itr == max_itr){
                clr = Color.black;
            }

            else{
                clr = new Color((int) Math.round(itr*8.5),(int) Math.round(itr*8.5),(int) Math.round(itr*8.5)); // Colouring of fractal
            }

            g.drawOval(x, y, 2, 2);
            g.setColor(clr);

            }
        }
    } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:49:10+00:00Added an answer on May 20, 2026 at 7:49 am

    I think that you have to wide boundaries. [-200,100], where you should have [-2,1] for Re and [-1,1] for Im.

    complex C = new complex(x/SCALE,y/SCALE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this question someone asked for ways to display disk usage in Linux. I'd
(I asked this question in another way , and got some interesting responses but
I've been asked to display the 'correct' time on our website which I frankly
I asked a somewhat related question but I want it to make it more
I asked before about pixel-pushing, and have now managed to get far enough to
I was asked to display the tech design of my JSF application with Visio.
I'm being asked to display a binary search tree in sorted order. The nodes
I asked a question regarding how to display aspx and cs code on page,
i was recently asked why a tumblr theme of mine does not display Vietnamese
Im working on an edit/display mode switch of MasterPage and PageLayout. I asked a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.