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 9194881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:31:00+00:00 2026-06-17T21:31:00+00:00

I found a project description on a course website for computer graphics. I am

  • 0

I found a project description on a course website for computer graphics. I am trying to complete the project for fun.

Here is the link to the problem description:

http://www.pdfhost.net/index.php?Action=Download&File=901bc7785bef41364b3a40f6f4493926

Below is my code. The problem I am running in to is that the terms of the series grow so fast I can’t map the points to the screen correctly. From the problem description it says the points will be mappable within a -2 – 2 square but the difference in value between the points is so huge that normalizing by the largest would collapse most of the points to a single pixel.

I assume I have a fundamental misunderstanding that I can’t identify. Any help or insight would be appreciated!

int w = 800, h = 600;
int numTimes = 10, cSize = 5;
float xr = 2, yr = 2;

void setup() {
  size(w,h);
}

void draw() {
  background(255);

  Complex v = new Complex(mouseX*(xr/w) - (xr/2), mouseY*(yr/h) - (yr/2));  
  Complex[] exps = new Complex[numTimes];

  for (int i = 0; i < numTimes; i++) {
    exps[i] = complexExp(v,i);
  }

  ellipse(w/2, h/2, cSize, cSize);
  for (int i = 0; i < numTimes; i++) {
    drawSeries(new Complex(0,0), exps, i, i);
  }
}

void drawSeries(Complex vToDraw, Complex[] exps, int count, int clrTrunc) {
  if (count == 0) {
    Complex v = exps[0];   

    float progress = float(clrTrunc) / float(numTimes);
    fill(255*progress, 180, 255 - 255*progress);

    vToDraw.add(v);
    ellipse(vToDraw.r*(w/xr) + (w/2), vToDraw.i*(h/xr) + h/2, cSize, cSize);
    vToDraw.sub(v);
    vToDraw.sub(v);
    ellipse(vToDraw.r*(w/xr) + (w/2), vToDraw.i*(h/xr) + h/2, cSize, cSize);
  } else {
    Complex v = exps[count];

    vToDraw.add(v);
    drawSeries(vToDraw, exps, count - 1, clrTrunc );
    vToDraw.sub(v);
    vToDraw.sub(v);
    drawSeries(vToDraw, exps, count - 1,clrTrunc );
  }
}

Complex complexExp(Complex v, int times) {
  if (times == 0) {
    return new Complex(1, 1);
  } else if ( times == 1) {
    return new Complex( v.r*v.r - v.i*v.i, 2*v.r*v.i );
  } else {
    return complexExp( new Complex( v.r*v.r - v.i*v.i, 2*v.r*v.i ), times - 1 );
  }
}

class Complex {
  float r, i;

  Complex() {
    this.r = 0;
    this.i = 0;
  } 

  Complex(float r, float i) {
    this.r = r;
    this.i = i;
  }

  void add(Complex nv) {
      this.r += nv.r;
      this.i += nv.i;
  }

  void sub(Complex nv) {
      this.r -= nv.r;
      this.i -= nv.i;
  }
}
  • 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-17T21:31:02+00:00Added an answer on June 17, 2026 at 9:31 pm

    I think you can make the code cleaner if you write a more complete Complex class.

    int w = 800, h = 600;
    int numTimes = 10, cSize = 5;
    float xr = 3, yr = 3;
    
    void setup() {
      size(w,h);
      noLoop();
    }
    void mousePressed() {
      redraw();
    }
    
    void draw() {
      background(255);
    
      Complex v = new Complex(mouseX*(xr/w) - (xr/2), mouseY*(yr/h) - (yr/2));  
      Complex[] exps = new Complex[numTimes];
    
      for (int i = 0; i < numTimes; i++) {
        exps[i] = v.raisedTo(i);
        print(exps[i]);
      }
    
      ellipse(w/2, h/2, cSize, cSize);
      print(exps);
      drawSerie(exps, numTimes);
    }
    
    void drawSerie(Complex[] exps, int total)
    {
      Complex partial = new Complex(0, 0);
      drawPartial(exps, total -1, partial);
    }
    
    void drawFinal(Complex toDraw)
    {
       point(toDraw.r*(w/xr) + (w/2), toDraw.i*(h/xr) + h/2);
    }
    
    void drawPartial(Complex [] exps, int depth, Complex partial)
    {
      if (depth == -1)
      {
        drawFinal(partial);
        return;
      }
      int nextDepth = depth -1;
      drawPartial(exps, nextDepth, partial);
      Complex element = exps[depth];
      drawPartial(exps, nextDepth, partial.add(element));
      drawPartial(exps, nextDepth, partial.sub(element));
    }
    
    
    class Complex {
      float r, i;
    
      Complex() {
        this.r = 0;
        this.i = 0;
      } 
    
      Complex(float r, float i) {
        this.r = r;
        this.i = i;
      }
    
      Complex(Complex other)
      {
        this.r = other.r;
        this.i = other.i;
      }
    
      Complex mult(Complex other)
      {
        return new Complex(this.r*other.r - this.i*other.i, this.r*other.i + this.i*other.r);
      }
    
      Complex add(Complex nv) {
          return new Complex(this.r + nv.r, this.i + nv.i);
      }
    
      Complex sub(Complex nv) {
          return new Complex(this.r - nv.r,  this.i - nv.i);
      }
    
      Complex raisedTo(int n) {
      if (n == 0) {
        return new Complex(1, 0);
      }
        else if (n % 2 == 0)
      {
        return (this.mult(this)).raisedTo(n/2);
      } 
      else 
      {
        return this.mult(this.raisedTo(n - 1 ));
      }
    
    }
      String  toString()
      {
        return "real: " + this.r + " imaginary: " + this.i;
      }
    }
    

    The computation of the series is not efficient but, I think, it is clear

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

Sidebar

Related Questions

The full problem description I am trying to solve can be found here: https://i.stack.imgur.com/o1cFn.png
I have found this project on Codeplex. http://www.codeplex.com/ProjNET I need to integrate this code
I found sample Facebook Chat Project for iOS here . also i got the
Today I found LiquiBase project and I think it is very interesting. I would
I just found this project which provides a way of running Google App Engine
I found that my project sets GCC_NO_COMMON_BLOCKS = NO under Apple LLVM Compiler 3.1
I just found the IUI project on google code where you can build websites
Some days ago I found a great project: vs-android. It allows you to build
When i was working on my Android project i found Logcat to be annoying
I'm working with PDFs in VB.NET using a DLL I found on code project:

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.