Primality Test to influence movement
For our first assignment we set out to produce a specific characterized movement. I made an attempt at modifying an existing motion example… trying to implement a Primality test to add idiosyncrasies to an object’s motion. While the algorithm does add something to the motion; aptly named “Cautious Creeper”, the Primality test that I used was flawed, returning a vast number of false positives.
A simple primality test:
boolean isPrime(int n) { boolean prime = true; for (int i = 3; i <= Math.sqrt(n); i += 2) if (n % i == 0) { prime = false; break; } if (( n%2 !=0 && prime && n > 2) || n == 2) { return true; } else { return false; } } }
