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.
IndexDiscussionExhibition › PRIME Number Finder
Pages: 1 2 3 
PRIME Number Finder (Read 5760 times)
Re: PRIME Number Finder
Reply #30 - Dec 7th, 2009, 2:14pm
 
Cool thats kind of how mine started but it wasn't slowed down by interface. I have lots of other things to do but I'll have a thought to that end to.

I also have made a version which checks the powers of two -1 here is the code.

PrintWriter output;
long x=1;
long lastprime;
PFont font;
boolean prime=true;
int pps;
float framerate=50;
long truex;

void setup()
{
 size(720,200);
 font = loadFont("Algerian-48.vlw");
 textFont(font, 48);
 frameRate(framerate);
 output = createWriter("data/primes.txt");
 long counter=0;
}

void draw()
{
 delay(int(frameRate/5));
 setup_primes();
 test_primes();
   display_primes();
 save_primes();
}

void setup_primes()
{
 background(0);
 x++;
 prime=true;
}

void test_primes()
{
 truex++;
 truex=(truex*2)-1;
 long counter;
 long countdif;
 counter=1;
 while(counter<truex/2)
 {
   countdif=truex/counter;
   counter++;
   if (countdif==0)
   {
     prime=false;
   }
 }
 if ((prime)&&(truex>0))
 {
    output.println("x"+str(x));
     output.println("truex"+str(truex));
   lastprime=x;
 }
}

void display_primes()
{
 text("last prime:"+lastprime+"  FPS:"+int(frameRate),20,60);
 text("checking:2^"+x+"-1",20,120);
 text("truex:"+truex,20,180);
}

void save_primes()
{
   output.flush();
}


Pages: 1 2 3