Nature of Code – Week 1 (Motion Study)

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.

Source and applet here

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;
		}
	}
	}
This entry was posted in Nature of Code, Spring 2011. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">