FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   julia fractals; recursive problems
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: julia fractals; recursive problems  (Read 561 times)
rgovostes

rgovostes
julia fractals; recursive problems
« on: Mar 20th, 2004, 10:53pm »

I am working on an evolving Julia fractal sketch. Most of the code I have found for generating Julia fractals do a recursive call to a 'plot' function which then calls two more 'plot' functions until the accuracy ('depth') becomes too great.
 
However, when I run my code, I get a plethora of stack overflow errors. I could replace this with a single loop, but it doesn't create the neat 'swirling' effect that the recursive version creates.
 
Code:
float t = 1.5, b = -1.5, l = -2.0, r = 2.0; // ??
void plotJulia(float x, float y) {
  int tX, tY, sign;
  float r2, newX, newY;
  
  tX = int((x - l) / (r - l) * width);
  tY = int((y - t) / (b - t) * height);
  
  set(tX, tY, color(255, 255, 255));
  
  if (depthField[tX][tY] < depth) {
    if (y > 0) { sign = 1; }
    else if (y < 0) { sign = -1; }
    else { sign = 0; }
  
    x -= -0.11; y -= 0.6556999;
    r2 = sqrt(sq(x) + sq(y));
    newX = sqrt(r2 + x) * 0.7071067;
    newY = sqrt(r2 - x) * 0.7071067 * sign;
    plotJulia(newX, newY);
    plotJulia(-newX, -newY);
  }
}

 
(I apologize for the messiness of it; it is patched together from various sources on the net, along with a handful of changes by myself.)
« Last Edit: Mar 20th, 2004, 10:54pm by rgovostes »  
TomC

WWW
Re: julia fractals; recursive problems
« Reply #1 on: Mar 20th, 2004, 11:15pm »

If you are using Windows, you can set the stack size on the command line (in run-expert.bat).
 
I think the default is 512k, set like so:
Code:

java -Xss512k ...

 
Try making it a big bigger, e.g. 1m or 2m?
 
 
rgovostes

rgovostes
Re: julia fractals; recursive problems
« Reply #2 on: Mar 21st, 2004, 2:13am »

I use the normal version (the PC I program on is not my own, so I can't install much), and it appears that the default memory is 128 MB. Even changing this to 256 causes errors - no points are plotted, anyway.
 
TomC

WWW
Re: julia fractals; recursive problems
« Reply #3 on: Mar 21st, 2004, 1:07pm »

No, this is stack size, it's different.  The default maximum memory is 128m I think (-mx128m), but I'm fairly sure the stack size start off as 512k (not m).
 
Can you post complete code, so we can try it?
 
In the snippet you posted, you aren't calculating depth, and you're not modifying your depthField array, so I can't work out when it should stop.
 
rgovostes

rgovostes
Re: julia fractals; recursive problems
« Reply #4 on: Mar 21st, 2004, 5:47pm »

Alright... As I said, it's horribly messy right now
I didn't see anything in run.bat (I don't have a run-expert.bat) with the number '512', so I don't know where it would be.
 
Code:
// Julia v1.0, Mar 20 '04
// by Ryan Govostes
 
int depth = 4;
int[][] depthField;
 
float t = 1.5, b = -1.5, l = -2.0, r = 2.0; // ??
 
void setup() {
  size(300, 300);
  background(0);
   
  depthField = new int[width][height];
}
 
boolean asdf;
void mousePressed() {
  asdf = true;
}
 
void loop() {
  if (asdf) { plotJulia(1.0, 1.0); println("done!"); }
}
 
void plotJulia(float x, float y) {
  int tX, tY, sign;
  float r2, newX, newY;
   
  tX = int((x - l) / (r - l) * width);
  tY = int((y - t) / (b - t) * height);
   
  set(tX, tY, color(255, 255, 255));
   
  if (depthField[tX][tY] < depth) {
    if (y > 0) { sign = 1; }
    else if (y < 0) { sign = -1; }
    else { sign = 0; }
   
    x -= -0.11; y -= 0.6556999;
    r2 = sqrt(sq(x) + sq(y));
    newX = sqrt(r2 + x) * 0.7071067;
    newY = sqrt(r2 - x) * 0.7071067 * sign;
    plotJulia(newX, newY);
    plotJulia(-newX, -newY);
  }
}
 
TomC

WWW
Re: julia fractals; recursive problems
« Reply #5 on: Mar 21st, 2004, 7:01pm »

on Mar 21st, 2004, 5:47pm, rgovostes wrote:

I didn't see anything in run.bat (I don't have a run-expert.bat) with the number '512', so I don't know where it would be.

 
Oh, sorry.
 
My run-expert.bat looks like this:  
 
Code:

@echo off
 
REM --- if you're running out of memory, change the 128m  
REM --- (which means 128 megabytes) to something higher.  
 
set SAVEDCP=%CLASSPATH%
set CLASSPATH=lib;lib\build;lib\pde.jar;lib\kjc.jar;lib\antlr.jar;lib\oro.ja r;lib\comm.jar;%windir%\system32\qtjava.zip;%windir%\system\qtjava.zip
 
start javaw -Xms256m -Xmx512m PdeBase
 
set CLASSPATH=%SAVEDCP%

 
I was proposing to add the -Xss1m line in like so...
 
Code:

start javaw -Xms256m -Xmx512m -Xss1m PdeBase

 
Note that it isn't normally defined at all, but if we were to explicitly set it, the default is -Xss512k.
 
Sorry I wasn't clearer earlier.
 
I don't know much about the Julia Set, so I can't help with what it should actually be doing.  Looking at your code though, I don't think setting a bigger stack size will fix your problem.  In the code you posted, you never modify depth or depthField[][], so your code goes into an infinite recursive loop when you click the mouse.
 
 
Pages: 1 

« Previous topic | Next topic »