/** MATHS util */ boolean isprime (int n) { if (n <= 2) return (n==2); if( (n & 1) == 0 ) return false; for ( int p= 3; p*p <= n; p+= 2) if (n % p == 0) return false; return true; } // PRIMES int nextprime(int n) { if(n <= 2) return (n==2) ? 3 : 2 ; if((n & 1) == 0) n++ ; else n += 2; while(true) { if(isprime(n)) return n; n+=2; } } int randomcomposite(int a, int b) { int c; do { c = (int) random(a,b) | 1 ;} while(isprime(c) || (c % 5) == 0) ; return c; } int randomprime(int a, int b, float f) { // 0 < f < 1 == frequency if (random(1) < f) return nextprime ((int) random(a,b)) ; return randomcomposite(a,b); } // GCD int gcd (int a, int b) { int t; while( b != 0) { t = b; b = a % b; a = t ; } return a; } /* UTILITIES */ void crect (float x, float y, float w, float h) { // centered rect rect(x-w/2,y-h/2,w,h); } float mapx(float x , float xmin ,float xmax, float ymin, float ymax) { // middle map - xmin = 0 float xmoy = (xmax - xmin)/ 2. ; return map((x > xmoy) ? xmax-x : x ,xmin,xmoy,ymin,ymax); } boolean pmouseInRect(float x, float y,float w, float h) { return (pmouseX >= x) && (pmouseX <= x+w) && (pmouseY >=y) && (pmouseY<= y+h) ; } boolean mouseInRect(float x, float y,float w, float h) { return (mouseX >= x) && (mouseX <= x+w) && (mouseY >=y) && (mouseY<= y+h) ; } boolean mouseInTarget(float d, float a, float r) { return dist(mouseX-width/2,mouseY-height/2,d*cos(a),d*sin(a)) <= r*2 ; } boolean ptInRect(float px, float py,float x, float y,float w, float h) { return (px >= x) && (px <= x+w) && (py >=y) && (py<= y+h) ; }