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

  • SEARCH
  • Home
  • 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 9036653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:03:16+00:00 2026-06-16T09:03:16+00:00

Okay, here’s a weird one that I’m having problems with (compiled with gcc btw)

  • 0

Okay, here’s a weird one that I’m having problems with (compiled with gcc btw)

Below is source for a Mandelbrot fractal generator for command prompt. I’ve done this before and I wanted to speed test myself to see how fast I could produce the code required to actually generate a Mandelbrot fractal in the command prompt. Every so often I do this to kinda test myself out for fun

Anyways I’ve run into a new problem and I can’t quite figure out what the issue is. When the fractal renders no matter how many iterations or what escapeValue I set it will ALWAYS appear as an oval! Its NOT supposed to do that.

For all you mandelbrot/cpp geeks out there can you help me identify why I’m not getting more of a ‘mandelbrot’ shape?

#include <stdio.h>
#include <math.h>

#define DOSWidth 80
#define DOSHeight 25

int iterations = 1024;
float escapeValue = 3.0f;

struct ivar {
    ivar(float _x, float _i) {
        x = _x;
        i = _i;
    }
    void log() {printf("(%g%c%gi)", x, (i<0)?'-':'+', fabs(i));}
    float magnitude() {return sqrtf(x*x+i*i);}
    ivar square() {return ivar(x, i)*ivar(x, i);}

    ivar operator + (ivar v) {return ivar(x+v.x, i+v.i);};
    ivar operator - (ivar v) {return ivar(x-v.x, i-v.i);};
    ivar operator * (ivar v) {return ivar(x*v.x-(i*v.i), x*v.i+i*v.x);};

    float x, i;
};

struct rect {
    rect(float _x, float _y, float _width, float _height) {
        x = _x;y = _y;width = _width;height = _height;
    }

    void setCenter(float cx, float cy) {
        x = cx-width/2.0f;
        y = cy-width/2.0f;
    }

    void log() {printf("(%f, %f, %f, %f)", x, y, width, height);}

    float x, y;
    float width, height;
};

int main() {
    rect region = rect(0, 0, 2.5f, 2.0f);
    region.setCenter(0, 0);
    float xSize = region.width / (float)DOSWidth;
    float ySize = region.height / (float)DOSHeight;
    for(int y=0;y<DOSHeight;y++) {
        for(int x=0;x<DOSWidth;x++) {
            ivar pos = ivar(x*xSize+region.x, y*ySize+region.y);
            bool escapes = false;
            for(int i=0;i<iterations;i++) {
                if(pos.magnitude() > escapeValue) {
                    escapes = true;
                    break;
                }
                pos = pos.square();
            }
            if(escapes)printf(" ");
            else printf("X");
        }
    }
}

Thanks if you got this far, appreciate your help!

  • 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-06-16T09:03:17+00:00Added an answer on June 16, 2026 at 9:03 am

    You’re just recursively squaring pos until its magnitude exceeds the limit. That won’t produce a fractal; it will produce a unit circle.

    You need to add the (x,y) coordinates to the squared value after every iteration. See Wikipedia.

    EDIT: A couple small changes and voila.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay here is what I'm trying to do: I have a model object that
Okay so here's, the scenario I have a thumbnail that contains an artists profile
Okay so here is the problem I am having. I have several unit tests
Okay so here's the scenario: User is presented with form that contains file inputs.
Sorry for the title couldn't come with a better one... Okay here's is my
Okay here's my issue. I have a block that is 348px wide, and on
Okay here's the situation. Net 4 WPF NO Silverlight. I have several Views that
Okay so here my issue, I have a list of items that when a
Okay here is the problem, I have images of different sizes, but that doesn't
Okay here's my situation. I have a php file that contains a simple form

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.