We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › newbie code issues
Page Index Toggle Pages: 1
newbie code issues (Read 632 times)
newbie code issues
May 13th, 2008, 10:22pm
 
hi everyone!

a couple of very simple questions if i may:

1)the below code is my very first processing experiment and it renders a bifurcation graph. now, where is the trick to make it look a little less "DOS"-like and mabye a little more like this: http://images.google.at/imgres?imgurl=http://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/LogisticMap_BifurcationDiagram.png/512px-LogisticMap_BifurcationDiagram.png&imgrefurl=http://en.wikipedia.org/wiki/Logistic_map&h=362&w=512&sz=53&hl=de&start=25&um=1&tbnid=oH5Gn_N4X35L5M:&tbnh=93&tbnw=131&prev=/images%3Fq%3Dbifurcation%26start%3D18%26ndsp%3D18%26um%3D1%26hl%3Dde%26client%3Dfirefox-a%26rls%3Dorg.mozilla:de:official%26sa%3DN
or this:
http://ccrma.stanford.edu/~blackrse/LogisticMap_BifurcationDiagram.png

both appear beautifully smooth and show no "pixels" like my version does. anyone have an idea here?

2) the OPENGL mode does weird things with my code. it shows only the outlines of the graph .... weird .... / any clues?

thanx for your time

markus

www.humanchaos.net

import processing.opengl.*;

float rotX;
float rotY;

float r0=1;
float rmax=4;
float n=.5;
float detail=.0001;
float x,y;

void setup(){
 //OPENGL does not really seem to work with this setup ...???
 size(800,600,P3D); //OPENGL);
 //frameRate(120);
 }

void draw(){
 background(0);
 translate(width/2,height/2, mouseY);
 
 //rotation  
   //rotateX(rotX+=.05);
   //rotateY(rotY+=.01);
 stroke(255);
 noFill();  
   //box(r0*100);
 point(0,0);
 stroke(100);
 line(0,height/2, 0, 0-height/2);
 line(width/2,0,0-height/2,0);
 
//bifurcation
 stroke(255);
 for(float r=r0; r<rmax; r=r+detail){
   n=r*n*(1-n);
   //println( "  n  " + n);
   if(n<0){
     stroke(90);
     point(-(mouseX/7-(1-mouseX/(mouseX+1)))-10*r*(1-r),mouseY/10-n*80);
     }
   else{
     stroke(255);
     point(-(mouseX/7-(1-mouseX/(mouseX+1)))-10*r*(1-r),mouseY/10-n*80);    
     }
     }
  }
 if (mousePressed){
   detail=detail/2;
 }  
   
   
}

Re: newbie code issues
Reply #1 - May 14th, 2008, 10:59am
 
a better link to that first picture:
http://en.wikipedia.org/wiki/Logistic_map

those have been drawn larger and then reduced down, which gets rid of the jaggies. see http://en.wikipedia.org/wiki/Anti_aliasing
Re: newbie code issues
Reply #2 - May 14th, 2008, 12:28pm
 
koogy wrote on May 14th, 2008, 10:59am:
a better link to that first picture:
http://en.wikipedia.org/wiki/Logistic_map

those have been drawn larger and then reduced down, which gets rid of the jaggies. see http://en.wikipedia.org/wiki/Anti_aliasing


ok cool - so you're saying that i only need to render it as large as possible and then scale it down

any clues to the OPENGL issue

thanx
markus
Re: newbie code issues
Reply #3 - May 14th, 2008, 7:43pm
 
having actually run the code now i see what you mean. and i think it's a mix of the above problem / not plotting enough pixels (which i think entails reducing your value for detail (i can't get the mousePressed to register)) / rounding errors in the arithmetic (ie it can't distinguish between .000003 and .0000031. you could try doubles rather than floats.)

opengl problem: no idea.
Re: newbie code issues
Reply #4 - May 15th, 2008, 9:50am
 
koogy wrote on May 14th, 2008, 7:43pm:
having actually run the code now i see what you mean. and i think it's a mix of the above problem / not plotting enough pixels (which i think entails reducing your value for detail (i can't get the mousePressed to register)) / rounding errors in the arithmetic (ie it can't distinguish between .000003 and .0000031. you could try doubles rather than floats.)

opengl problem: no idea.


ok cool!!! good points Smiley
please allow one last noob question: processing won't allow to simply substitute "float" with "double" precision. the point(n,r) command won't work with "double" anymore. any clue as to what i am doing wrong here

thanx
markus
Re: newbie code issues
Reply #5 - May 15th, 2008, 10:21am
 
you can use doubles in your calculation, but at the point of drawing you need to cast to a float, so you need: point((float)n,(float)r);

this only reduces the precision of the value passed to the point function, it doesn't make n or r less accurate in the process.
Re: newbie code issues
Reply #6 - May 16th, 2008, 2:37pm
 
very cool. thanks everyone for the help. having no coding background, processing is still give me some hard moments ... so bare with me if in case i return with more questions Smiley
thank you
markus

www.humanchaos.net
Re: newbie code issues
Reply #7 - May 16th, 2008, 9:45pm
 
did have a quick look for the equation for the above bifurcation diagram but couldn't find one, am sure i've done a version myself back around the time the Gleick book on chaos came out (gulp, 1988)

what that one did was trundle along the x axis one step at a time and ran an iterative function to get the y pixels to plot (discarding the first half a dozen values iirc to give it a chance to settle down) before moving onto the next column. i guess this is what yours is doing with the fractional increment.

over at electricsheep.org they also do IF fractals and rather than plotting the pixels immediately they keep a count of number of hits on each pixel, do tens of thousands of iterations, then normalise the colours at each pixel just to get rid of the noise.

(the double thing didn't help when i tried it here. it also pushed the whole diagram over to the right so you couldn't see it except when zoomed out. might have to twiddle some of the other numbers to centre it back up again. i also found that the if n < 0 part of the condition wasn't ever true)
Page Index Toggle Pages: 1